Modbus and RS485 (RTU) ethernet gateway periodic communication error

I have just added a ethernet <> RS485 modbus gateway to my system to run my Nilan ventilation system, insted of my USB<>RS485 dongle.
The gateway is a Riot USR-TCP232-410S and its working just fine… However, once every 2-5 minutes I get an timeout read error. The communication still works, but its quite annoying.

This is openhab log:

2020-06-21 23:43:16.468 [ERROR] [wimpi.modbus.io.ModbusTCPTransaction] - execute try 1/1 error: I/O exception: SocketTimeoutException Read timed out. Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@60107f (unit id 30 & transaction 58923). Address: /10.4.28.149:502
2020-06-21 23:43:16.472 [ERROR] [wimpi.modbus.io.ModbusTCPTransaction] - execute reached max tries 1, throwing last error: I/O exception: SocketTimeoutException Read timed out. Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@60107f (unit id 30 & transaction 58923). Address: /10.4.28.149:502
2020-06-21 23:43:16.477 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Try 1 out of 3 failed when executing request (ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@b96278[slaveId=30,functionCode=READ_MULTIPLE_REGISTERS,start=300,length=6,maxTries=3]). Will try again soon. Error was I/O error, so reseting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: SocketTimeoutException Read timed out [operation ID f974a621-4cf4-4962-bd7a-6aca4f5eddcc]

This is the setup of the gateway:

I have tried setting UART packet time to 100-200, makes no change.
I have tried activating ModbusTCP poll, makes no difference.

And this is the Bridge setup in openhab:

Bridge modbus:tcp:myNilan [ host="10.4.28.149", port=502, id=30, reconnectAfterMillis=3000 ] {

In another forum @EjvindHald who is using the same gatway mentioned something about terminating the bus with 120ohm resistance. My setup has not this termination… Is it really required?
Its the same cable and same length used with the USB<>RS485 dongle. But I suspect this new gateway could be more sensitive?

Anyone have an idea? @rossko57 perhaps? :wink:

Diagnosis of gateway issues is complex. There are three sides to it, TCP, serial, and internal. From openHAB, you can only see TCP “not working” and cannot even tell which area to look more closely at.
You have a transient recoverable error, which is good news, but also means you won’t find a solid cause. You’l almost certainly have to resort to try-it-and-see.

Okay, that’s the general stuff. What’s most likely to go wrong?

The gateway has limited processing power divided amongst several tasks, and Modbus binding default settings can hammer it.
It is possible the gateway is just too busy to talk once in a while.
If you haven’t already applied it here, I would recommend reviewing the performance guide


paying attention to the TCP section - reduce your connect/disconnect overheads by settings in the Modbus binding.

It is however more likely to be serial side problems. If a serial transaction messes up, this gateway cannot tell you about it, and just fails the TCP transaction.
It would be nice to inspect the gateways serial error log … but I don’t think it keeps one.
Your settings for RS485 look reasonable, and I assume match the real slave device.
So, to the physical serial bus…

RS485 wiring bus should in theory be terminated with a 120R resistor at both ends.
In reality, you can “usually get away with” one for short wiring runs, or even none for very short. “Short” for RS485 is relative - a few metres is short, but I would do it properly once we get into tens of metres or more than two devices on bus.
This USR box includes a terminator resistor, I think it can be selected by internal link on the PCB , but is enabled from the factory. If in doubt, check with a meter between A and B (gateway powered off, disconnected from bus)
Likewise, a slave device may or may not have an onboard resistor, but these are generally disabled from factory. Again you can check with a meter.

RS485 lines need bias resistors as well - weak resistors that apply a voltage to the line representing a clean “idle” state. Almost all devices include these, certainly the USR box, and you shouldn’t need to worry about these unless something really weird goes on.

Much more worthy of attention is the wiring itself. You MUST use twisted pair cable. It’s not so critical what cable exactly at reasonable lengths, but cat5 is ideal.
Where the cable runs is important - while some proximity to power cables is unavoidable, long runs of RS485 cable parallel to mains power cables will almost certainly introduce noise and glitches.
If this is inescapable, you may need to use shielded (screened) twisted pair, although that is not often needed outside an industrial environment. The shielding should be connected to earth at only one end.

Earth loops can arise on RS485 buses. Grown up RS485 devices (the expensive industrial stuff) has isolated interfaces, but the kind of cheap stuff we use at home does not. This can cause a problem if this box’s “zero volts” is different to that box’s. This is unlikely to be your problem though - on the assumption that your gateway is powered from a wall-wart mini SMPSU or similar that should provide a “floating earth” for your gateway.

Thanks alot Rossko57…

I played around with the tcp reconnectAfterMillis and timeBetweenReconnectMillis paramters… But it dont seem to change anything…

I do believe this is a serial issue as well. However, the cable has not changed in any way. Its a twisted pair. The same length, aprox 5 meters, as when I used the USB dongle. I just disconnected from the USB dongle, and connected it to the USR.
But maybe there is something about the terminating. I actually dont know if the USB dongle was therminated. And I´m not sure if this USR got a terminating resistor. I cant tell from the manual.

So I´m guess I have to investigate this terminating resistor.

Trying to reconcile “I have just added …” with “cable hasn’t changed”.
No matter, your “interference” environment is always subject to change. Got a new microwave? Has a neighbour? Sometimes there is no discernable logic around d these issues.

The USR does have a terminator onboard, usually factory enabled by link on PCB.

Most USB/RS485 dongles have a terminator hardwired. What is the dongle for, no real port on the Nilan thingy?

Yes and this USR is probably more sensible.

Nilan runs 3-wire RS485 interface, A+B- and G

I exhanged the USB dongle with this USR, cause I´m sick and tired of all the USB issues on the Rpi. Ethernet is much more flexible and easier to comprehend.

Yeh, I run only gateways, no direct RS485 to server.

Might be worth trying without G connected at USR end - might make it better or worse.

Thats an easy try. Will test it tomorrow.

It didnt change anything removing the ground wire :frowning: