📜 ⬆️ ⬇️

MQTT and Modbus: a comparison of the protocols used in IoT gateways

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 developments of past years. And the key point of such 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.

image

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 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 to give highly specialized integrated devices all the features that are available when connected to the Internet.
')
The figure below shows the scheme of interaction between these protocols, as well as the device that allows organizing such interaction - a gateway for the Internet of things.


Gateway for the Internet of Things allows you to combine the capabilities of MQTT and Modbus

Let's take a closer look at Modbus and MQTT, examine their features and the possibility of sharing them 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 of devices (for example, RS-485 interface). At the heart of all these implementations is a serial protocol built on the master-slave model. The master sends the slave a request, and the slave responds to the request. In the standard Modbus network, there is one main, leading node and up to 247 subordinate – knowledgeable ones. However, it should be noted that a two-byte addressing system can significantly relax this restriction.

Using the RS-485 interface, communication between master and slave devices is accomplished using packets that contain 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, perform a diagnostic operation. The slave device, receiving the command and executing it, responds by sending a packet, the structure of which is very simple. Due to the low computational load that Modbus interaction creates, very different devices can “communicate” with its use: from intelligent controllers to ordinary sensors.

From the description it is possible to judge the extreme simplicity of Modbus, but its openness has made this protocol 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. An MQTT network includes an MQTT broker that mediates the interaction of MQTT agents — publishers and subscribers. Publishers publish information intended for subscribers.


Broker, publisher and subscriber in the MQTT network

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

MQTT implements the publisher-subscriber model using a minimum number of methods. They serve to indicate the actions to be performed. These actions boil down to interacting with a broker and working with topics and posts. Agents connect to the broker, and then either publish the topics and posts in them, or subscribe to the threads and receive messages in these topics published. Upon completion, the agent disconnects from the broker. Here are the MQTT methods:


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


Subscriber / Publisher Interaction

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 a topic that is presented here as “/ home / alarms / 1 / status”. In this example, this topic publishes information about changes in the state of the home alarm system in some “zone number 1”. When the publisher has new data, he contacts the broker and publishes a message in this thread. The broker, in turn, transmits the published message to everyone who has signed on this topic.

Pay attention to the hierarchical structure of the theme name from our example. It is similar to the file system path. It simplifies the organization of topics. In addition, similar hierarchical naming structures of resources are popular in other protocol architectures, for example, in REST.

MQTT, in addition, allows the use of wildcard characters, 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 the following: "/ home / alarms / + / status". As a result, he will be notified of alarms in all zones, and not only in “zone No. 1”, as in the above example. You can subscribe to an entire subtree of topics using a template with a “#” sign. For example, a subscription to “/ home / #” will allow you to receive messages about everything that happens in the topics below the node “/ home”.

Quality of service


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


The choice of a specific level of quality of service depends on the characteristics of the transmitted data and on how important it is that they are 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 a variety of hardware developments. Intel's Internet Gateway is one of the industry-leading advanced solutions that MQTT supports.

This product family allows you to establish secure connections between sensors, IoT devices, and cloud services. Gateways are thoroughly tested and are ready to install on them the software necessary for the operation of a specific project. They are distinguished by excellent handling, high 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, support for cellular networks, and USB, and, of course, MQTT and Modbus.

If we talk about network capabilities, then there are three options for Intel Internet gateways of things, they have different configurations of input / output subsystems. This division is based on market needs. Among such needs, which can be taken into account both individually and in combinations, are the creation of stationary industrial-class solutions, economical energy consumption, the development of solutions for mobile 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 the execution of applications. At the same time, the standard OS of gateways is a secure and stable Wind River Linux.

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

Conclusion


MQTT and Modbus are very different technologies, but together they help build robust IoT solutions. Modbus is used as a local interface for interacting with devices, the role of MQTT is the organization of global connections between system components. Each of them plays an important role. At the same time, Intel Gateways for the Internet of Things support both of these protocols, in addition to other communications 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.

Source: https://habr.com/ru/post/304228/


All Articles