Hi
for some time I'm using node-red and have managed to setup some flows. I watched the Node-RED Essentials Videos, downloades & tested many examples and analyzed the debug-output in detail.
Unfortunately I'm still struggling with proper handling of node-red messages (topic, payload, array, object,...). With lots of try & error, I managed to create this flow.
[{"id":"c26fccb5be338e02","type":"group","z":"4b82e3cc342b356d","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["73339ead1924d2c8","9b5135f3c68cd689","77b0696eec233433","0528be875be31158","cf2ee961021ae563","8ed6ec5671466c90","19517d09aee7d992","276a32133241c4fa","39a0877b0bdcbeb0","2e45dcabc0bba4bf","257775974f6de189","5b2a44c745774f2a","a4d463f1fe6a071d"],"x":74,"y":1159,"w":1132,"h":282},{"id":"73339ead1924d2c8","type":"modbus-getter","z":"4b82e3cc342b356d","g":"c26fccb5be338e02","name":"Modbus P_Ch1","showStatusActivities":false,"showErrors":false,"showWarnings":true,"logIOActivities":false,"unitid":"1","dataType":"HoldingRegister","adr":"19020","quantity":"2","server":"9782f823cc54f17a","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"delayOnStart":false,"startDelayTime":"","x":400,"y":1280,"wires":[["2e45dcabc0bba4bf","a4d463f1fe6a071d"],[]]},{"id":"9b5135f3c68cd689","type":"debug","z":"4b82e3cc342b356d","g":"c26fccb5be338e02","name":"debug 2578","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":1090,"y":1400,"wires":[]},{"id":"77b0696eec233433","type":"modbus-getter","z":"4b82e3cc342b356d","g":"c26fccb5be338e02","name":"Modbus P_Ch2","showStatusActivities":false,"showErrors":false,"showWarnings":true,"logIOActivities":false,"unitid":"1","dataType":"HoldingRegister","adr":"19022","quantity":"2","server":"9782f823cc54f17a","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"delayOnStart":false,"startDelayTime":"","x":400,"y":1340,"wires":[["257775974f6de189"],[]]},{"id":"0528be875be31158","type":"modbus-getter","z":"4b82e3cc342b356d","g":"c26fccb5be338e02","name":"Modbus P_Ch3","showStatusActivities":false,"showErrors":false,"showWarnings":true,"logIOActivities":false,"unitid":"1","dataType":"HoldingRegister","adr":"19024","quantity":"2","server":"9782f823cc54f17a","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"delayOnStart":false,"startDelayTime":"","x":400,"y":1400,"wires":[["5b2a44c745774f2a"],[]]},{"id":"cf2ee961021ae563","type":"join","z":"4b82e3cc342b356d","g":"c26fccb5be338e02","name":"join","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","useparts":true,"accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":790,"y":1400,"wires":[["39a0877b0bdcbeb0","276a32133241c4fa"]]},{"id":"8ed6ec5671466c90","type":"debug","z":"4b82e3cc342b356d","g":"c26fccb5be338e02","name":"debug 2579","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":830,"y":1260,"wires":[]},{"id":"19517d09aee7d992","type":"inject","z":"4b82e3cc342b356d","g":"c26fccb5be338e02","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"iso","payloadType":"date","x":180,"y":1340,"wires":[["73339ead1924d2c8","77b0696eec233433","0528be875be31158"]]},{"id":"276a32133241c4fa","type":"debug","z":"4b82e3cc342b356d","g":"c26fccb5be338e02","name":"debug 2580","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":970,"y":1320,"wires":[]},{"id":"39a0877b0bdcbeb0","type":"change","z":"4b82e3cc342b356d","g":"c26fccb5be338e02","name":"sum","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":930,"y":1400,"wires":[["9b5135f3c68cd689"]]},{"id":"2e45dcabc0bba4bf","type":"buffer-parser","z":"4b82e3cc342b356d","g":"c26fccb5be338e02","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":"0.001","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"return","multipleResult":true,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":590,"y":1280,"wires":[["cf2ee961021ae563","8ed6ec5671466c90"]]},{"id":"257775974f6de189","type":"buffer-parser","z":"4b82e3cc342b356d","g":"c26fccb5be338e02","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":"0.001","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"return","multipleResult":true,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":590,"y":1340,"wires":[["cf2ee961021ae563"]]},{"id":"5b2a44c745774f2a","type":"buffer-parser","z":"4b82e3cc342b356d","g":"c26fccb5be338e02","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":"0.001","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"return","multipleResult":true,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":590,"y":1400,"wires":[["cf2ee961021ae563"]]},{"id":"a4d463f1fe6a071d","type":"debug","z":"4b82e3cc342b356d","g":"c26fccb5be338e02","name":"debug 2581","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":670,"y":1200,"wires":[]},{"id":"9782f823cc54f17a","type":"modbus-client","name":"Janitza_Test","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":true,"queueLogEnabled":true,"failureLogEnabled":true,"tcpHost":"172.20.39.200","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"0x3A","unit_id":1,"commandDelay":1000,"clientTimeout":3000,"reconnectOnTimeout":true,"reconnectTimeout":2000,"parallelUnitIdsAllowed":true,"showWarnings":true,"showLogs":true}]
Since the modbus-nodes requires corresponding hardware, I tried to replace them by a function giving identical output, so that other usesers can test the flow. Unfortunately I did not succeed doing this. Here is the output of "debug 2581".
{"topic":"73339ead1924d2c8","messageId":"6790f19e55e41801585b00f1","payload":[18109,25696],"queueLengthByUnitId":{"unitId":1,"queueLength":0},"queueUnitId":1,"unitId":1,"modbusRequest":{"value":"2025-01-22T13:24:46.008Z","unitid":"1","fc":3,"address":"19020","quantity":"2","messageId":"6790f19e55e41801585b00f1"},"responseBuffer":{"data":[18109,25696],"buffer":[70,189,100,96]},"_msgid":"8a99291638398420"}
Can someone please advice how to do this?
After that I would like to ask more questions regarding messages and optimization.