Before diving deeper into understanding what the usage MQTT in IoT is, let’s look at the history of MQTT itself. In 1999, Andy Stanford-Clark of IBM, and Arlen Nipper (then of Arcom Systems, later CTO of Eurotech), created MQTT. In its initial version, MQTT helped oil pipeline sensors communicate with satellites. In 2014 OASIS accepted MQTT as an ISO standard. Since then, MQTT has become widely used on the Internet of Things (IoT) and machine-to-machine (M2M) communication due to its lightweight and efficient design.
So, what is the use of MQTT in IoT?
MQTT is one of the communication protocols used in sending data on the Internet of Things (IoT) and it is an abbreviation for Message Queuing Telemetry Transport. MQTT is a simple messaging protocol designed for devices with low bandwidth. It is designed to enable devices with low bandwidth to send and receive messages efficiently. MQTT is an open protocol that utilizes publish/subscribe messaging pattern, making it ideal for exchanging data between multiple IoT devices in a network.
How the MQTT Work
Basically, MQTT uses the existing internet connection at your house to send and responds to the messages to your IoT devices.
MQTT is a simple publish/subscribe protocol. It enables you to send messages on certain subjects (channels) via a centralized message broker. MQTT communication operates on a publish-and-subscribe system. Messages on a specific topic are published by devices. The message is delivered to all devices that have subscribed to that topic. In a bigger picture, the MQTT works like the picture below.
In MQTT, there are a few basic concepts that need to be understand:
1. MQTT Broker:
The broker is a crucial component of the Internet of Things (IoT) ecosystem, responsible for facilitating communication between IoT devices. It acts as a message hub, receiving data from devices and distributing it to the appropriate recipients. This is the heart of the publish/subscribe protocol. The MQTT Broker is optimally designed to handle many thousands of concurrently connected MQTT clients.
2. MQTT Client
Client is the device that connects with the broker to send or receive the information. It could be any device, from a small microcontroller up to a big conveyor system inside a manufacturing plant, that has an MQTT library running and is connected to an MQTT Broker over any kind of network.
3. MQTT Topic
A topic is a string that acts as a label or address for messages being published and subscribed to. It serves as a way to categorize and organize the flow of information within an MQTT system. Clients subscribe to topics to receive relevant messages, and they publish messages to topics to reach interested recipients.
4. Publish
Clients that send messages or data to the broker to distribute the topics to interested clients. The client specifies the topic to which it wants to publish the message. Other clients that have subscribed to the same topic will receive the published message from the broker. The published message can contain any type of data, such as sensor readings, commands, status updates, or any other information to be shared within the MQTT network.
5. Subscribe
Clients tell the broker on which topics they are interested in. When a client subscribes to a topic, it essentially tells the broker that it wants to receive any messages published on that topic. Clients can also unsubscribe to stop receiving messages from the broker about that topic.
6. Quality of Service (QoS)
MQTT provides 3 levels of Quality of Service for messaging, to ensure reliable messaging in different network environments. The QoS does not affect the handling of the TCP data transmissions, only between the MQTT clients.
- QoS 0: The message is transmitted at most once
The publisher only sends the message once and doesn’t care whether the message is sent to the other side or not. If the client is not available at that time, the message is lost. This is often referred to as fire and forget.
- QoS 1: The message is transmitted at least once
The message is sent multiple times until there is an acknowledgement, the message will be resent if there is no acknowledgement. This model ensures that the message will be delivered at least once but does not ensure that it will be repeated.
- QoS 2: The message is transmitted only once
This model employs a two-level handshake which means only one copy of the messages is received. The mechanism is designed to ensure that messages reach the other side and arrive strictly only once.
Example
Let’s say you are already installing a smart light system where you can control it using a mobile phone. At one time, you want to turn the light on while on the way home, so you open the mobile app and push the button to ‘On’ and this message will be sent to the MQTT broker. On the other side, your smart lights subscribed to the same topic. Then once it receives the message that the device has been published, it toggles light based on the state.
Conclusion
MQTT is a lightweight messaging protocol for efficient device communication. Publishers send messages to topics, and subscribers’ express interest by subscribing to topics. An MQTT broker acts as a mediator, delivering messages from publishers to interested subscribers. MQTT offers different QoS levels for reliability. It’s ideal for IoT, sensor networks, and remote monitoring.
In our platform, we also provide MQTT as one of the communication protocols. Thanks to its reliability and lightweight nature, low bandwidth usage, and efficient publish-subscribe model make it well-suited for IoT application.
Visit our blog to get more information about technology. On the other hand, you can visit our knowledge base page for tutorials on how to use the features in IoT Stadium