Lightweight MQTT Protocol
The most adopted messaging protocol for IoT
What is MQTT?
MQTT is a featherweight and open source leading simple machine to machine messaging protocol runs over TCP/IP. Specially designed for the Internet of things (IoT) and for limited bandwidth to control devices. The communication is made more robust with a Central Broker, Clients and Gateways, Publishing & Subscribing client, Topics, Three levels of Quality of Service(QoS) & Message Retention.
How MQTT works?
Last WILL & Retain
Persistent session & Message Queuing
Central Message Broker
MQTT Broker is a central server that acts as a data warehouse for all the messages to be transmitted between the clients / devices works as per MQTT protocol Oasis standard. Clients connect to the broker and subscribes to the topics it requires, to listen for commands. Edge clients as well publishes data, when an event occurs on the sensors.
The broker keeps track of the subscriptions and published data. Based on the QoS levels (QoS 0, 1, 2), Retention definition and clean sessions defined by the clients, the broker sends the MQTT data to the respective clients. MQTT5 specification also defines the way the broker can handle the disconnection of clients and shared subscription.
Every device or edge application in the (MQTT) Message Queuing Telemetry Transport infrastructure must have the Client to read the edge data via sensors and communicate. Because the client is responsible for establishing a MQTT connection session with the MQTT server, providing subscriptions on topics of interest to them, and publishing information of interest to other clients.
The clients only interact with the MQTT broker, as the clients can not connect to each other directly. Each client acts as both sender and receiver. Any device can acts as the client that runs on an MQTT library and connects to the broker over the network.
IoT Applications Development
Two ways in building the IoT Application with MQTT
IoT Application over MQTT broker
90% of the application requirements today is the collection of data from various sources. As it is the data collection, the data will be sent to the central Broker. So it is better to build the application right behind the Broker where we get the most meta info of the data collected. As we build the application over the broker we cut down the flow of data from the broker to the application client. Python MQTT Interface of the MQTTRoute is one such Broker that supports MQTT version 3.1.1 with flexible extendibility to build a complete application.
IoT Application behind MQTT client
In this method of IoT Application development, there will be a master client which subscribes to all the topics either one by one or using the # subscription. Due to the subscription, the client will receive all the data sent to the broker. The client will have mechanism to store the data and process / analyze and present it to the customer as needed. However the data traffic will increase to this client as the number of real time data publishers increases. Use MQTT version 5.0 shared subscription to avoid data overloading.
IoT Edge Development
The MQTT gateway is usually a piece of software/hardware between sensors and the IoT operating system or server. It collects message, receives data from edge sensors and converts them into messages and passes them to IoT applications. The gateway acts as a middleware agent between the sensors and the server. This gateway has a built-in function to detect all available sensors on the network running around the gateway. The detected sensor and device are allowed to communicate with each other and are managed from the central IoT platform. The self-advertising of sensors and devices helps to find the Gateway to the Clients. Within this framework, gateway itself is considered as an IoT edge device.
Looking to learn more about the Protocol to build IoT Application and Clients?