Gateway: ESP8266 Modbus RTU MQTT + HMI Industrial Panasonic

Given the growth of IoT applications using the MQTT protocol as a base and the Node-RED platform, we have created a possibility for industrial devices or devices using Modbus RTU protocol (RS232 or RS485) to interact with applications or IoT platforms that use MQTTin This Node-RED case.

In the industry there is a large number of Monitoring and Control Devices that have Modbus RTU such as Counters, Meters (Flow, Electrical, Temperature, Humidity, etc.), Industrial Controllers PLC, PAC, HMI Screens, Speed ​​Inverters, For which the only possibility of extracting and concentrating data through OPC servers.

We have configured a module ESP8266 12E NodeMCU as Master Modbus RTU serial via RS232 (CHIP MAX232) to request and send data to a GT01 Industrial Screen Panasonic brand, the reference I have is fed to 5V, The same ESP module is configured as an MQTT client, The routine created in Arduino IDE bridges Modbus read and write registers in this case “Holding Registers” and by the MQTT subscribing and publishing topics.

Since the ESP8266 module has a serial port, we used the softwareserial library to create a second port that would be used only for Modbus RTU allowing programming and debugging without physically interrupting the modbus communication, we added an integrated MAX232 for protocol conversion to RS232.

In this specific case the test we will perform will be based on an industrial device, we will connect a Panasonic HMI GT01 Screen configured as a Modbus RTU slave (RS232) with GTWIN software, why a screen? It would be very boring and simple to use a simulator and we want to implement real hardware.

We will use 10 read registers and 10 write registers between Node-NET and the HMI.

We will explain the sending and receiving methods in Node-Red.

Quick Test HMI Panasonic and Node-RED Dashboard

In this example the HMI is configured as a slave modbus rtu only we will use 2 available registers:

Holding Register [0] – Read

Holding Register [10] – Write

A dashboard has been created in Node-RED and 2 MQTT nodes assigned to Send and Receive Topics have been previously set to the code in ESP8266.

The value entered on the screen will be sent to an MQTT Topic and the value sent from Node-RED for a topic will reach a screen record.

Downloads: Arduino code on the bottom

Node-RED

Receiving Holding Register from MQTT

The Holding Register [0] is received in an MQTT subscription node and the value individually and sent to 2 Widgets Text Node and Gauge Node for display in the Dashboard.

Note: Full explanation below “Node-RED reception from Panasonic HMI”

Sending Records via MQTT to Holding Registers

We add a slider node widget configured to send a value from 0 to 1000 which connects to the MQTT publication node to send the value in the Holding register [10] and connects to the Gauge node to display the change from the dashboard.

Note: Full explanation below “Shipping from Node-RED to Panasonic HMI”

Dashboard Settings

Order of widgets for visualization and control.

Node-RED Dashboard

Full Explanation

The following video will complete the explanation of the connection using 20 registers:

Panasonic HMI GT01 design in GTWIN

The screen is configured as slave Modbus RTU connection RS232, Previously on the GT01 Screen 2 screens have been designed the GTWIN Configuration software:

Reading from 3 Holding Registers [0] [1] [2] from 3 MQTT records.

Writing 3 Holding Registers [10] [11] [12] to 3 MQTT records.

Node-RED

In the previous test we only used 2 records in this new case we will use 10 read registers and 10 write registers.

MQTT Client Configuration on Node-RED

In this case we have previously installed the MQTT “Mosquitto” Broker installed on my Linux server (Lubuntu), to that MQTT broker connect Node-NET and the ESP8266 module.

This is the configuration of the connection MQTT of Node-RED to connect with mosquito and therefore with the ESP8266.

Shipping from Node-RED to HMI Panasonic

An Inject Node “Send 10 Registers” has been used which contains 10 values separated by commas “,” example: “1,2,3,4,5,6,7,8,9,10,” Note: have Note that modbus handles 16-bit integers to not send larger values.

It connects to the MQTT publishing node “MQTT_Holding_Array- Holding Registers [0] – Holdin Registers [9]”and 10 values will be sent to the top 10 holding registers on the screen.

Node-RED reception from Panasonic HMI

We have created 2 methods of receiving data from the ESP8266 Module:

Group reception 10 records a single MQTT topic

In this case, a MQTT subscription node “Holding_to_MQTT_Array – Holding Register [10] … Holding Register [19]” and the holding_to_MQTT_Array topic are used and you will receive all 10 registers of the following form 1,2,3, 4,5,6,7,8,9,10.

Individual reception 1 record 1 MQTT topic

Since in certain cases a value is required to be updated faster than others, it has been created that the ESP8266 sends in 1 single topic the value of 1 single holding register in specific, each subscriber node MQTT request individually, example Node “Holding Register [10]” and the “Holding_to_MQTT_1”topic.

Connections

Recommendations for implementation

Use Serial Communication Speed ​​9600 baud.

Depending on the number of modbus registers read, the tdelay variable must be modified, given a time for reading and deleting the modbus buffer, if there are modbus read failures, not exceeding 10 requested registers, we are still optimizing the modbus readings and Note that using softwareserial emulates a serial port.

There is another possibility of failure in this case we are making a constant sending of records both mqtt and modbus, it would be advisable to only send or receive MQTT records if required, not at all times as in this case.

Conclusions

In the industry we have seen devices such as Modbus RTU meters, and adding an ESP8266 and a TTL to RS232 (RS485 or RS485) we could monitor our electricity consumption without requiring an OPC or specific Hardware, as mentioned earlier MQTT protocol has been implemented in a variety of IoT applications and there are now a large variety of local and cloud platforms that could host our data.

To take into account, if you want to implement the tests described above in a real project, we detail that we have not tested 24/7 hardware esp8266, should take into account materials (pcb, welding, wiring), electrical protections, electrical insulation , Ambient temperature, Wifi signal strength, among other variables, but we consider that for basic automation applications taking into account the above mentioned would work correctly.