Original: https://www.cnblogs.com/3echo/p/11612560.html
The Internet of Things (IoT) is not just a new technology, but also an integration with old technologies, where communication is key. Various communication methods differ, but various protocols play a vital role in connecting vast numbers of “things” to the internet.This article introduces two complementary IoT protocols: the local protocol Modbus for short-range device connections and the extensible internet protocol “Message Queuing Telemetry Transport (MQTT)” that supports global communication for IoT.Modbus is a serial communication protocol that first appeared in 1979 and is the standard protocol used for connecting industrial devices. MQTT emerged over 20 years ago, but using these two protocols together can provide the scale and connectivity of IoT for deeply embedded devices.Figure 1. The IoT (Internet of Things) gateway as a supporting solution for IoT communication. Let’s look at Modbus and MQTT to understand their differences and how they complement each other in IoT.
1. Modbus
Since its introduction in 1979, Modbus has evolved into a comprehensive set of protocols supporting various physical links (such as RS-485). The core of Modbus is a serial communication protocol that employs a master-slave model. The master sends requests to the slave, which then replies. In a standard Modbus network, there is one master and up to 247 slaves (however, this limit can be significantly increased if 2-byte addressing is used).Communication between the master and slave occurs in frames that indicate function codes. These function codes identify the operations to be performed, such as reading discrete inputs; reading FIFO queues; or executing diagnostic functions. The slave then responds based on the received function code, and the response is relatively simple, consisting of a set of bytes. Thus, the slave can be an intelligent device or a simple device with just a sensor.From this description, you can see that the Modbus protocol is quite simple, but its openness as a protocol makes it a practical communication protocol for the entire industry or SCADA systems.
2. Message Queuing Telemetry Transport
MQTT is an open, lightweight machine-to-machine protocol designed for IoT interactions. An MQTT network consists of an MQTT broker that coordinates interactions between MQTT clients. Clients are publishers responsible for publishing information for users (see Figure 2).Figure 2. Factors in the Message Queuing Telemetry Transport Network
MQTT has very few requirements because it is designed for resource-constrained embedded devices. In addition to its small footprint, MQTT also offers excellent communication efficiency (even over low-bandwidth networks) and very little overhead (compared to protocols like HTTP). In 3G networks, MQTT’s throughput speed is 93 times that of using HTTP’s Representational State Transfer (REST).MQTT uses minimal methods to indicate operations to be performed on specific topics, thereby implementing a publish/subscribe model. Clients connect to the broker first, then publish or subscribe to topics. Once done, clients disconnect from the broker. The MQTT methods are defined as follows:Connect – Establish a connection to the MQTT broker.Disconnect – Disconnect from the MQTT broker.Publish – Publish a topic on the MQTT broker.Subscribe – Subscribe to a topic on the MQTT broker.Unsubscribe – Unsubscribe from a topic on the MQTT broker.Figure 3 shows a simple interaction between a publisher and a subscriber using the MQTT broker. As shown, the information producer connects to the MQTT broker. Similarly, the information consumer connects to the MQTT broker. The consumer subscribes to a topic (defined here as /home/alarms/1/status). This example topic identifies the status changes of the alarm system for area 1 on the home page. When the producer has information to share, it publishes a message to the broker, and then the broker shares the information with all users subscribed to that topic.Figure 3. Simple interaction between Message Queuing Telemetry Transport clients
Note the topic structure shared here. It resembles a file system hierarchy, which simplifies the topic structure. This hierarchical form of resources is also common in protocol architectures, such as REST.MQTT even allows the use of wildcards to simplify the subscription process. If a user wants to receive the status of all alarms, they can directly subscribe to /home/alarms/+/status, which notifies the user of all alarm status changes. The entire subtree can also be subscribed to using the topic /home/#, which can subscribe to all events under /home.
2.1 Quality of Service
MQTT allows for the definition of Quality of Service (QoS). There are three levels of QoS in MQTT:QoS 0. This level indicates “at most once” delivery (best effort). Messages are not acknowledged, making this a fire-and-forget method.QoS 1. This level indicates “at least once” delivery. Users may receive messages more than once, but acknowledgments are allowed for received messages.QoS 2. The slowest but most guaranteed level of service quality is level 2. QoS 2 indicates “exactly once” and involves a four-phase delivery handshake. This level is the slowest but the most secure.The QoS level you choose will depend on the data and its delivery importance.
2.2 Message Queuing Telemetry Transport Broker
As more IoT devices adopt MQTT as a supporting protocol, you will find MQTT appearing in many open-source applications and products. Intel® IoT Gateway Solution is one such comprehensive IoT solution that employs MQTT.This product line supports secure interactions between sensors, devices, and the cloud. These pre-validated application-ready platforms support excellent manageability, security, and various connectivity options such as ZigBee*, cellular networks, Bluetooth*, USB, Wi-Fi*, and of course, protocols like MQTT and Modbus.Intel offers three versions of the Intel® IoT Gateway based on market needs, each with different input/output options and targeting different fields such as industrial and energy, transportation, and integrated industries. Despite the differences, they all include common manageability and supply, data, and endpoint security, as well as runtime environments. They all run on the secure and stable Wind River* Linux*.The main advantage of the Intel® IoT Gateway is the McAfee® Embedded Control security technology. McAfee® Embedded Control can manage device changes based on policies while tracking all changes, providing complete visibility and explainability for continuous audit trails.SummaryMQTT and Modbus can complement each other to enhance IoT performance. Using Modbus as a local interface to manage devices while using MQTT as a global protocol to extend the range of devices, both play important roles. The Intel® IoT Gateway provides a simple and secure way to build IoT for now and the future.
Recently, many friends have asked me for essential materials for programmers, so I dug out some treasures and am sharing them for free!
Scan the QR code on the poster to get it for free.
