Dealing with multiple msg.payloads at once

Hi! I'm wondering if there's a more efficient way to accomplish what I'm doing here.

I'm using the FlightRadar24 Node, and the goal is that I want to generate a return-separated list of all of the flight registration numbers that it sees when activated.

Here's the flow that I made that accomplishes this, but I can't help but to think there's a more efficient way of doing it.

The challenge that I'm having is is that it returns each flight as its own msg.payload, rather than an object containing all of the flights.

[{"id":"e078e36c.5ea4d8","type":"tab","label":"FlightRadar24","disabled":false,"info":""},{"id":"847e74f7.1ff67","type":"flightradar24","z":"e078e36c.5ea4d8","lat":"34.129299","latType":"num","lon":"-88.640327","lonType":"num","name":"","x":390,"y":420,"wires":[["341310fb.aee5e","6492175.a155068"]]},{"id":"c9a0c1b4.a9f078","type":"inject","z":"e078e36c.5ea4d8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":280,"y":260,"wires":[["c1a25886.0012b8"]]},{"id":"341310fb.aee5e","type":"debug","z":"e078e36c.5ea4d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":380,"wires":[]},{"id":"ce0e65b0.3f7748","type":"change","z":"e078e36c.5ea4d8","name":"","rules":[{"t":"set","p":"reglist","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":420,"wires":[[]]},{"id":"4eb68d95.03e6ac","type":"debug","z":"e078e36c.5ea4d8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1050,"y":380,"wires":[]},{"id":"c1a25886.0012b8","type":"change","z":"e078e36c.5ea4d8","name":"","rules":[{"t":"set","p":"reglist","pt":"flow","to":" ","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":340,"wires":[["847e74f7.1ff67"]]},{"id":"cbff6f12.04444","type":"function","z":"e078e36c.5ea4d8","name":"","func":"var reg = msg.payload.registration+\"\\n\"\nvar list = flow.get(\"reglist\")\n\nmsg.payload = reg+list\nreturn msg;","outputs":1,"noerr":0,"x":890,"y":420,"wires":[["ce0e65b0.3f7748","4eb68d95.03e6ac"]]},{"id":"6492175.a155068","type":"delay","z":"e078e36c.5ea4d8","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"20","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":600,"y":420,"wires":[["2155f826.78d03"]]},{"id":"2155f826.78d03","type":"switch","z":"e078e36c.5ea4d8","name":"no nulls","property":"msg.payload.registration","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":760,"y":420,"wires":[["cbff6f12.04444"]]}]

Hi Mike, if you are posting code/flows in the forum, can you please put the 3 backtips before and after your code/flow on separate blank lines, as per How to share code or flow json otherwise other users may not be able to import it.

You can edit your post above by using the pencil icon.

Do you want the flow.reglist to contain a string with all the flights ?

You can use a join node to combine the messages, see flow example

[{"id":"25cfb79.25362c8","type":"inject","z":"5e81d16f.2a00b","name":"","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":228,"y":408,"wires":[["f84b9b07.7d029"]]},{"id":"f2e42509.bcd9a","type":"switch","z":"5e81d16f.2a00b","name":"no nulls","property":"msg.payload.registration","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":540,"y":408,"wires":[["f19a893d.91d3a"]]},{"id":"f84b9b07.7d029","type":"flightradar24","z":"5e81d16f.2a00b","lat":"51.463394","latType":"num","lon":"-0.457090","lonType":"num","name":"","x":382,"y":408,"wires":[["f2e42509.bcd9a"]]},{"id":"f19a893d.91d3a","type":"join","z":"5e81d16f.2a00b","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"2","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":674,"y":408,"wires":[["55892059.faab6","b573fde1.e4bd4"]]},{"id":"55892059.faab6","type":"debug","z":"5e81d16f.2a00b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":818,"y":384,"wires":[]},{"id":"b573fde1.e4bd4","type":"change","z":"5e81d16f.2a00b","name":"","rules":[{"t":"set","p":"reglist","pt":"flow","to":"**.registration","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":848,"y":432,"wires":[[]]}]

Note that i have set the lat/lon to London for some usable data (not much flying these days :wink: )
flow.reglist will contain an array of flight registrations.

What is the end goal of this flow ?

Ah, a join node! I didn't even know those existed. This is exactly what I was looking for, thanks!

And as for end goal, not sure yet. I was just experimenting with the data for now. Perhaps one day adding nearby flights to my office status board, we'll see.

Thanks for your help!

1 Like

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