General support for newbie

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.

Hi Egge,

If I understand correctly, you want to "simulate" the Modbus node's output so that you don't need to connect to actual hardware.

You could try to use a function node and force msg to be as you require.

Example

[
    {
        "id": "0144e009f69528bb",
        "type": "function",
        "z": "e9cf7aa393301396",
        "name": "Simulate MODBUS node",
        "func": "msg = {\"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\"};\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 454,
        "y": 512,
        "wires": [
            [
                "153576280fb7c962"
            ]
        ]
    },
    {
        "id": "6882b42b0965f6ec",
        "type": "inject",
        "z": "e9cf7aa393301396",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 226,
        "y": 512,
        "wires": [
            [
                "0144e009f69528bb"
            ]
        ]
    },
    {
        "id": "153576280fb7c962",
        "type": "debug",
        "z": "e9cf7aa393301396",
        "name": "debug 83",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 652,
        "y": 512,
        "wires": []
    }
]

or you could put it in a core change node...

[{"id":"a4105a37b00a23a4","type":"change","z":"37ef9ab5d60ffd43","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"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\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":3220,"wires":[["b2324e70e036f53d"]]},{"id":"5e1bfb23be476daf","type":"inject","z":"37ef9ab5d60ffd43","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":320,"y":3220,"wires":[["a4105a37b00a23a4","7f2c3bdc5407e982"]]},{"id":"b2324e70e036f53d","type":"debug","z":"37ef9ab5d60ffd43","name":"debug 2849","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":3220,"wires":[]}]

Yes, but in the example you provided, the entire content is within msg.payload. This approach doesn't emulate the behavior of a Modbus node since the msg structure is not formatted in the same way. Correct?

would it be possible to make it with change node?

yes, exactly this I want to do...

and I already tried it with a function similar to your proposal, but always got errors or other outputs than required

I also tried change node


and put the output of my debug

but this gave a different debug-response and also an error on buffer parser

You seem to have set msg.payload to an object which includes msg.payload.topic, some other stuff and presumably msg.payload.payload.
No surprise the buffer parses chokes on it.

You can have multiple lines in the change node, setting just one of msg.payload, msg.topic, etc per line.

In contrast, in a function node you can do something like this

const newmsg = {
"payload": 42,
"topic": "Ion Density"
}

Incidentally, I don't think it's a good idea for your simulated modbus data to include messageid. Every message will automatically be assigned a message id on creation. It should be unique.

2 Likes

If I may comment on the flow organisation, rather than reading 2 registers from address 19020, 2 from 19024 and 2 from 19024 it would be much simpler (and quicker) if you were to use just one modbus node set to read all 6 registers from 19020 and let the buffer parser pick out the data. Then you would not need the Join node and only one Modbus and one Parser node.

thank you very much for this hint! exactly this support is highly welcome and I will follow up on this later... however i first need to understand the basics of messages, therefore I'm trying to go step by step...

in the meantime I managed to simulate my modbus-nodes and I'm getting identical outputs from my change-nodes (or at lease very similar...)

[{"id":"ac3a9526615623e3","type":"group","z":"4b82e3cc342b356d","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["137b896a18d9ce03","3e6aafdee48648c8","8c70a7d9aa6256a8","f1144333d13df2d6","272538271560c416","67c3a22dad522bd4","379fad1cab2abffe","2177c1076d1a3ca8","0a1d717b5713b192","024e1b94cc47bee8","d879c5b5db9af994","116944ee21d0ac6b"],"x":54,"y":1539,"w":1132,"h":242},{"id":"137b896a18d9ce03","type":"debug","z":"4b82e3cc342b356d","g":"ac3a9526615623e3","name":"debug 2582","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":1070,"y":1740,"wires":[]},{"id":"3e6aafdee48648c8","type":"join","z":"4b82e3cc342b356d","g":"ac3a9526615623e3","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":770,"y":1740,"wires":[["272538271560c416","67c3a22dad522bd4"]]},{"id":"8c70a7d9aa6256a8","type":"debug","z":"4b82e3cc342b356d","g":"ac3a9526615623e3","name":"debug 2583","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":790,"y":1580,"wires":[]},{"id":"f1144333d13df2d6","type":"inject","z":"4b82e3cc342b356d","g":"ac3a9526615623e3","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"iso","payloadType":"date","x":160,"y":1680,"wires":[["024e1b94cc47bee8","d879c5b5db9af994","116944ee21d0ac6b"]]},{"id":"272538271560c416","type":"debug","z":"4b82e3cc342b356d","g":"ac3a9526615623e3","name":"debug 2584","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":950,"y":1660,"wires":[]},{"id":"67c3a22dad522bd4","type":"change","z":"4b82e3cc342b356d","g":"ac3a9526615623e3","name":"sum","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":1740,"wires":[["137b896a18d9ce03"]]},{"id":"379fad1cab2abffe","type":"buffer-parser","z":"4b82e3cc342b356d","g":"ac3a9526615623e3","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"P_Ch1","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":570,"y":1620,"wires":[["3e6aafdee48648c8","8c70a7d9aa6256a8"]]},{"id":"2177c1076d1a3ca8","type":"buffer-parser","z":"4b82e3cc342b356d","g":"ac3a9526615623e3","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"P_Ch2","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":570,"y":1680,"wires":[["3e6aafdee48648c8"]]},{"id":"0a1d717b5713b192","type":"buffer-parser","z":"4b82e3cc342b356d","g":"ac3a9526615623e3","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"P_Ch3","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":570,"y":1740,"wires":[["3e6aafdee48648c8"]]},{"id":"024e1b94cc47bee8","type":"change","z":"4b82e3cc342b356d","g":"ac3a9526615623e3","name":"P_Ch1","rules":[{"t":"set","p":"payload","pt":"msg","to":"[18289,51227]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1620,"wires":[["379fad1cab2abffe"]]},{"id":"d879c5b5db9af994","type":"change","z":"4b82e3cc342b356d","g":"ac3a9526615623e3","name":"P_Ch2","rules":[{"t":"set","p":"payload","pt":"msg","to":"[18302,28751]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1680,"wires":[["2177c1076d1a3ca8"]]},{"id":"116944ee21d0ac6b","type":"change","z":"4b82e3cc342b356d","g":"ac3a9526615623e3","name":"P_Ch3","rules":[{"t":"set","p":"payload","pt":"msg","to":"[18308,40470]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1740,"wires":[["0a1d717b5713b192"]]}]

This flow works, however there is probably lots of optimization potential and I have some questions:

  • in the video-tutorial it was mentioned, that the join-node can work in "automatic" mode when the incoming messages are correct - I'm getting always an error: "Message missing msg.parts property - cannot join in 'auto' mode". What is wrong or how to add the msg.parts?

  • after buffer parser, each message contains its topic (e.g. "P_Ch1"). After the join-node only one topic is remaining. Is there a way to maintain the topics? Do I need them?

  • instead of sum (=P_Ch1+P_Ch2+P_Ch3) I also want in some cases things like this: P_Ch1 + P_Ch2 - P_Ch3 (minus instead of plus). How do I need to modify the change-node (sum)?

Auto mode is for when the messages have been generated using a Split node. For this case you want key/value mode, using topic as the key. Look at the output and you will see how to identify the individual parts.

finaly I also succeded to read multible registers at once... and the output is identical as in my previous post

[{"id":"0e65a371111e3fe0","type":"group","z":"4b82e3cc342b356d","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["58536066390f486c","48bad12a99e53120","15b924d3aee4dbe9","378d4fab301d4bf4","e8a7a912a03752ce","a4b055697dfb26ab","d09806ae7889986f","33a1d733ecd78965","a51687f31f6cc797"],"x":54,"y":1779,"w":1132,"h":242},{"id":"58536066390f486c","type":"debug","z":"4b82e3cc342b356d","g":"0e65a371111e3fe0","name":"debug 2587","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":1070,"y":1980,"wires":[]},{"id":"48bad12a99e53120","type":"join","z":"4b82e3cc342b356d","g":"0e65a371111e3fe0","name":"join","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","useparts":true,"accumulate":false,"timeout":"3","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":770,"y":1980,"wires":[["e8a7a912a03752ce","a4b055697dfb26ab"]]},{"id":"15b924d3aee4dbe9","type":"debug","z":"4b82e3cc342b356d","g":"0e65a371111e3fe0","name":"debug 2588","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":790,"y":1820,"wires":[]},{"id":"378d4fab301d4bf4","type":"inject","z":"4b82e3cc342b356d","g":"0e65a371111e3fe0","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"iso","payloadType":"date","x":160,"y":1920,"wires":[["33a1d733ecd78965"]]},{"id":"e8a7a912a03752ce","type":"debug","z":"4b82e3cc342b356d","g":"0e65a371111e3fe0","name":"debug 2589","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":950,"y":1900,"wires":[]},{"id":"a4b055697dfb26ab","type":"change","z":"4b82e3cc342b356d","g":"0e65a371111e3fe0","name":"sum","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":1980,"wires":[["58536066390f486c"]]},{"id":"d09806ae7889986f","type":"buffer-parser","z":"4b82e3cc342b356d","g":"0e65a371111e3fe0","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"P_Ch1","offset":0,"length":1,"offsetbit":0,"scale":"0.001","mask":""},{"type":"floatbe","name":"P_Ch2","offset":4,"length":1,"offsetbit":0,"scale":"0.001","mask":""},{"type":"floatbe","name":"P_Ch3","offset":8,"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":570,"y":1920,"wires":[["48bad12a99e53120","15b924d3aee4dbe9"]]},{"id":"33a1d733ecd78965","type":"change","z":"4b82e3cc342b356d","g":"0e65a371111e3fe0","name":"Modbus-Simulator","rules":[{"t":"set","p":"payload","pt":"msg","to":"[18289,51227,18302,28751,18308,40470]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":1920,"wires":[["d09806ae7889986f","a51687f31f6cc797"]]},{"id":"a51687f31f6cc797","type":"debug","z":"4b82e3cc342b356d","g":"0e65a371111e3fe0","name":"debug 2590","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":1840,"wires":[]}]

However I'm still struggling with details of the "message-idea" of node-red. I only got above flow working with buffer-parser set to "multibel results" and "value only". After the join-node I'm losing the topic-information... And I have the impression, that I need the topic-information to be able to make instead of "sum(payload)" something like "P_Ch1 + P_Ch2 - P_Ch3 (minus instead of plus)". Can you please give me a hint, what I'm doing wrong or how to optimize?

Show us how you have configured the buffer parser, and what is the output of debug 2590. You should be able to get all the values in one message and not need the Join node.

[{"id":"0e65a371111e3fe0","type":"group","z":"8e2ddd056e4aef03","name":"without join","style":{"label":true},"nodes":["58536066390f486c","15b924d3aee4dbe9","378d4fab301d4bf4","a4b055697dfb26ab","d09806ae7889986f","33a1d733ecd78965"],"x":254,"y":319,"w":1072,"h":142},{"id":"58536066390f486c","type":"debug","z":"8e2ddd056e4aef03","g":"0e65a371111e3fe0","name":"sum 2","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1230,"y":420,"wires":[]},{"id":"15b924d3aee4dbe9","type":"debug","z":"8e2ddd056e4aef03","g":"0e65a371111e3fe0","name":"parsed data 2","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":980,"y":360,"wires":[]},{"id":"378d4fab301d4bf4","type":"inject","z":"8e2ddd056e4aef03","g":"0e65a371111e3fe0","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"iso","payloadType":"date","x":360,"y":420,"wires":[["33a1d733ecd78965"]]},{"id":"a4b055697dfb26ab","type":"change","z":"8e2ddd056e4aef03","g":"0e65a371111e3fe0","name":"sum","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":950,"y":420,"wires":[["58536066390f486c"]]},{"id":"d09806ae7889986f","type":"buffer-parser","z":"8e2ddd056e4aef03","g":"0e65a371111e3fe0","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"P_Ch1","offset":0,"length":1,"offsetbit":0,"scale":"0.001","mask":""},{"type":"floatbe","name":"P_Ch2","offset":4,"length":1,"offsetbit":0,"scale":"0.001","mask":""},{"type":"floatbe","name":"P_Ch3","offset":8,"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":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":770,"y":420,"wires":[["15b924d3aee4dbe9","a4b055697dfb26ab"]]},{"id":"33a1d733ecd78965","type":"change","z":"8e2ddd056e4aef03","g":"0e65a371111e3fe0","name":"Modbus-Simulator","rules":[{"t":"set","p":"payload","pt":"msg","to":"[18289,51227,18302,28751,18308,40470]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":420,"wires":[["d09806ae7889986f"]]},{"id":"4a7c0ef41884ac5b","type":"group","z":"8e2ddd056e4aef03","name":"key/val version (better readability, keeps key names)","style":{"label":true},"nodes":["0652b1aea0a8747a","1b22c751844fc7f2","53a2ae53c0e75411","95d7d2555e203875","001b772a159b406a","4359f485fb86ee21"],"x":254,"y":499,"w":1072,"h":142},{"id":"0652b1aea0a8747a","type":"debug","z":"8e2ddd056e4aef03","g":"4a7c0ef41884ac5b","name":"sum 3","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1230,"y":600,"wires":[]},{"id":"1b22c751844fc7f2","type":"debug","z":"8e2ddd056e4aef03","g":"4a7c0ef41884ac5b","name":"parsed data 3","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":980,"y":540,"wires":[]},{"id":"53a2ae53c0e75411","type":"inject","z":"8e2ddd056e4aef03","g":"4a7c0ef41884ac5b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"iso","payloadType":"date","x":360,"y":600,"wires":[["4359f485fb86ee21"]]},{"id":"95d7d2555e203875","type":"change","z":"8e2ddd056e4aef03","g":"4a7c0ef41884ac5b","name":"sum","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.P_Ch1 + payload.P_Ch2 + payload.P_Ch3","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":950,"y":600,"wires":[["0652b1aea0a8747a"]]},{"id":"001b772a159b406a","type":"buffer-parser","z":"8e2ddd056e4aef03","g":"4a7c0ef41884ac5b","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"P_Ch1","offset":0,"length":1,"offsetbit":0,"scale":"0.001","mask":""},{"type":"floatbe","name":"P_Ch2","offset":4,"length":1,"offsetbit":0,"scale":"0.001","mask":""},{"type":"floatbe","name":"P_Ch3","offset":8,"length":1,"offsetbit":0,"scale":"0.001","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":770,"y":600,"wires":[["1b22c751844fc7f2","95d7d2555e203875"]]},{"id":"4359f485fb86ee21","type":"change","z":"8e2ddd056e4aef03","g":"4a7c0ef41884ac5b","name":"Modbus-Simulator","rules":[{"t":"set","p":"payload","pt":"msg","to":"[18289,51227,18302,28751,18308,40470]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":600,"wires":[["001b772a159b406a"]]}]

thank you very much!!! the "key/val version" was exactly what I was looking for and with this I understand the message-flow much better!

last question in this thread:
In my modbus-node, I'm reading now 6 registers in a row and forward it to the buffer parser. However in some cases the required registers are separated by other information (not required). As an example - I need registers 600, 601, 800, 801, 1000, 1001. Is it good to do it the same way (reading 402 registers) and just adapt the offset in buffer parser or will I overflow the system with too much data?

For minimising data comms, improving read speeds AND as a bonus, getting consistent data it is absolutely better to pull larger arrays of values and parse only the items of interest (skipping the unused data)

I wrote an article on this here: Modernize your legacy industrial data. Part 2. • FlowFuse

HOWEVER: Modbus has a physical limitation of 125 (ish) registers in one go. So for modbus, I tend to group things into reads of 100 or less registers. it makes the byte offset calcs easier. so what i would say is: If you have control over modbus register placement in the end device, try to lay them out so that related items are in the same block of registers & pull them all at once.

2 Likes

Dear Steve-Mcl,

thank you very much! Your articel was very helpfull and I understand much better the potential of node-red. I also can recommend reading the first part of your article to everyone starting with modbus...

1 Like

This is exactly what i did when I was struggling with non-contiguos data registers, modified the ladder program to make a copy of required data registers into one continuous block

1 Like

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