Create an array from different modbus read

hi,
how can i create a vector from different modbus read node?
is it possible to change the payload name of the modbus read node?
I have to perform mathematical operations from the data processed by several modbus nodes with a function.
Please help me.

Hi @Salvatore looking at your screenshot I assume you want to compute a value based on what comes out of three separate modbus nodes?

If so, then you are not understanding the basic underlying concept of node-red and message flow.

In simple terms, the messages flowing out of the three modbus nodes all arrive at the function at different times. This is an important concept. You could use a join node to join the three messages but there are other issues here....

For example, the values read by those three nodes will be on separate COMMS polls & therefore you could encounter consistency errors.

You would be FAR better off reading a ALL registers in one go (assuming they are near each other and on the same device)

e.g. Say you needed modbus registers 3, 31 and 32. You would be better off having 1 read node that reads all registers 1 ~ 32 - that way, you get consistent data - all in one go - all in the same message.

Further, to assist with the conversion of data types, you could use the buffer-parser node to rhelp with data type conversions.

But firstly, to help you to help yourself, you would be wise to watch this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

hi steve,
thank you for your kind reply.
I thought I had solved this:


do you think this is incorrect?

hi Steve,
can you help me?

What help do you want?

You haven't done any of the recommendations I posted.

Not really. I believe (as I said before) you should read read all related values in one go, ensuring consistency.

Re-read my earlier post.

Hello yes I understand what you were referring to.
My goal is to read the powers coming from each PAC4200 and carry out operations with them (for example add, subtract and divide).
but with the method I was using there is a high risk of having wrong results.
I have 4 PAC4200 in total.

So are the 4 modbus devices on the left 4 separate PAC4200s?

And it is values from these 4 devices you wish to combine?

Question. Why do you have a split node after them then a join?

Question are you reading multiple values from each unit (as an array) that you need to convert to proper units?

Yes, there are 4 devices and they are separate.
I have to read the powers of each device and carry out operations with them.
I put the split node in order to create an array containing all the values ​​to be processed.
No. In addition to the power I'm also reading the energy absorbed.

Thank you

I don't have enough info to help you.

If you want more help...

  • Export and post your flow
  • List all the modbus addresses and their, name and data type (unt16, float, uint32 etc)
  • Provide sample data (as it comes out of the modbus nodes - capture full msg object by using a debug set to show complete message) AND expected values.

flows (16).json (7.7 KB)

As I realized it seemed to work but there is the problem of inconsistency as you explained to me.

I cannot provide example data because at this moment I don't have the pacs with me.
Thank you.

And what modbus registers are you using, what are the value types?

E.g...

Register 2&3 = current, UINT 32 bit

Register 4 = temperature, UINT 16 (scale ÷ 10)

Retailer 5&6 = speed, FLOAT.

It should be register 2 with data type Float

There are a number of issues with your flow. please review the comments & pictures...

PROBLEM 1...

PROBLEM 2 - network delays...
Your invertors will not always respond at the same time so your current solution will get the PUE calculation wrong...

time(sec) device value join count join fires PUE calc
1.01 QGBT 158.89 2 - -
1.03 QEPTC 113.44 4 - -
1.12 QGA 123.44 6 - -
1.16 QGB 139.89 8 NOW (158.89+113.44) / (123.44+139.89) = 1.0341
2.02 QGA 123.44 2 - -
2.06 QEPTC 113.44 4 - -
2.24 QGB 139.89 6 - -
2.84 QGBT 158.89 8 NOW (123.44+113.44) / (139.89+158.89) = 0.7928

PROBLEM 3 - device off line...
Assume INVERTER4 (QGB) is offline - your data will get out of order...

time(sec) device value join count join fires PUE calc
1 QGBT 158.89 2 - -
1 QEPTC 113.44 4 - -
1 QGA 123.44 6 - -
2 QGBT 158.89 8 NOW (158.89+113.44) / (123.44+158.89) = 0.9645
2 QEPTC 113.44 2 - -
2 QGA 123.44 4 - -
3 QGBT 158.89 6 - -
3 QEPTC 113.44 8 NOW (113.44+123.44) / (158.89+113.44) = 0.8698
3 QGA 123.44 2 - -

My solution...

The flow...

