What is MQTT 5.0, and How Does it Work in IoT?
- Last Updated: December 2, 2024
MobiDev
- Last Updated: December 2, 2024
MQTT serves as a tool to connect many types of IoT devices in deployments of all magnitudes. It originally started in 1999 for oil and gas pipelines to communicate over remote satellites.
Operating above TCP/IP, MQTT is a network protocol that functions on a publisher-subscriber communication model. It’s lightweight enough to be used for a wide variety of IoT devices yet powerful enough to work through unstable network conditions.
Thanks to its energy-efficient method of delivering data, MQTT is common for low-powered devices with limited CPU power or RAM.
Let’s look at a case where we need to organize a local MQTT v5.0 network with Python-based clients. We will describe the challenges, issues, and pros and cons along the way. We will conclude by comparing it with an MQTT v3.1.1 network.
<!-- wp:heading {" />
We have a building with several rooms containing a local area network (LAN). One room contains three standalone devices (e.g., activity standalone sensor, photo camera sensor, or audio sensor).
The host device is located inside the LAN and connected to the router wirelessly or via cable. It must provide data gathering (and processing) functions from the standalone device in a period and must store this data locally in the database.
Learn more about how to organize a local MQTT v5.0 network with Python-based clients.
For the current scope, an SQLLite database or simpler alternative is usable. The photo camera sensor and audio sensor must activate only after receiving the message from the activity sensor.
To ensure communication between the host device and standalone devices; and provide local database deployment and communication on the host side.
Standalone device: x86 or ARM-based (e.g., Raspberry Pi) with connected sensors and access to the local network.
Host device: x86 or ARM-based (e.g., Raspberry Pi) hosts MQTT broker and handles messages from standalone devices.
Currently, we have two options to work with: paho-MQTT and gMQTT. However, these options do not have a built-in MQTT 5.0 broker and therefore are not preferable with a local deployment of a network. There is a non-Python implementation of the broker called Mosquitto that does support MQTT 5.0.
It is able to support up to 50 000 devices per broker. Mosquitto has an “inflight queue” that can be configured in size (typical setting: 1000 messages) so that even under heavy load conditions like thousands of messages per sec or thousands of connected clients no connection or message gets lost.
Not many libraries and documentation exist for the MQTT v5.0 protocol, especially from a Python developer’s point of view. The only current v5.0 clients for Python are gmqtt and paho-mqtt.
The upgraded protocol version allows simplifying data payload processing and parsing. It brings the ability to separate and precise control over messages, connections, and sessions. And it allows transferring additional data through properties, which could lead to creating more sophisticated IoT solutions.
MQTT v5.0 is a suitable option for local IoT device communication if you have a central device that can host a message broker for communication between devices and/or the host. Despite its drawbacks (most of which were eliminated in MQTT v5.0), this protocol can be used for communication between small-to-medium sized networks of IoT devices.
The Most Comprehensive IoT Newsletter for Enterprises
Showcasing the highest-quality content, resources, news, and insights from the world of the Internet of Things. Subscribe to remain informed and up-to-date.
New Podcast Episode
Related Articles