Modbus Failure on State Sending

I have a code, that sends data over modbus to a device. it works. But every so often, i get a warning:
"Modbus Failure on State sending Get more about it by logging"


I'm not even sending data at the moment and I get this warning..
What is this error? How do I "log" it to get more information?

Are you absolutely certain of that? Click the node id above the message and it will take you to the node generating the error, then add a debug node showing what is going into that node to check you are not passing it anything.

maybe the Modbus Config Node tries by itself to reconnect, if the Reconnect on timeout is checked.


regardless, there is a problem with the connection.

  1. When you see this error, does the modbus connection ever recover or do you have to restart Node-red?
  2. There were a few important issues fixed with the latest release v5.15.0 of the Modbus nodes.
    What version version do you have and what version of Node.js ?

I did and it shows a modbus flex write node. I put a debug node in front to monitor the payload, and I see nothing when the error/warning is thrown.

My reconnect on Time out is checked.


My connection is good though. I'm reading from the this client the entire time. it's the modbus flex write that's giving me fits.

NR is telling me to log the errors to see more information. How do I do log the errors or pull the error logs?

hmm .. when you say "entire time" .. how often is that ? every second ? what happens if the modbus connection to that device is preoccupied because you are doing continuous reads and the write command fails. I dont know how modbus handles that but you can try increasing the Queue delay to allow the device to close the previous connection? (maybe)

Debug will be activated by starting Node-RED with debug mode
You can read how to do that here

ps. you didnt tell us if you are on the latest version of Modbus nodes v5.15.0

after further testing .. i got some error also with the Modbus Read node. Seems they're still a bit buggy.

Try this flow that uses the Flex Getter and Flex Write instead and see if you get it to fail
(edit appropriately to match your device settings)

[{"id":"7b1cceebbc6b3155","type":"debug","z":"54efb553244c241f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":300,"wires":[]},{"id":"accdd8a5e0ae9d64","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":170,"y":320,"wires":[["d419c64748d8892d"]]},{"id":"70290fbbbe462b5e","type":"modbus-flex-getter","z":"54efb553244c241f","name":"","showStatusActivities":true,"showErrors":true,"logIOActivities":false,"server":"ebeab3422d31a778","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"x":560,"y":320,"wires":[["7b1cceebbc6b3155"],[]]},{"id":"d419c64748d8892d","type":"function","z":"54efb553244c241f","name":"","func":"msg.payload = { value: msg.payload, 'fc': 1, 'unitid': 1, 'address': 1, 'quantity': 8 }\nreturn msg\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":320,"wires":[["70290fbbbe462b5e"]]},{"id":"89369c2bcbeb76ca","type":"debug","z":"54efb553244c241f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":480,"wires":[]},{"id":"acefe3edeaaea469","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[0,0,0,0,1,1,1,1]","payloadType":"json","x":160,"y":460,"wires":[["5d070261787e3b4f"]]},{"id":"5d070261787e3b4f","type":"function","z":"54efb553244c241f","name":"","func":"\n\n\nmsg.payload = { value: msg.payload, 'fc': 15, 'unitid': 1, 'address': 1, 'quantity': 8 }\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":500,"wires":[["c77cda57d306495e"]]},{"id":"c77cda57d306495e","type":"modbus-flex-write","z":"54efb553244c241f","name":"","showStatusActivities":true,"showErrors":true,"server":"ebeab3422d31a778","emptyMsgOnFail":false,"keepMsgProperties":false,"x":550,"y":500,"wires":[["89369c2bcbeb76ca"],[]]},{"id":"6e7c0a768c13e750","type":"modbus-queue-info","z":"54efb553244c241f","name":"","topic":"","unitid":1,"queueReadIntervalTime":1000,"lowLowLevel":25,"lowLevel":75,"highLevel":150,"highHighLevel":300,"server":"ebeab3422d31a778","errorOnHighLevel":false,"showStatusActivities":true,"updateOnAllQueueChanges":false,"updateOnAllUnitQueues":false,"x":980,"y":400,"wires":[[]]},{"id":"1b16fc2c2c07f65b","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1,1,1,1,0,0,0,0]","payloadType":"json","x":160,"y":540,"wires":[["5d070261787e3b4f"]]},{"id":"ebeab3422d31a778","type":"modbus-client","name":"","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"","unit_id":"0","commandDelay":"50","clientTimeout":"500","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true}]

I'm on 5.13 nodes. I'm having trouble updating it to 5.15.

According to the debug messages, its happening with the flex write nodes. The project still works, but those warnings do concern me a bit. Thanks.

hi .. can you give us some more information of what you tried to upgrade the modbus node and why you had trouble ?

From your .node-red folder run

npm install node-red-contrib-modbus

Its worth updating it because with the latest release they added better support for Node.js version 14.
something changed in nodejs 14 and up and the tcp connection wasnt handled correctly with Modbus and it would hang. You can read more about it here

What OS are you on and whats your nodejs version by the way. From terminal run
node -v

Thanks for your help. I'm going to get on this again after the holidays.
I think part of the problem is I'm not able to get to the internet with my ethernet due to incorrect subnet mask.

1 Like

Happy thanksgiving.
Ok, back on this. Trying to update my modbus nodes. I puttied in and typed in that npm install script and I get this:


No errors. But I go to node-red, manage palettes, and find that 5.13 is installed. I can't install 5.15 from manage palettes either.

Hello .. you dont seem to be in the .node-red folder

or use the Manage Palette from the Editor

OK, I get this in putty now:

Then if I try manage palette I get this:

The debug log here.
2021-11-30T17_28_23_942Z-debug.log (77.8 KB)

I can't make heads/tails out of this.

error Refusing to delete /home/pi/.node-red/node_modules/modbus-serial/node_modules/.bin/prebuild-install: is outside /home/pi/.node-red/node_modules/modbus-serial/node_modules/prebuild-install and not a link
error File exists: /home/pi/.node-red/node_modules/modbus-serial/node_modules/.bin/prebuild-install

Im no npm expert but try again these steps
first from /home/pi/ folder run

npm uninstall node-red-contrib-modbus

(this is to ensure there are no remnants of the wrong folder installation you did before)

.. then from .node-red folder

npm uninstall node-red-contrib-modbus

npm cache clean

npm install node-red-contrib-modbus

If the above fails again .. then carefuly delete only the node_modules folder from .node-red and run
npm install

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.