MQTT - IoT Messaging Standard
MQTT is a simple and lightweight messaging protocol to be used for devices constrained with low-bandwidth. This is the perfect way for IoT devices to communicate with the the applications that they are connected to. MQTT allows the client to send commands to control outputs, read and publish data from devices.
The following are the core items of the MQTT system. These different elements are broken down easily with examples for you to understand the flow of how the MQTT protocol facilitates communication between devices and the broker.
The information that is exchanged (send/receive) between devices. Can be a command or data.
Topics are a form of addressing that allows devices to share information with each other. MQTT Topic structure is in a hierarchy similar to folders in a file system using the forward slash ( / ).
Publishers publish messages on a topic.
Subscribers subscribe to topics and receive messages.
- Publisher publishes on a Topic.
- Subscriber is subscribed to the same Topic as Publisher is publishing in.
- Subscriber receives the message.
Identify messages and direct them to the correct publisher/subscriber based on topics.
Example: AWS IoT Core
MQTT with Room Temperature Data
The room thermometer publishes of the message of the temperature (24C) to the topic. This topic and message is received by the broker.
The broker facilitates the published message and publishes to the devices that are subscribed to the relevant topic. Therefore, the subscribed devices receive the temperature data of 24C because they are subscribed to the appropriate topic.
Why use MQTT?
Lightweight, so it can be used in high latency, limited bandwidth scenarios.
Flexible, its versatile protocol is used as an industry standard and can be paired with many IoT hardware devices.
Two-way communication, unlike HTTP which is one-way, MQTT allows two-way communication between devices. IoT devices using MQTT can actively send information AND passively receive, which cannot be done using HTTP.