HTTP Modbus Converter Linux
![](https://habrastorage.org/getpro/habr/upload_files/d12/8b6/5e4/d128b65e46d37f9207230ae9c2bf8a4b.jpg)
In the world of industrial automation, HMI interfaces are outdated, they look scary and there is an opinion that the more expensive the hardware and software complex, the better it will work. Young people who can draw beautiful WEB-faces do not meddle in this business, everyone is scared of the so-called Machine to machine protocols and interfaces, the industry has acquired experienced men who understand what two bytes of data in one Modbus register look like.
So, the article is for those who are faced with the task of converting Modbus RTU TCP into the HTTP protocol, which can then be pulled out onto any colorful web page or other service.
Let's imagine that you have come to a production facility where industrial devices are already installed – temperature sensors, machines that receive/transmit data via the Modbus RTU TCP protocol, and you need to upload some data to the monitoring system. Indeed, the vast majority of monitoring systems will not be able to poll devices via Modbus without a special hardware and software gateway.
We offer free software Node-Red and controller AntexGate and we get a powerful hardware and software complex for converting various protocols. In the previous article, we already looked at the ModbusTCP2ModbusRTU conversion.
The first thing you need to do is install the software product. Node-Redthis is done with one script:
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
Make Node-Red a service after installation:
sudo systemctl enable nodered.service
Reboot the hardware:
sudo reboot
Now we get into the environment of our Node-Red software converter via a web browser using the link gateway ip:1880
In the settings on the right, install the node-red-contrib-modbus plugin.
After the plugin is installed, we proceed to the configuration, this is done just as easily from the web interface. Click the menu button, import, examples, Modbus-HTTP, import.
So, the setup is almost finished, we just need to configure our polling and recording modules to the required Modbus connection parameters.
![Setting up Modbus RTU node reading 4 registers starting from 512 Setting up Modbus RTU node reading 4 registers starting from 512](https://habrastorage.org/getpro/habr/upload_files/9e7/1c2/d8c/9e71c2d8c73c2fa903f6a82d4240a569.png)
So we configure all 4 nodes. In my case, this is a Modbus RTU device poll with the hardware port parameters /dev/ttyRS485-1 115200 – 8 – 1 – N. Another 2 nodes are responsible for automatic reading from preset registers, so I immediately configured reading an array of 4 registers starting with 512, using the Holding Register function. By the way, do not forget to actually connect the end device to the RS485 bus.
Now in the comments block you can find the HTTP API for interaction, we will get acquainted with them below.
## Read
### Flex Read
http://ip:1880/modbus/flex/read?value=0&unitid=1&fc=3&address=0&quantity=1
http://ip:1880/modbus/flex/read?value=0&unitid=1&fc=4&address=0&quantity=1
http://ip:1880/modbus/flex/read?value=0&unitid=1&fc=3&address=0&quantity=5
http://ip:1880/modbus/flex/read?value=0&unitid=1&fc=4&address=0&quantity=5
### Read
http://ip:1880/modbus/read
## Write
### Test HTTP without Modbus
http://ip:1880/modbus/flex/write/test?value=[1,2,3,4,5]&unitid=1&fc=16&address=0&quantity=5
### Flex Write
http://ip:1880/modbus/flex/write?value=10&unitid=1&fc=6&address=0&quantity=1
http://ip:1880/modbus/flex/write?value=[1,2,3,4,5]&unitid=1&fc=16&address=0&quantity=5
### Write
http://ip:1880/modbus/write
I was interested in a couple of queries that worked great.
First, we test the recording function – we write the value 123 to the Modbus RTU device with the address 16, function 6 in register 512, and the recording length is 1 value. You can also write arrays at once, for example [1,2,3,4,5] then the length of the record is accordingly 5.
Now let's check whether our value was written to the required address space and read the state of 5 registers starting with 512 using function 3.
As we can see, the value has been recorded. Now we can embed our data into any web application.
The AntexGate controller in conjunction with Node-Red or other software is an excellent universal solution for processing, sending and storing data. I apologize for the advertising, but you can implement the above project on any hardware and any OS.
Join our community at Telegram there are instructions for the controller.
You can get hardware for testing, write to the mail: info@antexcloud.ru (for three months for legal entities and individual entrepreneurs)