Modbus serial with Node-RED

This provides a simple example of using the Rio to read Modbus data using serial Modbus RTU.


The Modbus device is connected to the Rio USB port through a RS232 to USB Adapter. A small NodeRed flow reads the Modbus registers.


The RS232 to USB Adapter is a Belkin Model: F5U409.

The Rio is good at recognizing various USB adapters, so this specific model is probably not necessary. Here are a few others: RS232 and RS485 SERIAL ADAPTERS FOR RIO
Gearmo Model: GM-FTDI-A12
Sabrent USB to Serial converter
Aluratek Model: AUS100

Verify the adapter is recognized by the Rio using groovManage: System, then Serial Devices.

You should show a serial device similar to below. The device name displayed, /dev/ttySer0 , will be entered into Nodered as a serial device.

Using Nodered Manage Palette, install the node-red-contrib-serial-modbus node.

Place a modbusSerialIN node and a debug node of the flow and connect them.

Double click the Modbus node, and click the pencil icon next to the Port setting, to add a serial device.

Enter the properties for the serial device and click Update.

Enter the Modbus register settings into the Modbus node. This example reads the first 3 holding registers. Click Done.

Click Deploy to send the flow to the Rio. Click the Debug Messages Icon to see the output of the Modbus node, which shows the holding register values.

Here is the NodeRed Flow.

[{"id":"a11d31ab.f68ac","type":"tab","label":"Modbus Serial","disabled":false,"info":""},{"id":"f509d4a.9024528","type":"modbusSerial in","z":"a11d31ab.f68ac","port":"3e468e22.842a02","slaves":"1","start":"1","count":"3","dtype":"holding","period":"10","topic":"","name":"Read Holding Regs 1-3","x":200,"y":200,"wires":[["aeb3845a.ae6e38"]]},{"id":"aeb3845a.ae6e38","type":"debug","z":"a11d31ab.f68ac","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":410,"y":200,"wires":[]},{"id":"3e468e22.842a02","type":"modbusSerialConfig","z":"","port":"/dev/ttySer0","baud":"19200","data":"8","parity":"none","stop":"1","name":""}]


I cheated a bit since I did not have a real Modbus Serial RTU device available.

A utility called Simply Modbus Slave was used on the PC to simulate the Modbus device.



Nice Post! Thanks for all the good info.

Great information on getting the Modbus data into Node-Red. In my case, when I used a Modbus scanner like CAS Modbus Scanner, I got the following:

which correctly showed the value I was after (1143).
However, when I read the same data in Node-RED using the method outlined above, I got the following:

I have since learned that (for my particular device, which is an atmosphere controller) Node-Red is outputting as 16 bit registers, but the debug is showing each byte as decimal. So the first number has ms byte 4 and ls byte 119, which is 4*256 + 119 = 1143 which is exactly what was expected. This node will help do the conversion.

1 Like

I have discovered an issue whereby I am getting a “Timed Out” message after about 10-12 hours of readings (taken every 30 sec). It happens regardless of the controller that I am reading from. When I redeploy, it works fine again (like it is waiting to be “manually” restarted). My solution would be to put an Inject node that runs whenever a Timed Out message is detected , but where can I put an Inject Node if there are no wire connections on the Modbus Serial In node? See my flow below which shows the message I get on one of the controllers (again, it happens on the other one, but it not depicted here).

Very odd error… And after 10-12 hours. Phew, this is going to be ‘fun’ to debug…

Is this on a RIO?
Is it using a USB to Serial adapter? If so, are you using a USB hub?

What does the Node-RED log show? Often there is more information in the log than in the debug tab.

It’s running on a Raspberry Pi with this adapter. If I had a Rio, I would hook it up and try it with that. We have an EPIC that I could use next week, but not sure if the above USB adapter will play nice with the EPIC.

Huh, never seen an adapter in that form factor before. But yeah, I don’t think the EPIC is going to like it, seem like its not FTDI compatible or even using that chip set. Might work on RIO as it is more flexible in what USB to serial converters it will work with (but we still highly recommend FTDI).

That aside, I would still be checking the Node-RED console log to see if there is any other helpful error reporting.

Not to get too deep into the weeds here, but my Error Log (shown by following the path below) does not have any information whatsoever. Is this something that needs to be turned on?

Yeah, the event log will be blank. I mean the console log.
Where you start Node-RED, that will show whats really going on blow-by-blow.

Thank you. I will check that out and report back what I find.