How to use AWS IoT MQTT client

AWS Dec 27, 2021

Hello People. This article discusses about how to use AWS IoT MQTT client. Using this, you can watch MQTT messages sent and received by AWS IoT. Before that we should know a bit about MQTT topics.

What are MQTT topics?

MQTT topics can identify AWS IoT messages. AWS IoT clients identify the messages they publish by giving topic names to the messages. Clients identify the messages to which they want to subscribe(to receive messages) by registering a topic filter with AWS IoT Core. The message broker uses topic names and topic filters to route messages from publishing clients to subscribing clients. Also the message broker uses topics to identify messages sent using MQTT and sent using HTTP to the HTTPS message URL.

AWS IoT supports some reserved system topics. However, most MQTT topics are created and managed by you, the system designer.  Before you create a topic namespace for your system, review the characteristics of MQTT topics to create the hierarchy of topic names that works best for your IoT system.

How to use AWS IoT MQTT client 

Creating Topic names

Please note that Topic names and topic filters are UTF-8 encoded strings. They can represent a hierarchy of information by using the forward slash (/) character to separate the levels of the hierarchy. For example, this topic name could refer to a temperature sensor in room 1:

  • sensor/temperature/room1

In this example, there might also be other types of sensors in other rooms with topic names such as:

  • sensor/temperature/room2
  • sensor/humidity/room1
  • sensor/humidity/room2

Note

As you consider topic names for the messages in your system, follow these:

  • Topic names and topic filters are case sensitive.
  • Topic names must not contain personally identifiable information.
  • Topic names that begin with a $ are reserved topics to be used only by AWS IoT Core.
  • AWS IoT Core can't send or receive messages between AWS accounts or Regions.

View MQTT messages in the MQTT client

In the AWS IoT console, in the left menu, choose Test and then choose MQTT test client. In the Subscribe to a topic tab, enter the topicName to subscribe to the topic on which your device publishes. For the getting started sample app, subscribe to #, which subscribes to all message topics.

You can Continue with the getting started example, on the Subscribe to a topic tab, in the Topic filter field, enter #, and then choose Subscribe.

The topic message log page, # opens and # appears in the Subscriptions list. If the device that you configured in Configure your device is running the example program, you should see the messages it sends to AWS IoT in the # message log. The message log entries will appear below the Publish section when messages with the subscribed topic are received by AWS IoT.

On the # message log page, you can also publish messages to a topic, but you'll need to specify the topic name. You cannot publish to the # topic.

Messages published to subscribed topics appear in the message log. The most recent message apear first.

Hope this article on how to use AWS IoT MQTT client is useful to you. Please read about AWS IoT actions and core related services.

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.