Message Queuing Telemetry Transport (MQTT)

MQTT is a lightweight publish and subscribe system that allows clients to send and receive messages.

MQTT is a low-bandwidth messaging system developed for limited devices. As a result, it’s ideal for Internet of Things applications.

MQTT allows you to control outputs, read and publish data from sensor nodes, and send commands to control outputs. As a result, setting up communication across many devices is simple.

The server is in charge of responding to client requests for data to be received or sent between them. A broker is an MQTT server, while clients are just linked devices.

MQTT Components 

  1. Subscribe and Publish
  2. Message
  3. Topic
  4. Broker
  1. Subscribe and Publish

A device can either publish a message on a topic or subscribe to a topic to receive messages in a publish and subscribe system. 

For example,

Device_1 publishes on a certain topic.

Device_2 is subscribing to the same topic as Device_1 publishes.

As a result, the message is received by Device_2.

  1. Message

Messages are the information you wish to send and receive between your devices. It doesn’t matter if it’s a command or data.

For example, if we are publishing temperature data to the cloud, this data is referred to as a Message.

  1. Topic

Topics are how you indicate your interest in incoming messages or where you wish the message to be published.

Strings separated by a forward slash are used to denote topics. A topic level is indicated by each forward slash.

For Example,

  1. Broker

The broker is in charge of receiving all messages, screening them, determining who is interested in them, and finally publishing the message to all subscribers.

QoS – Quality of Service 

With an integer number ranging from 0-2, each connection can indicate a level of service to the broker.

0 denotes at most once, or once and only once without needing an acknowledgment of delivery. This is known as the “fire and forget” strategy. When a sender sends a message, it doesn’t care if it’s delivered to the intended recipient or if it’s resent.

1 denotes at least once. The message is delivered several times until it receives an acknowledgment, which is known as acknowledged delivery. The Sender waits for the receiver’s acknowledgment after sending a message. It resends the message if it does not get an ACK. This option ensures that the message is delivered at least once, but it does not ensure that it is repeated.

2 denotes exactly once. A two-level handshake is used by the sender and receiver clients to ensure that only one copy of the message is received, which is known as ensured delivery.

Example of MQTT

Suppose, there is a device with a temperature sensor. And, it wants to send its readings to the broker. A phone/desktop application, on the other hand, want to get this temperature value. As a result, two things will occur:

  • The device specifies the topic on which it wishes to publish, for example, “temp.” The message “temperature value” is then published. 
  • The “temp” topic is subscribed by the phone/desktop application. The device’s published message, which is the temperature reading, is then received.

The broker’s job is to transmit the message “temperature value” to the phone/desktop application.

Categories: Science, Tech

Tagged as: , ,