BiancoRoyal / node-red-contrib-modbus

maintained by PLUS for Node-RED - https://plus4nodered.com
https://www.npmjs.com/package/node-red-contrib-modbus
BSD 3-Clause "New" or "Revised" License
278 stars 107 forks source link

"Error: Client Not Ready To Read At State init" when deploying #376

Closed KlausHans closed 10 months ago

KlausHans commented 1 year ago

Which node-red-contrib-modbus version are you using?

"node-red-contrib-modbus": "5.25.0"

What happened?

I have a weird issue, that only happens after x amounts of deploying the flows. x is most often 3 from my observation. I have 3 Usb-Rs485 adapters on an usb hub connected to a Raspi. The adapters are defined in the modbus node via /dev/serial/by-id/ or /dev/serial/by-path. The error is "Error: Client Not Ready To Read At State init". If i unplug and then plug the usb hub where the adapters are connected to, everything works again flawless without end (as long as i don't deploy). Of course i can not unplug and plug the usb hub every ~3 deployments.

I am not really sure if this is an issue with the node though. I tried other usb hubs, but then the issues were even worse. Defining a startup or queue delay doesn't help.

Server

Modbus-Flex-Server Node (Please attach Script to the next section)

How can this be reproduced?

"Please attach relevant flows as a .json file. " Github wont let me. So here plain text:

[{"id":"3b451f743e7a5e91","type":"function","z":"19039640d8fcfcf8","name":"Total system power","func":"msg.payload = { \n    'fc': 4, \n    'address': 52, \n    'quantity': 2 };\nmsg.topic = \"Total system power\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":590,"y":100,"wires":[["98e308333928a47f"]]},{"id":"98e308333928a47f","type":"modbus-flex-getter","z":"19039640d8fcfcf8","name":"","showStatusActivities":true,"showErrors":true,"showWarnings":true,"logIOActivities":false,"server":"3adf24f10428449c","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"delayOnStart":false,"startDelayTime":"","x":850,"y":120,"wires":[[],["67fc804e6c23ec1f","af66179e0f8233d4","0bd36a4afea8147c","07390446e4992730","387020dfea4be52a","a93fe7f50a0268eb","16625dbbd22ed54b","42b33487d27b85d8","f16c02a0d4dbcdd6","378087677ff1b6ed","bd09f5f2bb8d7a69","a73d88e5027e2ba5"]]},{"id":"67fc804e6c23ec1f","type":"function","z":"19039640d8fcfcf8","name":"Convert Buffer Momentanleistung","func":"if (msg.topic === \"Total system power\") {\n    const buf = Buffer.from(msg.payload.buffer);\n    const value = buf.readFloatBE();\n    msg.payload = {\n        \"HPVZ Momentanleistung(W)\": Number((value).toFixed(1))*(-1)\n    };\n    return msg;\n} else {\n    return null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1160,"y":100,"wires":[["cae38570107da166","7b04ad459851e668"]]},{"id":"f5f9a90ad869c39d","type":"function","z":"19039640d8fcfcf8","name":"Import active energy","func":"msg.payload = { \n    'fc': 4, \n    'address': 72, \n    'quantity': 2 };\nmsg.topic = \"Import active energy\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":160,"wires":[["98e308333928a47f"]]},{"id":"af66179e0f8233d4","type":"function","z":"19039640d8fcfcf8","name":"Convert Buffer Gesamtverbrauch","func":"if (msg.topic === \"Import active energy\") {\n    const buf = Buffer.from(msg.payload.buffer);\n    const value = buf.readFloatBE();\n    msg.payload = {\n        \"HPVZ Gesamtverbrauch(kWh)\": Number((value).toFixed(2))\n    };\n    return msg;\n} else {\n    return null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1160,"y":160,"wires":[["cae38570107da166"]]},{"id":"cae38570107da166","type":"join","z":"19039640d8fcfcf8","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"12","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1430,"y":120,"wires":[["6135e8a5f743e094","9b9d051c2ce1d138"]]},{"id":"8177ae354225beda","type":"function","z":"19039640d8fcfcf8","name":"Export active energy","func":"msg.payload = { \n    'fc': 4, \n    'address': 74, \n    'quantity': 2 };\nmsg.topic = \"Export active energy\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":200,"wires":[["98e308333928a47f"]]},{"id":"0bd36a4afea8147c","type":"function","z":"19039640d8fcfcf8","name":"Convert Buffer Gesamterzeugung","func":"if (msg.topic === \"Export active energy\") {\n    const buf = Buffer.from(msg.payload.buffer);\n    const value = buf.readFloatBE();\n    msg.payload = {\n        \"HPVZ Gesamterzeugung(kWh)\": Number((value).toFixed(2))\n    };\n    return msg;\n} else {\n    return null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1160,"y":200,"wires":[["cae38570107da166"]]},{"id":"e25d84858275eaa2","type":"function","z":"19039640d8fcfcf8","name":"Phase 1 line to neutral volts","func":"msg.payload = { \n    'fc': 4, \n    'address': 0, \n    'quantity': 2 };\nmsg.topic = \"Phase 1 line to neutral volts\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":260,"wires":[["98e308333928a47f"]]},{"id":"07390446e4992730","type":"function","z":"19039640d8fcfcf8","name":"Convert Buffer L1 Spannung","func":"if(msg.topic === \"Phase 1 line to neutral volts\") {\n    const buf = Buffer.from(msg.payload.buffer);\n    const value = buf.readFloatBE();\n    msg.payload = {\n        \"HPVZ L1 Spannung(V)\": Number((value).toFixed(2))\n    };\n    return msg;\n} else {\n    return null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1140,"y":260,"wires":[["cae38570107da166"]]},{"id":"4d6cc2165b3a7c7b","type":"function","z":"19039640d8fcfcf8","name":"Phase 2 line to neutral volts","func":"msg.payload = { \n    'fc': 4, \n    'address': 2, \n    'quantity': 2 };\nmsg.topic = \"Phase 2 line to neutral volts\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":300,"wires":[["98e308333928a47f"]]},{"id":"387020dfea4be52a","type":"function","z":"19039640d8fcfcf8","name":"Convert Buffer L2 Spannung","func":"if(msg.topic === \"Phase 2 line to neutral volts\") {\n    const buf = Buffer.from(msg.payload.buffer);\n    const value = buf.readFloatBE();\n    msg.payload = {\n        \"HPVZ L2 Spannung(V)\": Number((value).toFixed(2))\n    };\n    return msg;\n} else {\n    return null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1140,"y":300,"wires":[["cae38570107da166"]]},{"id":"6a9981a6625fb3df","type":"function","z":"19039640d8fcfcf8","name":"Phase 3 line to neutral volts","func":"msg.payload = { \n    'fc': 4, \n    'address': 4, \n    'quantity': 2 };\nmsg.topic = \"Phase 3 line to neutral volts\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":340,"wires":[["98e308333928a47f"]]},{"id":"a93fe7f50a0268eb","type":"function","z":"19039640d8fcfcf8","name":"Convert Buffer L3 Spannung","func":"if(msg.topic === \"Phase 3 line to neutral volts\") {\n    const buf = Buffer.from(msg.payload.buffer);\n    const value = buf.readFloatBE();\n    msg.payload = {\n        \"HPVZ L3 Spannung(V)\": Number((value).toFixed(2))\n    };\n    return msg;\n} else {\n    return null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1140,"y":340,"wires":[["cae38570107da166"]]},{"id":"61e1b0928ddf80a1","type":"function","z":"19039640d8fcfcf8","name":"Phase 1 current","func":"msg.payload = { \n    'fc': 4, \n    'address': 6, \n    'quantity': 2 };\nmsg.topic = \"Phase 1 current\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":400,"wires":[["98e308333928a47f"]]},{"id":"16625dbbd22ed54b","type":"function","z":"19039640d8fcfcf8","name":"Convert Buffer L1 Strom","func":"if(msg.topic === \"Phase 1 current\") {\n    const buf = Buffer.from(msg.payload.buffer);\n    const value = buf.readFloatBE();\n    msg.payload = {\n        \"HPVZ L1 Strom(A)\": Number((value).toFixed(2))\n    };\n    return msg;\n} else {\n    return null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1130,"y":400,"wires":[["cae38570107da166"]]},{"id":"a8e7fd23eab8e036","type":"function","z":"19039640d8fcfcf8","name":"Phase 2 current","func":"msg.payload = { \n    'fc': 4, \n    'address': 8, \n    'quantity': 2 };\nmsg.topic = \"Phase 2 current\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":440,"wires":[["98e308333928a47f"]]},{"id":"2997c9e1499a0a37","type":"function","z":"19039640d8fcfcf8","name":"Phase 3 current","func":"msg.payload = { \n    'fc': 4, \n    'address': 10, \n    'quantity': 2 };\nmsg.topic = \"Phase 3 current\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":480,"wires":[["98e308333928a47f"]]},{"id":"42b33487d27b85d8","type":"function","z":"19039640d8fcfcf8","name":"Convert Buffer L2 Strom","func":"if(msg.topic === \"Phase 2 current\") {\n    const buf = Buffer.from(msg.payload.buffer);\n    const value = buf.readFloatBE();\n    msg.payload = {\n        \"HPVZ L2 Strom(A)\": Number((value).toFixed(2))\n    };\n    return msg;\n} else {\n    return null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1130,"y":440,"wires":[["cae38570107da166"]]},{"id":"f16c02a0d4dbcdd6","type":"function","z":"19039640d8fcfcf8","name":"Convert Buffer L3 Strom","func":"if(msg.topic === \"Phase 3 current\") {\n    const buf = Buffer.from(msg.payload.buffer);\n    const value = buf.readFloatBE();\n    msg.payload = {\n        \"HPVZ L3 Strom(A)\": Number((value).toFixed(2))\n    };\n    return msg;\n} else {\n    return null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1130,"y":480,"wires":[["cae38570107da166"]]},{"id":"672b961721bae21d","type":"function","z":"19039640d8fcfcf8","name":"Phase 1 active power","func":"msg.payload = { \n    'fc': 4, \n    'address': 12, \n    'quantity': 2 };\nmsg.topic = \"Phase 1 active power\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":540,"wires":[["98e308333928a47f"]]},{"id":"378087677ff1b6ed","type":"function","z":"19039640d8fcfcf8","name":"Convert Buffer L1 Power","func":"if(msg.topic === \"Phase 1 active power\") {\n    const buf = Buffer.from(msg.payload.buffer);\n    const value = buf.readFloatBE();\n    msg.payload = {\n        \"HPVZ L1 Leistung(W)\": Number((value).toFixed(2))\n    };\n    return msg;\n} else {\n    return null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1130,"y":540,"wires":[["cae38570107da166"]]},{"id":"a302fc0db23854b2","type":"function","z":"19039640d8fcfcf8","name":"Phase 2 active power","func":"msg.payload = { \n    'fc': 4, \n    'address': 14, \n    'quantity': 2 };\nmsg.topic = \"Phase 2 active power\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":580,"wires":[["98e308333928a47f"]]},{"id":"bd09f5f2bb8d7a69","type":"function","z":"19039640d8fcfcf8","name":"Convert Buffer L2 Power","func":"if(msg.topic === \"Phase 2 active power\") {\n    const buf = Buffer.from(msg.payload.buffer);\n    const value = buf.readFloatBE();\n    msg.payload = {\n        \"HPVZ L2 Leistung(W)\": Number((value).toFixed(2))\n    };\n    return msg;\n} else {\n    return null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1130,"y":580,"wires":[["cae38570107da166"]]},{"id":"1a1f25b938dcf7f6","type":"function","z":"19039640d8fcfcf8","name":"Phase 3 active power","func":"msg.payload = { \n    'fc': 4, \n    'address': 16, \n    'quantity': 2 };\nmsg.topic = \"Phase 3 active power\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":620,"wires":[["98e308333928a47f"]]},{"id":"a73d88e5027e2ba5","type":"function","z":"19039640d8fcfcf8","name":"Convert Buffer L3 Power","func":"if(msg.topic === \"Phase 3 active power\") {\n    const buf = Buffer.from(msg.payload.buffer);\n    const value = buf.readFloatBE();\n    msg.payload = {\n        \"HPVZ L3 Leistung(W)\": Number((value).toFixed(2))\n    };\n    return msg;\n} else {\n    return null;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1130,"y":620,"wires":[["cae38570107da166"]]},{"id":"392ed6a16ec0e3de","type":"mqtt in","z":"19039640d8fcfcf8","name":"","topic":"sensoren/strom/hausanschlusszählerSDM","qos":"2","datatype":"auto-detect","broker":"e8a44b7f.9e3c7","nl":false,"rap":true,"rh":0,"inputs":0,"x":200,"y":200,"wires":[["3b451f743e7a5e91","f5f9a90ad869c39d","8177ae354225beda","e25d84858275eaa2","4d6cc2165b3a7c7b","6a9981a6625fb3df","61e1b0928ddf80a1","a8e7fd23eab8e036","2997c9e1499a0a37","672b961721bae21d","a302fc0db23854b2","1a1f25b938dcf7f6"]]},{"id":"3adf24f10428449c","type":"modbus-client","name":"Huawei PV Stromzähler","clienttype":"serial","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"failureLogEnabled":true,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.4.4:1.0-port0","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"0x3A","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true},{"id":"e8a44b7f.9e3c7","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"NodeRed","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

What did you expect to happen?

No error appears after deploying.

Other Information

No response

biancode commented 1 year ago

"Error: Client Not Ready To Read At State init" means you inject a request while it is not ready and do the initializing of the client. You need some switch variable to give MQTT msg just to the client if it is ready to work.

github-actions[bot] commented 11 months ago

This issue is stale because it has been open 60 days with no activity. It will be closed in 30 days, but can be saved by removing the stale label or commenting.