[{"id":"9d54e87c.2f5378","type":"join","z":"1ce23005.82287","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":790,"y":380,"wires":[["d1d2cf51.5c6f1","2e87f678.9f56aa"]]},{"id":"23db2fe0.ca234","type":"modbus-getter","z":"1ce23005.82287","name":"P_QGBT","showStatusActivities":false,"showErrors":false,"logIOActivities":false,"unitid":"","dataType":"HoldingRegister","adr":"65","quantity":"2","server":"444193d1.5dbd7c","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"x":460,"y":460,"wires":[["2a2867d2.e55dd8"],[]]},{"id":"3a08a20a.8a3f3e","type":"inject","z":"1ce23005.82287","name":"POLL","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":90,"y":380,"wires":[["84f8ddc0.c1f47","2cb85fbe.97a0a"]]},{"id":"9cedefc3.61c62","type":"change","z":"1ce23005.82287","name":"topic QGBT","rules":[{"t":"set","p":"topic","pt":"msg","to":"QGBT","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":460,"wires":[["23db2fe0.ca234"]]},{"id":"632c87c4.af41b8","type":"change","z":"1ce23005.82287","name":"topic QEPTC","rules":[{"t":"set","p":"topic","pt":"msg","to":"QEPTC","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":520,"wires":[["284a6e10.1b4c72"]]},{"id":"284a6e10.1b4c72","type":"modbus-getter","z":"1ce23005.82287","name":"QEPTC","showStatusActivities":false,"showErrors":false,"logIOActivities":false,"unitid":"","dataType":"HoldingRegister","adr":"65","quantity":"2","server":"afd94ceb.5294b","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"x":460,"y":520,"wires":[["f9fc37d8.f04cb8"],[]]},{"id":"d90eeaab.d0b0b8","type":"change","z":"1ce23005.82287","name":"topic QGA","rules":[{"t":"set","p":"topic","pt":"msg","to":"QGA","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":580,"wires":[["11994479.94fa6c"]]},{"id":"a00548fe.4760d8","type":"change","z":"1ce23005.82287","name":"topic QGB","rules":[{"t":"set","p":"topic","pt":"msg","to":"QGB","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":640,"wires":[["df8bbbd4.fcc7b8"]]},{"id":"11994479.94fa6c","type":"modbus-getter","z":"1ce23005.82287","name":"QGA","showStatusActivities":false,"showErrors":false,"logIOActivities":false,"unitid":"","dataType":"HoldingRegister","adr":"65","quantity":"2","server":"8fdc78ce.763778","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"x":450,"y":580,"wires":[["d5137d4d.6900e"],[]]},{"id":"df8bbbd4.fcc7b8","type":"modbus-getter","z":"1ce23005.82287","name":"QGB","showStatusActivities":false,"showErrors":false,"logIOActivities":false,"unitid":"","dataType":"HoldingRegister","adr":"65","quantity":"2","server":"38f9f7ef.b04278","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"x":450,"y":640,"wires":[["51c468fb.04a3e8"],[]]},{"id":"84f8ddc0.c1f47","type":"change","z":"1ce23005.82287","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":380,"wires":[["9d54e87c.2f5378"]]},{"id":"d1d2cf51.5c6f1","type":"debug","z":"1ce23005.82287","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":950,"y":380,"wires":[]},{"id":"2cb85fbe.97a0a","type":"delay","z":"1ce23005.82287","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":110,"y":460,"wires":[["9cedefc3.61c62","632c87c4.af41b8","d90eeaab.d0b0b8","a00548fe.4760d8"]]},{"id":"2a2867d2.e55dd8","type":"buffer-parser","z":"1ce23005.82287","name":"","data":"responseBuffer.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"TotalActivePowerW","offset":0,"length":1,"offsetbit":0,"scale":1,"mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"setTopic":false,"x":610,"y":460,"wires":[["9d54e87c.2f5378"]]},{"id":"2e87f678.9f56aa","type":"function","z":"1ce23005.82287","name":"PUE","func":"var QGBT = msg.payload.QGBT.TotalActivePowerW;\nvar QEPTC = msg.payload.QEPTC.TotalActivePowerW;\nvar QGA = msg.payload.QGA.TotalActivePowerW;\nvar QGB = msg.payload.QGB.TotalActivePowerW;\nmsg.payload = (QGBT+QEPTC)/(QGA+QGB);\nmsg.topic = \"PUE attuale\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":870,"y":440,"wires":[["b687956a.94f588"]]},{"id":"b687956a.94f588","type":"debug","z":"1ce23005.82287","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":950,"y":500,"wires":[]},{"id":"f9fc37d8.f04cb8","type":"buffer-parser","z":"1ce23005.82287","name":"","data":"responseBuffer.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"TotalActivePowerW","offset":0,"length":1,"offsetbit":0,"scale":1,"mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"setTopic":false,"x":610,"y":520,"wires":[["9d54e87c.2f5378"]]},{"id":"d5137d4d.6900e","type":"buffer-parser","z":"1ce23005.82287","name":"","data":"responseBuffer.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"TotalActivePowerW","offset":0,"length":1,"offsetbit":0,"scale":1,"mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"setTopic":false,"x":610,"y":580,"wires":[["9d54e87c.2f5378"]]},{"id":"51c468fb.04a3e8","type":"buffer-parser","z":"1ce23005.82287","name":"","data":"responseBuffer.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"TotalActivePowerW","offset":0,"length":1,"offsetbit":0,"scale":1,"mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"setTopic":false,"x":610,"y":640,"wires":[["9d54e87c.2f5378"]]},{"id":"444193d1.5dbd7c","type":"modbus-client","z":"","name":"PAC4200_QGBT","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"10502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true},{"id":"afd94ceb.5294b","type":"modbus-client","z":"","name":"PAC4200_QE-PTC","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"10503","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true},{"id":"8fdc78ce.763778","type":"modbus-client","z":"","name":"PAC4200_QGA","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"10504","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true},{"id":"38f9f7ef.b04278","type":"modbus-client","z":"","name":"PAC4200_QGB","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"10505","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true}]

IMPORTANT NOTE: Be careful if you import my flow - I had to adjust the modbus config nodes IP and PORT numbers to do some tests