Reference URLs:
Features of MQTT:
-
Open messaging protocol, simple and easy to implement
-
Publish/subscribe model, one-to-many message publishing
-
Message QoS support, ensuring reliable transmission
-
Based on TCP/IP network connection, providing ordered, lossless, bidirectional connection.
-
1-byte fixed header, 2-byte heartbeat message, minimizing transmission overhead and protocol exchange, effectively reducing network traffic.
Design Principles:
Due to the unique environment of IoT, MQTT follows these design principles:
-
Simplistic, without adding unnecessary features; -
Allows users to dynamically create topics, zero operational cost; -
Minimizes transmission volume to enhance transmission efficiency; -
Considers factors such as low bandwidth, high latency, and unstable networks; -
Supports continuous session control; -
Understands that client computing capability may be low; -
Provides quality of service management; -
Publish/subscribe (Pub/Sub) model, facilitating message transmission among sensors; -
Assumes data is unknown, does not enforce data type and format for transmission, maintaining flexibility.
1. Why Choose MQTT
MQTT is a lightweight and flexible network protocol, designed to achieve an appropriate balance for IoT developers:
-
This lightweight protocol can be implemented on severely constrained device hardware and high-latency/low-bandwidth networks.
-
Its flexibility allows for support of diverse application scenarios for IoT devices and services.
To understand why MQTT is so suitable for IoT developers, we first analyze why other popular network protocols have not been successfully applied in IoT.
2. Why Not Choose Other Numerous Network Protocols
Most developers are already familiar with HTTP web services. So why not connect IoT devices to web services? Devices can send their data in the form of HTTP requests and receive updates from the system in the form of HTTP responses. However, this request-response model has several serious limitations:
A.HTTP is a synchronous protocol. Clients must wait for server responses. Web browsers have this requirement, but at the cost of scalability. In the IoT field, numerous devices and potentially unreliable or high-latency networks make synchronous communication problematic. Asynchronous messaging protocols are more suitable for IoT applications. Sensors send readings, allowing the network to determine the best route and timing for delivering them to target devices and services.
B.HTTP is one-way. The client must initiate the connection. In IoT applications, devices or sensors are usually clients, meaning they cannot passively receive commands from the network.
HTTP is a 1-1 protocol. Clients make requests, and servers respond. Delivering messages to all devices on the network is not only difficult but also costly, which is a common use case in IoT applications.
C.HTTP is a heavyweight protocol with many headers and rules. It is not suitable for constrained networks.
For the above reasons, most high-performance, scalable systems use asynchronous message buses for internal data exchange rather than web services. In fact, the most popular messaging protocol used in enterprise middleware systems is called AMQP (Advanced Message Queuing Protocol). However, in high-performance environments, computational capacity and network latency are usually not an issue. AMQP aims to achieve reliability and interoperability in enterprise applications. It has a large feature set but is not suitable for resource-constrained IoT applications.
In addition to AMQP, there are other popular messaging protocols. For instance, XMPP (Extensible Messaging and Presence Protocol) is a peer-to-peer instant messaging (IM) protocol. It heavily relies on features supporting IM use cases, such as presence status and media connections. Compared to MQTT, it requires far more resources on devices and networks.
So, why is MQTT so lightweight and flexible? Because a key feature of the MQTT protocol is the publish and subscribe model. Like all messaging protocols, it separates the data publisher from the user.
Follow the WeChat public account ‘strongerHuang’, reply “1024” in the backend to see more exciting content.
Long pressto recognize the QR code in the imageto follow