Modbus Read Node via Modbus TCP in Node Red

Dear Guys.
I'm use Modbus Read node from default library Modbus to read data from modbus Server.
The connection was established and work Ok.
But there is a small problem.
when Connection is normal, Modbus Read will return layload normally with array result.
But if because some of reasons, the server lost connection with modbus, the payload will hod the last result before lost connection. I don't want like that.
I want, if connection lost., Modbus read will return array with all elements in the results array are zero.
Is that Posible?
Many thank

In your Modbus read node try enabling the option "Empty msg on Modbus fail"

Its not going to do exactly what you need which is all elements to be zero .. but it should produce an empty msg .. which can give you an indication of a failed connection.

That msg can then be manipulated to whatever you need.

I tried your solution, but it l also do not work

Add a debug node after the modbus node and show us what it shows when the connection fails.

Hi Colin
When Rad Modbus or Modbus Flex getter lost connection, no message was shoed via debug.

You said in your first post that it keeps sending the old data

If you want to take action when no data are received then use a Trigger node. Set it to Send Original Message, Then Wait For 10 seconds, then Send whatever message you need. Then if there is a gap of 10 seconds in the data stream it will send the message you have configured.

Also, if you just need to update a display to show no data then you can tell the Trigger node to send the timeout message to the second output and use that output to send an appropriate value to the displays.


Dear Sir
I used function node in front of Modbus Flext getter.
I mean that, when lost connection with server, no output payload.

Use a Trigger node as I suggested.

Connect the Trigger node to the output of the modbus node, obviously.

HI Guys.
I also tried to use trigger. But it still didn't resolce problem

There was a breaking change, for a few years now, in the latest versions of the Modbus nodes and "Empty msg on Modbus fail" isnt working when there is a connection failure.

In your terminal go to your .node-red folder and run

npm i node-red-contrib-modbus@5.23.3

This will install the older version of modbus 5.23.3

Restart node-red and test again if with this specific version you get an empty msg.

Please export you flow with the trigger node so I can see what you have done.

Dear Sir.
Can you remote directly to my node-red and check
many thank

Select the nodes that you showed the image of earlier, plus the Trigger node, then hit CTRL+E and click Export to Clipboard.

Then paste the flow here. In order to make flow usable it is necessary to surround it with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

See this post for more details - How to share code or flow json