MQTT, full name (Message Queuing Telemetry Transport), is a communication protocol that is not too old. It was originally developed for environments with limited network conditions, so it has the characteristics of low bandwidth and low overhead, and The amount of code is also small, and MQTT itself is built on the TCP protocol, and provides deeper protection for the reliability of information transmission.
Therefore, in the embedded field, the MQTT communication protocol already occupies an irreplaceable part, because most embedded devices require such a protocol for data exchange. There are not many available resources for embedded devices, and various plug-ins The method of connecting to the Internet is also inferior to ordinary mobile phones and personal computers. It is a low-speed communication method, and the large amount of traffic consumption is too much for 4G/NB-IOT devices that consume traffic.
Deep features of MQTT protocol
Next, we should talk about the deep features of the MQTT protocol.
1. One-to-many information release
First of all, it is a protocol based on subscription and publishing, so it can publish messages one-to-many. There are many application scenarios for this function. Limited broadcast allows the server to flexibly control the device it wants to control, and the server can Providing multiple topics that can be subscribed to is extremely critical.
Because for the server, receiving and processing data is the core task. However, as the number of devices and device function lines increases, the server processing logic will increase exponentially. The same data received may be completely uploaded by different types of devices. Different information, so when multiple subscription topics and publishing topics can be provided, this logical difference can be distinguished, which brings great convenience to developers.
2. Different underlying protocols
The second feature of the MQTT protocol is actually that it is based on TCP/IP. It is destined to be a protocol based on the upper layer. Most of the people we come into contact with now are actually developed based on the TCP protocol, but it actually has a version based on UDP. , named MQTT-SN, but everyone knows that TCP is connection-oriented, while UDP is not connection-oriented, so based on different underlying protocol types, the characteristics of MQTT must be different.
For the commonly used MQTT (based on TCP) protocol, it has a very important feature to ensure message reliability: QoS.
QoS is divided into three levels:
QoS 0 is actually equivalent to MQTT without additional information protection. Because it is based on the TCP protocol, its message reliability completely depends on the TCP protocol. QoS 1 means that it promises to send it to the recipient at least once. This is information protection at the MQTT layer, not just relying on the TCP protocol layer. Finally, QoS 2 ensures that the message is only delivered to the destination once.
Because for QoS 1, the message may be sent multiple times because there is no feedback, and the receiver may also receive the message multiple times. For this reason, the message transmitted by QoS 2 has a unique ID, and the message with the unique message ID will be stored Twice, first from the sender and then from the receiver QoS level 2 has the highest overhead in the network because two flows are required between the sender and receiver.
At present, the MQTT protocol is actually widely used. It can be found in embedded agriculture, industry, and infrastructure equipment fields, but it is a protocol in itself.
In fact, as a part of data transmission in Internet of Things applications, it plays an equally important role as the wireless transmission method of data. Whether it is 4G wireless module, NB-IOT module, WiFi module, lora module, Bluetooth module, zigbee module, etc., data Transmission belongs to data transmission, but protocols are the soul of the upper layer. Different protocols have different application scenarios and play different roles.