Manage Data through MQTT

MQTT is the standard messaging protocol for the Internet of Things based on publish/subscribe information. It allows for messaging between device to cloud and cloud to device. Connections are always handled by an MQTT broker, which is responsible for receiving and filtering the messages using topics.

The Altair IoT Studio Platform offers its own MQTT broker to interact with the platform and perform different operations through MQTT.
Figure 1.


Establishing a Connection

To use this protocol, a connection between Altair IoT Studio and the Thing must be done with the username and password given. The data will be sent by publishing it to the properties using the correct MQTT topic. Check the MQTT documentation to learn more about the different topics available.
Note:
  • Host: tcp://mqtt.swx.altairone.com
  • Port: 1883

Messaging

Note: As W3C standards are followed, the body of the request should be in JSON formatting.

MQTT Topics are crucial in the MQTT ecosystem as the broker relies on them to determine which clients receive specific messages. Topics consist of one or more levels separated by a forward slash (topic level separator).

Wildcards can be used for subscribing to multiple topics simultaneously. When a client subscribes to a topic, it can either subscribe to the exact topic of a published message or utilize wildcards to broaden its subscription. It’s important to note that wildcards can only be used for subscription and not for publishing messages. There are two types of wildcards:
  • single-level: Represented by a symbol (+) and allows the replacement of a single topic level. By subscribing to a topic with a single-level wildcard, the client receives all messages from any topic that contains an arbitrary string in place of the wildcard.
  • multi-level: Represented by a hash symbol (#) and must be placed as the last character in the topic, preceded by a forward slash. By subscribing to a topic with a multi-level wildcard the client receives all messages of any topic that begins with the pattern before the #. If the topic is specified as “#” alone, the client receives all messages sent to the MQTT broker.

To handle the communication publisher/subscriber properly, an agreement regarding the guarantees of the message delivery is established. This is called the Quality of Service (QoS), and there are three levels of agreement:

Level 0
“At most once”. The message sent will not be stored nor redelivered by the sender and will not be acknowledged by the receiver.
Level 1
“At least once”. The message will be delivered at least once to the subscriber, but it can be delivered more than once.
Level 2
“Exactly once”. The message will be delivered strictly one time accompanied by multiple acknowledgment messages confirming the delivery of the message.
Figure 2.


Using the MQTT Inspector

The MQTT Inspector allows you to see MQTT incoming topics and messages and the format of the data payload. A list of the messages and topics is shown so you will know what topics are available.

Display the MQTT Inspector by opening the Utility Belt (left side menu) and clicking MQTT Inspector.
Figure 3.


A summary of topics and total messages received is shown.
Figure 4.


The message is published to the Thing:
Figure 5.


After publishing, you will be able to check all the details at the MQTT Inspector:
Figure 6.