Introduction to MQTT Protocol: Essential for IoT Enthusiasts

Follow the IoT Planet to track IoT dynamics! “IoT Planet” aligns with global industry trends, focusing on the integration of IoT and industry, and sharing technologies and applications related to IoT.

Introduction to MQTT Protocol: Essential for IoT Enthusiasts

Introduction to MQTT Protocol: Essential for IoT Enthusiasts

MQTT (Message Queuing Telemetry Transport) is a “lightweight” communication protocol based on the publish/subscribe model. This protocol is built on top of the TCP/IP protocol and was released by IBM in 1999. It has now become the OASIS standard messaging protocol for the Internet of Things (IoT). The biggest advantage of MQTT is that it provides real-time reliable messaging services for connecting remote devices with minimal code and limited bandwidth.
The MQTT protocol is lightweight, simple, open, and easy to implement, making it widely applicable in IoT, small devices, mobile applications, and more. The MQTT protocol operates on top of the Transmission Control Protocol/Internet Protocol (TCP/IP) stack, providing ordered, lossless, two-way connections. The MQTT protocol has strong adaptability in handling unstable network connections and limited bandwidth, and is often used in scenarios such as smart homes, medical devices, and satellite communications.
Introduction to MQTT Protocol: Essential for IoT Enthusiasts

Why Choose MQTT?

The MQTT protocol has the following characteristics:
  • Lightweight and Efficient:The code size of the MQTT client is very small, and it has low resource requirements, making it very suitable for use on small microcontrollers. Additionally, the header fields of MQTT messages are small, optimizing network bandwidth and further improving transmission efficiency.
  • Supports Two-Way Communication: The MQTT protocol supports message passing between devices and the cloud, as well as from the cloud to devices. This makes broadcasting messages to a large number of devices relatively straightforward.
  • Scalability: The MQTT protocol can scale to connect millions of IoT devices, meeting the needs of large-scale device deployment and data collection.
  • Reliable Messaging: For many IoT applications, the reliability of message delivery is crucial. The MQTT protocol provides three defined levels of Quality of Service (QoS): at most once (QoS 0), at least once (QoS 1), and exactly once (QoS 2), to meet the different reliability needs of message delivery in various scenarios.
  • Supports Unreliable Networks: Many IoT devices connect via mobile cellular networks, which are often unstable. However, the MQTT protocol reduces the time and communication delay for re-establishing connections between clients and brokers through the design of persistent sessions, thus providing relatively reliable message transmission in unreliable network environments.
  • Security: The MQTT protocol can easily use TLS (Transport Layer Security) to encrypt messages in transit and supports modern authentication protocols like OAuth to authenticate clients, ensuring the security of message transmission and the legitimacy of client identities.
Introduction to MQTT Protocol: Essential for IoT Enthusiasts

Common Terminology Explained

Term

Explanation
MQTT Broker

The MQTT Broker is a message middleware that is responsible for receiving messages sent by publishers and forwarding them to subscribers based on the topics subscribed by the subscribers. It manages client connections, handles subscriptions and unsubscriptions, and ensures messages are sent according to the specified Quality of Service (QoS) levels. MQTT is an open, lightweight machine-to-machine protocol designed for IoT interactions. In an MQTT network, the MQTT Broker is the server coordinating interactions between all MQTT agents. MQTT clients can be publishers, subscribers, or both. The MQTT architecture can be centralized or distributed to suit different application scenarios.

Bridge
A Bridge in the MQTT protocol refers to connecting two MQTT brokers, allowing them to communicate with each other to achieve message interoperability.
When two brokers are bridged, they can serve as access nodes, providing a configurable virtual IP or domain name for access. This bridging method can achieve load balancing and failover, improving system availability and stability.
When configuring a Bridge, it is necessary to specify the topic for message synchronization, rather than synchronizing all topics to avoid traffic amplification issues. It is more recommended to use a vertically segmented approach for traffic diversion.
The Bridge in the MQTT protocol has the following characteristics:
  • It can achieve message interoperability between two MQTT brokers, ensuring message reliability and stability.
  • It can configure a virtual IP or domain name for access, improving system availability and maintainability.
  • It can achieve load balancing and failover, improving system availability and stability.
  • It can specify the topic for message synchronization, avoiding traffic amplification issues.
  • It is more recommended to use a vertically segmented approach for traffic diversion to further enhance system availability and stability.

MQTT Client

The MQTT Client refers to devices that run the MQTT library and connect to the MQTT broker over the network. These devices can be microcontrollers or mature servers, implementing the MQTT protocol’s client. In the MQTT protocol, a typical client will perform the following main operations: publishing messages to a topic, subscribing to messages from a topic, handling received messages, and acknowledging received QoS 1 or QoS 2 messages. The implementation of the MQTT protocol’s client is very simple and straightforward.

