System and method for transmitting Modbus message based on MQTT
Through the MQTT-based transmission Modbus message system, the problem of missing identifiable register addresses in the Modbus protocol is solved, and data acquisition efficiency and real-time improvement is achieved, data accuracy and consistency are ensured, and implementation is reduced. Cost, suitable for low-cost and high-efficiency data acquisition in industrial sites.
Patent Information
- Application Number
- CN202411288705.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2024-12-20
AI Technical Summary
The Modbus protocol lacks a recognizable register address value for the packets reported to the cloud platform on the device, which causes the industrial IoT platform to be unable to directly identify the object model acquisition points corresponding to the data, resulting in low data acquisition efficiency, poor real-time performance and high data processing complexity.
Using MQTT-based transmission Modbus message system, the transmission module and the MCU chip are used as edge gateways to convert between Modbus data and MQTT messages, poll the Modbus device regularly, read data and add message headers, The end of the message and the register address ensures the integrity and recognition of the data, and is transmitted to the industrial Internet of Things platform via Ethernet or wireless network.
It improves the efficiency and real-time nature of data acquisition, ensures the accuracy and consistency of data, enhances the universality of the system, reduces the implementation cost, and is suitable for low-cost and high-efficiency industrial data acquisition.
Smart Images

Figure CN119172195A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of Modbus message systems, and in particular, relates to a Modbus message transmission system based on MQTT and a method thereof. Background Art
[0002] Modbus is a widely used serial communication protocol, originally developed by Schneider in 1979; Modbus supports multiple physical layers, including RS-232, RS-485 and Ethernet; the Modbus protocol is mainly used to connect industrial electronic equipment, sensors, actuators, etc., and has been widely used in the field of industrial automation due to its simplicity, openness and easy implementation; Modbus can be used to read and write device registers, control the status of I / O points, and realize data exchange between devices; Modbus is often used in factory automation, building automation, energy management systems and other scenarios.
[0003] MQTT is a lightweight publish / subscribe message transmission protocol designed for low-bandwidth, high-latency or unreliable networks. MQTT is based on the TCP / IP protocol stack and supports a variety of network environments, including the Internet and local area networks. One of the design goals of the MQTT protocol is to maintain minimal overhead and minimize battery power usage, which makes it widely used in the Industrial Internet of Things. MQTT supports a one-to-many message distribution mode, that is, a device can send data to multiple subscribers, and is often used in scenarios such as remote monitoring, equipment management, and data collection.
[0004] The Industrial Internet of Things platform provides a complete set of tools and services for connecting, managing and analyzing data generated by industrial equipment; these platforms usually have functions such as device management, data visualization, and data analysis; the object model is a standardized model used in the Industrial Internet of Things platform to describe device attributes, functions, and services; the object model defines the device's capability set and how to interact with these devices through APIs, which helps to standardize device interfaces and enable different devices to collaborate with each other more easily.
[0005] However, due to the characteristics of the Modbus protocol, the messages reported by the device to the cloud platform lack identifiable register address values, which makes it impossible for the industrial Internet of Things platform to directly identify which object model collection point the data in the message corresponds to; although the ModbusTCP protocol improves the data transmission rate and network coverage, it still cannot adapt to most devices; this problem leads to low data collection efficiency and poor real-time performance, and also increases the complexity of data processing; therefore, in order to solve this problem, an effective method is needed to improve data collection efficiency and real-time performance, and ensure the accuracy and consistency of data. Summary of the invention
[0006] The main technical problem to be solved by the present invention is to provide a Modbus message transmission system based on MQTT and a method thereof, which can improve the efficiency and real-time performance of data acquisition while ensuring the accuracy and consistency of data and the versatility of equipment.
[0007] In order to solve the above technical problems, the present invention provides the following technical solutions: A Modbus message transmission system based on MQTT includes a codec transmission module, the input end of the codec transmission module is connected to an existing Modbus device via a wireless or wired network, the codec transmission module is used to periodically poll the Modbus device, read data, and convert Modbus to TCP / IP, and transmit it via Ethernet or a wireless network, and the input end of a DTU or a transparent transmission module is connected to an industrial Internet platform via a wireless or wired network.
[0008] The following is a further optimization of the above technical solution by the present invention: The encoding and decoding transmission module includes an external MCU chip and a transmission module. The external MCU chip serves as an edge gateway and is responsible for processing the conversion between Modbus data and MQTT messages.
[0009] Further optimization: The external MCU chip is used to implement Modbus polling and is responsible for processing the conversion between Modbus data and MQTT messages.
[0010] Further optimization: The transmission module adopts one or more combinations of DTU, WiFi module, and 4G module; the transmission module is connected to the industrial Internet platform through a wireless or wired network, so that the external MCU chip transmits data between the transmission module and the industrial Internet platform.
[0011] The present invention also provides a method for transmitting Modbus messages based on MQTT, based on the above-mentioned Modbus message transmission system based on MQTT, including data collection and reporting, platform service data processing and response processing; wherein data collection and reporting includes the following steps: S1, the external MCU chip periodically polls the Modbus device to read data; S2, process the read data, encapsulate the data, add the message header, message footer and register address; S3, encapsulating the processed data into an MQTT message according to a predefined format; S4, the external MCU chip sends the MQTT message to the industrial Internet of Things platform through the transmission module.
[0012] Further optimization: In step S2, the message header: the message length is 2 bytes, and the content is the constant 0xFF 0xAA; it is used to ensure the integrity of the message; Message tail: The message length is 1 byte, and the content is the constant 0x0D; it is used to ensure the integrity of the message; Register address: The message length is 2 bytes, and the content is the register address, which is used to identify the message; Modbus data packet: Modbus raw data packet.
[0013] Further optimization: Platform service sends data processing, including the following steps: X1. The industrial Internet of Things platform sends service instructions to the external MCU chip through the MQTT protocol and transmission module; X2, after receiving the service command, the external MCU chip unpacks it and converts it into a Modbus message; X3, the external MCU chip sends the converted Modbus message to the corresponding Modbus device.
[0014] Further optimization: In step X1, the data sent by the platform service includes a message header and a message ID, wherein the message header: the message length is 2 bytes, and the content is a constant 0xFF 0xDD; it is used to ensure the integrity of the message; Message ID: The message length is 6 bytes, and the content is a self-incrementing unique ID; it is used to ensure the uniqueness of the message; Modbus data packet: Modbus raw data packet.
[0015] Further optimization: Response processing, including the following steps: Y1. After the Modbus device executes the service instruction, it reports the execution result in the form of a Modbus message through the external MCU chip; Y2. The external MCU chip converts the Modbus message into an MQTT message and sends it back to the Industrial Internet of Things platform.
[0016] Further optimization: the device response reporting data in step Y2 comprises: Message header: The message length is 2 bytes, and the content is the constant 0xFF 0xDD; it is used to ensure the integrity of the message; Message ID: The message length is 6 bytes, and the content is the message ID when the platform issues the instruction; it is used to ensure the uniqueness of the message; Modbus data packet: Modbus raw data packet.
[0017] The present invention adopts the above technical scheme, which is ingenious in conception and solves the problem that the Modbus original message lacks identifiable register address values, improves the efficiency and real-time performance of data acquisition, and ensures the accuracy and consistency of the data; in addition, by using an additional MCU chip as an edge gateway, which is responsible for processing the conversion between Modbus data and MQTT messages, it not only enhances the versatility of the system, but also reduces the implementation cost, and is suitable for industrial sites with low-cost and high-efficiency data acquisition.
[0018] The present invention is further described below in conjunction with the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 A result block diagram of the system in an embodiment of the present invention; Figure 2 This is a schematic diagram of the composition of the dynamically reported data in an embodiment of the present invention; Figure 3 This is a schematic diagram of the data composition sent in an embodiment of the present invention; Figure 4 The figure is a schematic diagram of the composition of response reporting data in an embodiment of the present invention. DETAILED DESCRIPTION
[0021] like Figure 1-4 As shown, a Modbus message transmission system based on MQTT includes a codec transmission module, the input end of the codec transmission module is connected to an existing Modbus device via a wireless or wired network, the codec transmission module is used to periodically poll the Modbus device, read data, and convert Modbus to TCP / IP, and transmit it via Ethernet or a wireless network, and the input end of the DTU or transparent transmission module is connected to the industrial Internet platform via a wireless or wired network.
[0022] In this embodiment, the existing equipment is industrial equipment with a PLC controller or other MCU microcontroller. These devices are usually on-site controllers or sensors, which exchange data through the Modbus protocol; these devices usually have certain computing power and storage space and can perform basic data processing tasks.
[0023] In this embodiment, the codec transmission module is used to provide devices with wireless or wired network connections, supporting Modbus to TCP / IP conversion; wherein the codec transmission module is a bridge between industrial field equipment and remote monitoring systems; they can convert Modbus RTU or ASCII protocol data into TCP / IP protocol data for transmission via Ethernet or wireless networks.
[0024] In this embodiment, the encoding and decoding transmission module has a stable network connection capability, which can ensure the reliability and real-time performance of data transmission.
[0025] The encoding and decoding transmission module includes an external MCU chip and a transmission module. The external MCU chip serves as an edge gateway and is responsible for processing the conversion between Modbus data and MQTT messages.
[0026] In this embodiment, the external MCU chip is used to implement Modbus polling, change reporting and other functions, thereby improving data collection efficiency in a low-cost manner; the external MCU chip serves as an edge gateway, responsible for processing the conversion between Modbus data and MQTT messages.
[0027] In an embodiment, the external MCU chip has a lower cost and a smaller size, and is suitable for integration into existing industrial equipment; the external MCU chip can realize functions such as parsing Modbus messages, mapping data, and constructing MQTT messages.
[0028] The transmission module adopts one or more combinations of DTU (Data Transfer Unit), WiFi module, and 4G module.
[0029] The transmission module is connected to the industrial Internet platform via a wireless or wired network, so that the external MCU chip transmits data between the transmission module and the industrial Internet platform.
[0030] The external MCU chip periodically polls existing devices with the Modbus protocol to read data; processes the read data, encapsulates the data, adds a message header, a message tail and a register address; encapsulates the processed data into an MQTT message according to a predefined format; and sends the MQTT message to the industrial Internet of Things platform through a transmission module.
[0031] The industrial Internet of Things platform sends service instructions through the MQTT protocol; after the external MCU chip receives the service instructions, it unpacks them and converts them into Modbus messages; and sends the converted Modbus messages to the corresponding Modbus devices.
[0032] In this embodiment, the external MCU chip can be a single-chip microcomputer or a PLC, etc.; the external MCU chip has certain computing power and storage space, and can perform basic data processing tasks.
[0033] The present invention also provides a method for transmitting Modbus messages based on MQTT, based on the above-mentioned Modbus message transmission system based on MQTT, including data collection and reporting, wherein the data collection and reporting includes the following steps: S1, the external MCU chip periodically polls the Modbus device to read data; S2. Process the read data, encapsulate the data, and add a message header, a message footer, and a register address.
[0034] In step S2, the read data is processed, the data is encapsulated, and a message header, a message footer and a register address are added, so that the integrity of the data can be ensured, and the platform end can recognize the address of the register, thereby ensuring efficient recognition of Modbus.
[0035] In step S2, the message header: the message length is 2 bytes, and the content is the constant 0xFF 0xAA; it is used to ensure the integrity of the message; Message tail: The message length is 1 byte, and the content is the constant 0x0D; it is used to ensure the integrity of the message; Register address: The message length is 2 bytes, and the content is the register address, which is used to identify the message; Modbus data packet: Modbus raw data packet.
[0036] S3. Encapsulate the processed data into an MQTT message according to a predefined format.
[0037] S4, the external MCU chip sends the MQTT message to the industrial Internet of Things platform through the transmission module.
[0038] A method for transmitting Modbus messages based on MQTT also includes data processing sent by a platform service, including the following steps: X1. The industrial Internet of Things platform sends service instructions to the external MCU chip through the MQTT protocol and transmission module; X2. After receiving the service command, the external MCU chip unpacks it and converts it into a Modbus message.
[0039] When the platform issues instructions in step X1, in order to ensure the uniqueness of the message, a fixed message header and a unique message ID are added to form the platform service sending data.
[0040] The data sent by the platform service includes a message header and a message ID, wherein the message header: the message length is 2 bytes, and the content is a constant 0xFF 0xDD; it is used to ensure the integrity of the message; Message ID: The message length is 6 bytes, and the content is a self-incrementing unique ID; it is used to ensure the uniqueness of the message; Modbus data packet: Modbus raw data packet.
[0041] X3, the external MCU chip sends the converted Modbus message to the corresponding Modbus device.
[0042] A method for transmitting Modbus messages based on MQTT also includes response processing, including the following steps: Y1. After the Modbus device executes the service instruction, it reports the execution result in the form of a Modbus message through the external MCU chip; In step Y1, when the Modbus protocol device receives the write instruction and completes the execution, it will actively report the issued write instruction to the platform to indicate that the execution has been successful; the message format is the same as the instruction format issued by the platform.
[0043] Y2. The external MCU chip converts the Modbus message into an MQTT message and sends it back to the Industrial Internet of Things platform.
[0044] The device response reporting data in step Y2 comprises: Message header: The message length is 2 bytes, and the content is the constant 0xFF 0xDD; it is used to ensure the integrity of the message; Message ID: The message length is 6 bytes, and the content is the message ID when the platform issues the instruction; it is used to ensure the uniqueness of the message; Modbus data packet: Modbus raw data packet.
[0045] The present invention adopts the above technical solution to improve the efficiency and real-time performance of data acquisition and ensure the accuracy and consistency of data; in addition, by using an external MCU chip as an edge gateway, not only the versatility of the system is enhanced, but also the implementation cost is reduced; this solution is particularly suitable for industrial sites that require low-cost and high-efficiency data acquisition.
[0046] For those skilled in the art, according to the teachings of the present invention, without departing from the principles and spirit of the present invention, changes, modifications, substitutions and variations made to the implementation methods are still within the protection scope of the present invention.
Claims
1. A Modbus message transmission system based on MQTT, characterized in that: It includes a codec transmission module, the input end of which is connected to an existing Modbus device via a wireless or wired network. The codec transmission module is used to periodically poll the Modbus device, read data, convert Modbus to TCP / IP, and transmit it via Ethernet or a wireless network. The input end of the DTU or transparent transmission module is connected to the industrial Internet platform via a wireless or wired network.
2. A Modbus message transmission system based on MQTT according to claim 1, characterized in that: The encoding and decoding transmission module includes an external MCU chip and a transmission module. The external MCU chip serves as an edge gateway and is responsible for processing the conversion between Modbus data and MQTT messages.
3. A Modbus message transmission system based on MQTT according to claim 2, characterized in that: The external MCU chip is used to implement Modbus polling and is responsible for processing the conversion between Modbus data and MQTT messages.
4. A Modbus message transmission system based on MQTT according to claim 3, characterized in that: The transmission module adopts one or more combinations of DTU, WiFi module, and 4G module; the transmission module is connected to the industrial Internet platform through a wireless or wired network, so that the external MCU chip transmits data between the transmission module and the industrial Internet platform.
5. A method for transmitting Modbus messages based on MQTT, based on a system for transmitting Modbus messages based on MQTT according to claim 4, comprising data collection and reporting, platform service data processing and response processing; wherein data collection and reporting comprises the following steps: S1, the external MCU chip periodically polls the Modbus device to read data; S2, process the read data, encapsulate the data, add the message header, message footer and register address; S3, encapsulating the processed data into an MQTT message according to a predefined format; S4, the external MCU chip sends the MQTT message to the industrial Internet of Things platform through the transmission module.
6. A method for transmitting Modbus messages based on MQTT according to claim 5, characterized in that: In step S2, the message header: the message length is 2 bytes, and the content is the constant 0xFF 0xAA; it is used to ensure the integrity of the message; Message tail: The message length is 1 byte, and the content is the constant 0x0D; it is used to ensure the integrity of the message; Register address: The message length is 2 bytes, and the content is the register address, which is used to identify the message; Modbus data packet: Modbus original data packet.
7. A method for transmitting Modbus messages based on MQTT according to claim 6, characterized in that: The platform service sends data for processing, including the following steps: X1. The industrial Internet of Things platform sends service instructions to the external MCU chip through the MQTT protocol and transmission module; X2, after receiving the service command, the external MCU chip unpacks it and converts it into a Modbus message; X3, the external MCU chip sends the converted Modbus message to the corresponding Modbus device.
8. A method for transmitting Modbus messages based on MQTT according to claim 7, characterized in that: In step X1, the data sent by the platform service includes a message header and a message ID, wherein the message header: the message length is 2 bytes, and the content is a constant 0xFF 0xDD; it is used to ensure the integrity of the message; Message ID: The message length is 6 bytes, and the content is a self-incrementing unique ID; it is used to ensure the uniqueness of the message; Modbus data packet: Modbus original data packet.
9. A method for transmitting Modbus messages based on MQTT according to claim 8, characterized in that: Response processing includes the following steps: Y1. After the Modbus device executes the service instruction, it reports the execution result in the form of a Modbus message through the external MCU chip; Y2. An external MCU chip converts the Modbus message into an MQTT message and sends it back to the Industrial Internet of Things platform.
10. A method for transmitting Modbus messages based on MQTT according to claim 9, characterized in that: The device response reporting data in step Y2 comprises: Message header: The message length is 2 bytes, and the content is the constant 0xFF 0xDD; it is used to ensure the integrity of the message; Message ID: The message length is 6 bytes, and the content is the message ID when the platform issues the instruction; it is used to ensure the uniqueness of the message; Modbus data packet: Modbus original data packet.
