Arrays can be iterated using the split node.
Then you update the topic of each message emitted from the split node to append "_n" to the topic (where n
is the index + 1)
NOTE: The split node adds msg.parts
to each message, which contains the index
. (see built in help of split node) (add a debug node to the output of the split node (set to show complete message) to this for your own understanding)
Demo:
[{"id":"c61dd404de610e73","type":"inject","z":"06a2836c9f2ae124","name":"transformer/temperature_PL6X12 [50, 40, 43]","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"transformer/temperature_PL6X12","payload":" [50, 40, 43]","payloadType":"json","x":1410,"y":460,"wires":[["efac7f31e3da5f23"]]},{"id":"cefe06e6888df2bf","type":"split","z":"06a2836c9f2ae124","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":1370,"y":400,"wires":[["6fdd372739f2be43"]]},{"id":"6fdd372739f2be43","type":"change","z":"06a2836c9f2ae124","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"topic & \"_\" & (parts.index+1)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1510,"y":400,"wires":[["8ee933d648549309"]]},{"id":"8ee933d648549309","type":"debug","z":"06a2836c9f2ae124","name":"debug 14","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1820,"y":400,"wires":[]},{"id":"efac7f31e3da5f23","type":"switch","z":"06a2836c9f2ae124","name":"","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"array","vt":"array"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1670,"y":460,"wires":[["cefe06e6888df2bf"],["c9904fc2b7f3ee69"]]},{"id":"c9904fc2b7f3ee69","type":"debug","z":"06a2836c9f2ae124","name":"debug 15","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1820,"y":480,"wires":[]},{"id":"89333c91338bce96","type":"inject","z":"06a2836c9f2ae124","name":"transformer/temperature_PL6X13 55","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"transformer/temperature_PL6X13","payload":"55","payloadType":"num","x":1380,"y":520,"wires":[["efac7f31e3da5f23"]]},{"id":"58ddd82492454565","type":"inject","z":"06a2836c9f2ae124","name":"transformer/temperature_PL6X14 \"some text\"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"transformer/temperature_PL6X14","payload":"some text","payloadType":"str","x":1410,"y":580,"wires":[["efac7f31e3da5f23"]]}]