How to connect Modbus device to TeamViewer IoT
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
- Linux Debian, Ubuntu, Raspbian and so on
- TeamViewer IoT Agent installed and provisioned to an account
- TeamViewer IoT Device SDK for Node.js0.1 and higher
- Node-Red v1.0 and higher
- Node-Red Modbus plugin
- TeamViewer IoT Node-Red plugin
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.
Comments
-
Can you provide more details about how to connect to the Raspberry Pi the RS-485 to UART TTL level converter? Both about the pinout of the RPI and the converter and about the communication software. Is it possible to use instead one of the RPI USB connector with an USB-RS485 converter?
0 -
Hi DAChe,
In this example we have connected rs-485 converter to serial pins on the RPi. RXD0 and TXD0. But you also can use USB to serial converter. In that case please make sure to change the resource for the serial interface from /dev/ttyS0 to appropriate one in Node-Red application.
Regards
Tech Support IoT
1