MQTT and Modbus: comparison of protocols used in gateways for IoT

Original author: M. Tim J
  • Transfer
In the development of the Internet of things, not only completely new technologies are important. An invaluable role here is played by the possibility of integration with the development of past years. And the key to this integration is communication. There are many protocols that allow a huge number of various “things” to connect to the Internet and interact with each other. Today we will talk about a pair of complementary protocols that have found application in IoT. The first is Modbus. It serves to organize communication between devices located close to each other. The second is MQTT. It has much more features, supports work in local networks and on the Internet. With it, you can organize the exchange of data between "things" on a global scale. Modbus

image



- This is a serial data exchange protocol that appeared in 1979 and became the de facto standard for organizing communication between industrial devices. MQTT appeared 20 years later, but despite the difference in age, the joint use of these two protocols allows you to give highly specialized integrated devices all the features that are available when connected to the Internet.

The figure below shows a diagram of the interaction of these protocols, as well as a device that allows such interaction to be organized - a gateway to the Internet of things.


The gateway to the Internet of things allows you to combine the capabilities of MQTT and Modbus.

Let us consider Modbus and MQTT in more detail, examine their features and the possibilities of their joint use in IoT solutions.

Modbus


Over the decades of its existence, Modbus has evolved into a wide range of protocols using various methods of physical communication between devices (for example, the RS-485 interface). At the heart of all these implementations is a sequential protocol built on the basis of the master-slave model. The master sends a request to the slave, and the slave responds to this request. The standard Modbus network has one master, master node and up to 247 slave-slaves. However, it should be noted that a two-byte addressing system can significantly ease this restriction.

Using the RS-485 interface, communication between master and slave devices is carried out using packages that contain a function code and data. This code indicates what action should be taken, for example, the need to read discrete input data, read data from the FIFO queue, and perform a diagnostic operation. The slave device, having received the command and executing it, responds by sending a packet whose structure is very simple. Due to the low computational load that Modbus interaction creates, very different devices can communicate with it using it: from smart controllers to conventional sensors.

From the description you can judge the extreme simplicity of Modbus, but its openness made this protocol the standard de facto for industrial and SCADA systems.

MQTT


MQTT (Message Queuing Telemetry Transport) is a simple open protocol designed specifically for IoT and used to exchange data between devices. The MQTT network includes an MQTT broker, which serves as an intermediary in the interaction of MQTT agents - publishers and subscribers. Publishers publish information intended for subscribers.


The broker, publisher and subscriber in the MQTT network

MQTT is designed for low-power embedded devices, so the computing requirements for its implementation are minimal. In addition to the very low system load, MQTT is characterized by high communication efficiency even in networks with low bandwidth. Moreover, in the structure of data transmitted with its help, there is very little overhead information, that is, in comparison with many other protocols, for example, with HTTP, it almost does not load the network with the transfer of information that is needed only for the protocol to function. According to measurements made in 3G networks, the MQTT bandwidth is 93 times higher than the Representational State Transfer (REST) ​​protocol, which runs on top of HTTP.

MQTT implements the publisher-subscriber model using the minimum number of methods. They serve to indicate the actions to be performed. These actions come down to interacting with a broker and working with topics and messages. Agents connect to the broker, and then either publish topics and messages in them, or subscribe to topics and receive messages published in these topics. Having completed the work, the agent disconnects from the broker. Here's what the MQTT methods look like:

  • Connect - establish a connection with a broker.
  • Disconnect - disconnect from the broker.
  • Publish - Publish a topic to a broker.
  • Subscribe - subscribe to a topic on a broker.
  • Unsubscribe - unsubscribe from the topic on the broker.

Here is a simplified diagram of the interaction between the subscriber and the publisher using the MQTT broker.


The interaction of the subscriber and the publisher The

