Modbus Not Reconnecting

Hi, I am trying to monitor modbus register values with library "node-red-contrib-modbus". Although it works just fine but the issue is that, whenever there is a long disconnection time, let's say hours. My modbus nodes do not reconnect with the PLC hence showing reconnecting but not getting connected.In order to retain connection I have to Restart all flows.

Attached is my current flow

[{"id":"4a09007c.72828","type":"ui_gauge","z":"677d8905.de2b08","name":"","group":"e15b0c94.455b6","order":1,"width":0,"height":0,"gtype":"donut","title":"Simporter Main Belt Current","label":"Amps","format":"{{value}}","min":0,"max":"200","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":660,"y":20,"wires":[]},{"id":"1cbbb40.8c3c94c","type":"function","z":"677d8905.de2b08","name":"","func":"msg.payload= msg.payload;\n return[msg,null];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":380,"y":20,"wires":[["4a09007c.72828"]]},{"id":"fcc1016e.0a7e9","type":"function","z":"677d8905.de2b08","name":"","func":"msg.payload= msg.payload/10;\n return[msg,null];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":380,"y":80,"wires":[["144885d3.7039ea"]]},{"id":"144885d3.7039ea","type":"ui_gauge","z":"677d8905.de2b08","name":"","group":"e15b0c94.455b6","order":3,"width":0,"height":0,"gtype":"donut","title":"Simporter Central Feeder Current","label":"Amps","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":660,"y":80,"wires":[]},{"id":"1f02c1ef.f75f5e","type":"function","z":"677d8905.de2b08","name":"","func":"msg.payload= msg.payload/10;\n return[msg,null];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":160,"wires":[["21c18e55.f5de02"]]},{"id":"21c18e55.f5de02","type":"ui_gauge","z":"677d8905.de2b08","name":"","group":"e15b0c94.455b6","order":2,"width":0,"height":0,"gtype":"donut","title":"Simporter External Feeder Current","label":"Amps","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":720,"y":160,"wires":[]},{"id":"a54d6b37.772a58","type":"ui_gauge","z":"677d8905.de2b08","name":"","group":"7c1d895d.4278f8","order":1,"width":0,"height":0,"gtype":"donut","title":"Simporter Main Belt Freq.","label":"Hz","format":"{{value}}","min":0,"max":"70","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":670,"y":280,"wires":[]},{"id":"74e3d08.7de5d3","type":"function","z":"677d8905.de2b08","name":"","func":"msg.payload= msg.payload/10;\n return[msg,null];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":390,"y":280,"wires":[["a54d6b37.772a58"]]},{"id":"410ad4d.234442c","type":"function","z":"677d8905.de2b08","name":"","func":"msg.payload= msg.payload/10;\n return[msg,null];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":340,"wires":[["a38c8d42.00acb"]]},{"id":"a38c8d42.00acb","type":"ui_gauge","z":"677d8905.de2b08","name":"","group":"7c1d895d.4278f8","order":2,"width":0,"height":0,"gtype":"donut","title":"Simporter External Feeder Freq.","label":"Hz","format":"{{value}}","min":0,"max":"70","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":670,"y":340,"wires":[]},{"id":"814fee4e.25eb5","type":"function","z":"677d8905.de2b08","name":"","func":"msg.payload= msg.payload/10;\n return[msg,null];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":340,"y":220,"wires":[["dc8c1dfc.c2534"]]},{"id":"dc8c1dfc.c2534","type":"ui_gauge","z":"677d8905.de2b08","name":"","group":"7c1d895d.4278f8","order":3,"width":0,"height":0,"gtype":"donut","title":"Simporter Central Feeder Freq.","label":"Hz","format":"{{value}}","min":0,"max":"70","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":670,"y":220,"wires":[]},{"id":"e3f91e3e.8ae5e","type":"modbus-read","z":"677d8905.de2b08","name":"Simporter PLC","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"","dataType":"HoldingRegister","adr":"4111","quantity":"1","rate":"500","rateUnit":"ms","delayOnStart":false,"startDelayTime":"","server":"68b35801.5c2f08","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":true,"x":120,"y":20,"wires":[["1cbbb40.8c3c94c"],[]]},{"id":"d55b483b.a74da8","type":"modbus-read","z":"677d8905.de2b08","name":"Simporter PLC","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"","dataType":"HoldingRegister","adr":"4118","quantity":"1","rate":"500","rateUnit":"ms","delayOnStart":false,"startDelayTime":"","server":"68b35801.5c2f08","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":true,"x":120,"y":80,"wires":[["fcc1016e.0a7e9"],[]]},{"id":"d73847c3.5cdcf8","type":"modbus-read","z":"677d8905.de2b08","name":"Simporter PLC","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"","dataType":"HoldingRegister","adr":"4136","quantity":"1","rate":"500","rateUnit":"ms","delayOnStart":false,"startDelayTime":"","server":"68b35801.5c2f08","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":true,"x":120,"y":140,"wires":[["1f02c1ef.f75f5e"],[]]},{"id":"ec4ee7dc.6f8358","type":"modbus-read","z":"677d8905.de2b08","name":"Simporter PLC Main Belt (Hz)","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"","dataType":"HoldingRegister","adr":"4126","quantity":"1","rate":"500","rateUnit":"ms","delayOnStart":false,"startDelayTime":"","server":"68b35801.5c2f08","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":true,"x":140,"y":280,"wires":[["74e3d08.7de5d3"],[]]},{"id":"ac72652e.5d3ef8","type":"modbus-read","z":"677d8905.de2b08","name":"Simporter PLC External(Hz)","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"","dataType":"HoldingRegister","adr":"4127","quantity":"1","rate":"500","rateUnit":"ms","delayOnStart":false,"startDelayTime":"","server":"68b35801.5c2f08","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":true,"x":120,"y":360,"wires":[["410ad4d.234442c"],[]]},{"id":"5a186e34.ef817","type":"modbus-read","z":"677d8905.de2b08","name":"Simporter PLC Centeral (Hz)","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"","dataType":"HoldingRegister","adr":"4128","quantity":"1","rate":"500","rateUnit":"ms","delayOnStart":false,"startDelayTime":"","server":"68b35801.5c2f08","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":true,"x":120,"y":220,"wires":[["814fee4e.25eb5"],[]]},{"id":"e15b0c94.455b6","type":"ui_group","name":"Current Rate","tab":"6572373e.e86d98","order":1,"disp":true,"width":"6","collapse":false},{"id":"7c1d895d.4278f8","type":"ui_group","name":"Frequency Rate","tab":"6572373e.e86d98","order":2,"disp":true,"width":"6","collapse":false},{"id":"68b35801.5c2f08","type":"modbus-client","name":"Simporter PLC","clienttype":"tcp","bufferCommands":false,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.50.100.160","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"12000","reconnectOnTimeout":true,"reconnectTimeout":"5000","parallelUnitIdsAllowed":false},{"id":"6572373e.e86d98","type":"ui_tab","name":"SIMPORTER","icon":"dashboard","disabled":false,"hidden":false}]