RSMB
RSMB (Very Small Message Broker) is a lightweight message broker developed by IBM, primarily used for message transmission services in MQTT protocol’s C/S (client/server) architecture. Later, the Eclipse Foundation adopted RSMB as a project under its umbrella, renaming it Eclipse Mosquitto.
Eclipse Mosquitto is an open-source message broker that implements MQTT protocol versions 3.1 and 3.1.1, designed for various devices ranging from low-power single-board computers to full servers. The MQTT protocol uses a publish/subscribe model for message delivery, which has proven to be very effective in many scenarios, especially in IoT (Internet of Things) applications.
LWT
Last Will and Testament (LWT) is a mechanism in the MQTT protocol used to handle abnormal disconnections.
LWT can be understood as the will mentioned when connecting to the MQTT Broker. When the Broker detects that the Client has disconnected abnormally, it will publish a message to the will topic. The settings related to the will are specified when establishing the connection, in the CONNECT packet’s Variable header and Payload.
M2M
Machine to Machine (M2M) refers to the transfer of data from one terminal to another, essentially a dialogue between machines. M2M application systems consist of intelligent machines, M2M hardware, communication networks, and middleware. M2M application domains include home applications, industrial applications, retail and payment fields, logistics and transportation industries, medical industries, and more.
IoT

The Internet of Things (IoT) refers to the real-time collection of any monitored, connected, or interactive object or process through various information sensors, RFID technology, GPS, infrared sensors, laser scanners, and other devices and technologies, gathering information such as sound, light, heat, electricity, mechanics, chemistry, biology, and location, to achieve ubiquitous connectivity between objects and people, enabling intelligent perception, identification, and management of objects and processes. The IoT is an information carrier based on the Internet and traditional telecom networks, allowing all independently addressable physical objects to form an interconnected network.

QoS
In MQTT (Message Queuing Telemetry Transport), mechanisms are designed to ensure stable message transmission, including message acknowledgment, storage, and retransmission. Under this mechanism, three different levels of Quality of Service (QoS) are provided:
  • QoS0, i.e., at most once (At most once). Under this level, the sender will attempt to send the message to the receiver, but the message delivery process includes only one attempt. If the sending fails, it will not retry. This QoS level is suitable for scenarios where the reliability of message delivery is not high, but the response speed is critical.
  • QoS1, i.e., at least once (At least once). Under this level, the sender ensures that the message is delivered at least once to the receiver. In some cases, the message may be delivered multiple times. The receiver can determine whether a message has been received using message IDs or other identifiers, thus handling duplicate reception. This QoS level is suitable for scenarios where it is necessary to ensure that messages are delivered at least once but allows for duplicate delivery.
  • QoS2, i.e., exactly once (Exactly once). Under this level, the sender ensures that each message is delivered only once to the receiver. In some cases, message delivery may be delayed. The receiver can rely on some mechanism (such as database transactions) to ensure that the processing of a message does not occur multiple times. This QoS level is suitable for scenarios where it is necessary to ensure that each message is delivered only once, and there is a certain tolerance for message delivery delays.
Different QoS levels provide various options and flexibility for MQTT applications, allowing for the selection of the most suitable QoS level based on actual needs and network environments. It is important to note that QoS is a protocol between the Sender and Receiver, not between the Publisher and Subscriber.
Introduction to MQTT Protocol: Essential for IoT Enthusiasts

Frequently Asked Questions

  • What is MQTT?
MQTT is the OASIS standard for IoT connectivity. It is an extremely simple and lightweight messaging protocol designed for constrained devices and low-bandwidth, high-latency, or unreliable networks. The design principles aim to minimize network bandwidth and device resource requirements while trying to ensure reliability and a certain level of delivery guarantee. These principles also make the protocol an ideal choice for connecting devices in the “Internet of Things” world and for mobile applications where bandwidth and battery life are very precious.
  • Who invented MQTT?
MQTT was invented in 1999 by Dr. Andy Stanley-Clark of IBM and Arlen Nipper of Arcom (now Eurotech).
  • Where is MQTT used?
Since 1999, MQTT has been widely implemented across various industries.
  • Is MQTT a standard?
Versions 5.0 and 3.1.1 have become OASIS standards (version 3.1.1 has also been approved by ISO).
  • Are there standard ports for MQTT?
Yes. TCP/IP port 1883 has been reserved by IANA for MQTT. TCP/IP port 8883 has also been registered for MQTT over SSL.
  • Does MQTT support security?
In protocol version 3.1, you can pass a username and password using MQTT packets. Encryption over the network can be handled using SSL, independent of the MQTT protocol itself (notably, SSL is not the lightest protocol and does add significant network overhead). Additional security can be provided by applications encrypting their sent and received data, but this is not built into the protocol to keep it simple and lightweight.
    Introduction to MQTT Protocol: Essential for IoT Enthusiasts
    Introduction to MQTT Protocol: Essential for IoT Enthusiasts
    Introduction to MQTT Protocol: Essential for IoT Enthusiasts

    Previous Recommendations

    • List of IoT Platforms at Home and Abroad (As of 2023, a must-see for IoT platform technology selection)

    • KubeEdge: Cloud-Native Edge Computing Framework Built on Kubernetes

    • Open Source IoT Platform: ThingsBoard

    • List of Common IoT Protocols (Collection Edition, please bookmark)

    Introduction to MQTT Protocol: Essential for IoT Enthusiasts
    Introduction to MQTT Protocol: Essential for IoT Enthusiasts

    AIoT Planet:Technical Communication ยท Add as Friend

    IoT technical communication community is about to be established

    Introduction to MQTT Protocol: Essential for IoT Enthusiasts

    Clicking to see is the greatest support!

Leave a Comment