How to concatenate multiple arrays

Hi,
i have 5 nodes that output an array,
how can i concatenate them into a single array?

example :
node A ->> [-8192, 17418]
node B ->> [-13107, 17143]
node C ->> [-15856, 18725]
node D ->> [0, 18725]
node E ->> [0, 16320]

Desired Out:
OUT == [-8192, 17418,-13107, 17143,-15856, 18725,0,18725,0,16320]

Then I have to send them via the "ModbusFlexiWrite" node:
msg.payload = { 'value': [OUT],
'fc': 16,
'unitid': 1,
'address': 30 ,
'quantity': 5 }

The result should be this (taking care not to lose negative values)

01

Thank you so much for your help.
R.

One possible way to achieve that is using a join node to accumulate the output of the five nodes and then a function node to concatenate them in a single array. The function node might use the spread syntax for the job:

let pay = msg.payload;
return {"value" : [...pay[0], ...pay[1], ...pay[2], ...pay[3], ...pay[4]]};

Flow:

[{"id":"9709bc5b.dc8c9","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"14f6b95b.3a14c7","type":"inject","z":"9709bc5b.dc8c9","name":"","topic":"","payload":"[-8192, 17418]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":290,"y":180,"wires":[["404f4a70.9c6de4"]]},{"id":"323110fa.1ee8b","type":"inject","z":"9709bc5b.dc8c9","name":"","topic":"","payload":"[-13107, 17143]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":220,"wires":[["404f4a70.9c6de4"]]},{"id":"a982d18e.638d4","type":"inject","z":"9709bc5b.dc8c9","name":"","topic":"","payload":"[-15856, 18725]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":260,"wires":[["404f4a70.9c6de4"]]},{"id":"292bf366.07d3cc","type":"inject","z":"9709bc5b.dc8c9","name":"","topic":"","payload":"[0, 18725]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":280,"y":300,"wires":[["404f4a70.9c6de4"]]},{"id":"a3694647.dce098","type":"inject","z":"9709bc5b.dc8c9","name":"","topic":"","payload":"[0, 16320]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":280,"y":340,"wires":[["404f4a70.9c6de4"]]},{"id":"7afc4c37.a2f9c4","type":"debug","z":"9709bc5b.dc8c9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":850,"y":280,"wires":[]},{"id":"404f4a70.9c6de4","type":"join","z":"9709bc5b.dc8c9","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"5","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":560,"y":280,"wires":[["16ec7547.e7d6eb"]]},{"id":"16ec7547.e7d6eb","type":"function","z":"9709bc5b.dc8c9","name":"concat","func":"let pay = msg.payload;\nreturn {\"value\" : [...pay[0], ...pay[1], ...pay[2], ...pay[3], ...pay[4]]};","outputs":1,"noerr":0,"x":690,"y":280,"wires":[["7afc4c37.a2f9c4"]]}]

Perfect, excellent solution, you are a myth thank you very much for your help!

Last question, I am “injecting” the result obtained in the "ModbusFlexiWrite" node but I am also wrong and consequently Modbus does not work,

I get this:

mdb-errato
While I should get this:
mdb-giusto2

Where can I find in-depth manuals on this language and on the node-red base nodes that I consider very powerful (Join, switch, change, etc ...)?

Thanks again for the help.

i am trying this way:

let pay = msg.payload;
msg.payload = {
'value':[...pay[0], ...pay[1], ...pay[2], ...pay[3], ...pay[4]],
'fc': 16,
'unitid': 1,
'address': 50,
'quantity': 10 }
return msg

I find that the ModbusFlexiWrite node only writes when it receives all 10 registers in positive format, is there any logic in this?

At this point the question I ask myself is: how do you send 5 numbers in floating point with the ModbusFlexiWrite node?

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