Hi Fahad,

Your flow cannot be imported.
Please re-edit your post and paste your flow again using the Preformatted Text icon image
in order to prevent the forum from corrupting some special characters

What version of node.js are you using ?
you can check with node -v

i was able to reproduce the issue on a Win10 system with node version version 14
there is a discussion on the Modbus node's github page regarding the problem of reconnection
I dont know if its related to your issue but its worth reading it.
One solution mentioned is to downgrade to nodejs v12 if indeed you are in a version higher than that
since v14 is not fully supported by the modbus node.
I have tested the same setup on a Raspberry Pi running v12 and indeed the nodes behave correctly.

Also i would recommend to optimize your modbus reads a bit by doing a single read and using the Modbus Flex Getter node instead of 6 x individual ones. Then with a function node pick out the modbus register values you need to display on the dashboard.

Test Flow:

[{"id":"c9d6de44.89938","type":"debug","z":"2a23d970.6413b6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":890,"y":620,"wires":[]},{"id":"2422dcfa.832584","type":"function","z":"2a23d970.6413b6","name":"","func":"msg.payload = { \n    value: msg.payload, \n    'fc': 3, \n    'unitid': 1, \n    'address': 4111, \n    'quantity': 25\n} \n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":495,"y":660,"wires":[["7877199b.91e27"]],"l":false},{"id":"7877199b.91e27","type":"modbus-flex-getter","z":"2a23d970.6413b6","name":"Simporter PLC","showStatusActivities":false,"showErrors":false,"logIOActivities":false,"server":"7d19bc34.f0162c","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":true,"keepMsgProperties":false,"x":620,"y":660,"wires":[["c9d6de44.89938"],[]]},{"id":"d118ad7d.a3616","type":"inject","z":"2a23d970.6413b6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":320,"y":660,"wires":[["2422dcfa.832584"]]},{"id":"7d19bc34.f0162c","type":"modbus-client","name":"Simporter PLC","clienttype":"tcp","bufferCommands":false,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.1.66","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"200","clientTimeout":"1000","reconnectOnTimeout":false,"reconnectTimeout":"2000","parallelUnitIdsAllowed":false}]
1 Like

I think it Worked!!! I downgraded nodejs to v12 and the again installed node red, also used modbus flex getter.It works just fine now, no error occured uptill now. Its will be on Testing phase for 3 days

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