by Siddhesh B (III Year – Electronics and Communication Engineer), Sastra University, Tamil Nadu
MQTT is a lightweight publish/subscribe messaging protocol designed for machine- to-machine telemetry in low bandwidth environments. It runs over TCP/IP. However, any network that is lossless, and bi- directional can provide MQTT support.
Residing on top of the TCP/IP network stack, MQTT is a lightweight publish/subscribe messaging protocol designed for low-bandwidth, high latency, unreliable networks. MQTT’s features make it an excellent option for sending high volumes of sensor messages to analytics platforms and cloud solutions.
Publish / Subscribe Model
MQTT entities are split into categories: a broker, and a various number of clients. The MQTT ‘broker’ is the middle man who handles all the communication between the clients.
The clients do not know anything about each other and all communication between the clients go through the broker. The client that sends the data ‘publishes’ the data onto the MQTT broker. The clients who want to receive it ‘subscribe’ to the data published, and receive it from the MQTT broker. This is defined as the Publish/Subscribe model.
In the above example, the humidity sensor is a client, along with the Cloud and On-premise analytics. The sensor publishes the message to the broker. The broker then checks for any subscribers. Upon finding a subscriber, the broker then publishes the message to the subscribers.If the broker does not find any subscribers to a published message, the broker gets rid of the message.
The MQTT broker is software running on a computer (running on-premises or in the cloud), and could be self-built or hosted by a third party. It is available in both open source and proprietary implementations.
MQTT brokers have a one-to-many property, where they can send messages to multiple subscribers. MQTT doesn’t use the address of the intended recipient but uses the subject line called “Topic”, and anyone who wants a copy of that message will subscribe to that topic. Multiple clients can receive the message from a single broker (one to many capability). Similarly, multiple publishers can publish topics to a single subscriber (many to one). Every client can publish data and subscribe to topics to receive data.
Topics are hierarchical UTF-8 strings. Each level in a topic is signified by a forward slash. Every message from a publisher must include a topic. To receive the published message, the entity that consumes the message must subscribe to the same topic. A broker sends the message it receives only to those clients that have subscribed to the same topic.
Advantages of MQTT
- Distribute information more efficiently
- Increase scalability
- Reduce network bandwidth consumption dramatically
- Reduce update rates to seconds
- Very well-suited for remote sensing and control
- Maximize available bandwidth
- Saves development time
Disadvantages of MQTT
- MQTT uses TCP protocol which requires more processing power and more memory. TCP uses handshake protocol which requires frequent wake up and communication time intervals. This affects battery consumption. Moreover TCP connected devices tend to keep sockets open for each other which adds memory/power requirements.
- Centralised broker limits the scalability as each client devices take up some overhead. In order to avail scalability, local broker hub is used.
- It is not easy to implement compare to HTTP.
- It does not support advanced features such as flow control.
- In MQTT protocol, clients must have to support TCP/IP.
Projects implemented using MQTT
- OpenHAB, an open source home automation system
- MQTT Buddy, an android app launched by XIM, Inc
- Node RED is a visual programming tool by IBM which supports MQTT
- Ejabberd is an open source software which supports MQTT.