publisher, which is the source of some data, connects to the broker. The subscriber, the consumer of information, does the same and subscribes to the topic, which is presented here as "/ home / alarms / 1 / status". In this example, this topic publishes information about changes in the state of a home alarm in a certain “zone number 1”. When the publisher has new data, he contacts the broker and publishes a message in this thread. The broker, in turn, sends the published message to everyone who is subscribed to this topic.

Pay attention to the hierarchical structure of the topic name from our example. It looks like a path in a file system. This makes organizing topics easier. In addition, such hierarchical resource naming structures are popular in other protocol architectures, such as REST.

MQTT also allows you to use wildcards, which simplifies the subscription process. If the subscriber, for example, wants to know about the status of all alarm sensors, he can subscribe to a topic like this: “/ home / alarms / + / status”. As a result, it will be notified of alarms in all zones, and not only in “zone No. 1”, as in the above example. You can subscribe to the whole subtree by using the template with the "#" sign. For example, subscribing to “/ home / #” will allow you to receive messages about everything that happens in topics below the “/ home” node.

Quality of service


MQTT supports the indication of the level of quality of service (QoS). Namely, there are three such levels:

  • QoS 0. This layer employs the “maximum one-time message delivery” strategy. The receiver of the message does not confirm their receipt, the sender, accordingly, transmits the message only once, without attempting to retransmit them. This is the send and forget method.

  • QoS 1. Here the approach of "at least one-time message delivery" is applied. It is guaranteed that the receiver will receive a message at least once. In this case, the subscriber can receive the same message several times. And the sender will make repeated attempts to send until he receives confirmation of the successful delivery of the message.

  • QoS 2. This level of quality of service corresponds to the slowest message delivery procedure, but at the same time it is the most reliable. Its main feature is the implementation of the “one-time message delivery” strategy. When using it, a four-step message delivery confirmation procedure is used.

The choice of a specific level of quality of service depends on the characteristics of the data being transferred and on how important it is that they be delivered.

Intel MQTT Brokers and Gateways for the Internet of Things


The growing popularity of MQTT as an important element in the construction of IoT projects has led to the fact that many open source MQTT implementations have been created; it is used in many hardware developments. Intel Gateways for the Internet of Things is one of the industry-leading advanced solutions that supports MQTT.

This family of products enables secure connections between sensors, IoT devices, and cloud services. The gateways are thoroughly tested and ready to install on them the software necessary for the operation of a specific project. They are distinguished by excellent controllability, a high level of security and a wide range of supported methods of communication with the outside world. Among these methods, in addition to traditional wired Ethernet and wireless Wi-Fi, you can find ZigBee, and support for cellular networks, and USB, and, of course, MQTT and Modbus.

If we talk about network capabilities, there are three options for Intel gateways for the Internet of things, they have different configurations of information input-output subsystems. This division is based on market needs. Among such needs, which can be taken into account both individually and in combination, we can note the creation of stationary industrial-grade solutions, economical energy consumption, and the development of solutions for moving objects. But, even with different characteristics, all gateways support management and configuration functions, ensure the security of data transmission and storage, and provide an environment for executing applications. At the same time, the standard gateway OS is the safe and stable Wind River Linux.

A very important advantage of Intel IoT gateways is its support for McAfee Embedded Control security technologies. In particular, thanks to these technologies, it becomes possible to monitor the state of a device based on security policy. Such monitoring the status of the device, tracking all events occurring with it, allows you to organize a fully transparent, continuously operating audit system, the reports of which can be trusted.

Conclusion


MQTT and Modbus are very different technologies, but together they help build reliable IoT solutions. Modbus is used as a local interface for interacting with devices, the role of MQTT is the organization of global communications between system components. Each of them plays an important role. At the same time, Intel Gateways for the Internet of Things supports both of these protocols, in addition to other communication tools and technologies that ensure the stability and security of projects. With the help of such gateways, you can quickly create reliable, modern IoT solutions that will remain relevant in the future.

Also popular now: