Description
Modbus devices are being widely used in industrial applications. Condition monitoring, building automation, energy, gas and oil industries all are using counters and meters which are communicating via Modbus-RTU or Modbus-TCP protocols. This article demonstrates how to read data from Modbus supported devices and to store it in TeamViewer-IoT Cloud using Node-Red programming tool and TeamViewer-IoT Agent running on Linux based environment.
Hardware setup
For this article we will use the following hardware setup:
- SDM-230 Modbus-RTU energy meter
- RS-485 to UART TTL level converter
- Raspberry Pi 3 Model B
SDM-230 is an energy-meter which is measuring voltage, current, active and reactive powers, power factor and other energy related measurements. All the measurements data are 32bit IEEE754 formatted and located in the 16bit input registers. In this article we will read voltage measurments.
Below table shows the register addresses of mentioned measurements.
Register Address
Description
Unit
High Byte
Low Byte
30001
Voltage
Volt
00
00
30007
Current
Ampere
00
06
30013
Active Power
Watt
00
0C
The Raspberry Pi is connected to the RS-485 interface of the energy-meter. As the Raspberry Pi does not have a RS-485 interface we need a level converter to translate TTL levels of the UART interface.
The bellow picture is taken from the real hardware setup:
Software requirements
Developing the program
After installing all the required software packages open the Node-Red environment in your browser. On the left panel you should see “modbus” and “TeamViewer Iot” sections. Build the program as demonstrated in below picture using “Modbus Read”, “functions”, “teamvieweriot” and nodes.
First, we need to configure the “Modbus Read” node to use the “/dev/ttyS0” interface of the raspberry pi and then to read voltage data which is stored in 30001 and 30002 input registeres.
The “function” node is used to convert data from binary to decimal format and to create a JSON data which can be parsed by “teamvieweriot” node. Configure the “function” node as illustrated in below picture.
For your convenience please find the code in the text format below.
var rawData = new ArrayBuffer(4);
var fltView = new Float32Array(rawData);
msg.payload = {"voltage":parseFloat(fltView[0].toFixed(1))};
msg.topic = "voltage";
node.status({fill:"blue",shape:"ring",text:msg.topic + ":" + msg.payload.voltage});
return msg;
After applying all the above-mentioned steps, you will have the data in you TeamViewer IoT cloud.