Actuellement, il faut que la valeur soit attribuée à la propriété payload uniquement. Donc, il faut reformater pour que le message arrive correctement au nœud suivant.
Un même nœud de type fonction peut sortir plusieurs messages sur une ou plusieurs sorties. Cette technique permet de ne pas multiplier les nœuds de type fonctions et permet de tout traiter en une fois pour tout envoyer aux différents nœuds suivants.
Deux exemples:
- return [ msg1,msg2,msg3 ]
[{"id":"4f7b0a93c55ee47c","type":"inject","z":"606b655c5dab1a2b","name":"Push","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":1060,"wires":[["34109ca32c578b6e"]]},{"id":"34109ca32c578b6e","type":"function","z":"606b655c5dab1a2b","name":"Test","func":"let msg1 = { topic: 'A', payload: 1 }\nlet msg2 = { topic: 'B', payload: 2 }\nlet msg3 = { topic: 'C', payload: 3 }\n\nreturn [msg1,msg2,msg3];","outputs":3,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":250,"y":1060,"wires":[["54f494fb64e95490"],["dad25bc19c0a64b2"],["d6b0115031f4104a"]]},{"id":"d6b0115031f4104a","type":"function","z":"606b655c5dab1a2b","name":"Msg3","func":"node.status({fill:'grey',shape:'dot',text:msg.payload})\nreturn null;","outputs":0,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":1100,"wires":[]},{"id":"dad25bc19c0a64b2","type":"function","z":"606b655c5dab1a2b","name":"Msg2","func":"node.status({fill:'grey',shape:'dot',text:msg.payload})\nreturn null;","outputs":0,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":1060,"wires":[]},{"id":"54f494fb64e95490","type":"function","z":"606b655c5dab1a2b","name":"Msg1","func":"node.status({fill:'grey',shape:'dot',text:msg.payload})\nreturn null;","outputs":0,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":1020,"wires":[]}]
Chaque message est envoyé sur une sortie différente. Le nombre de sortie doit être correctement défini dans l’onglet Setup.
- return [[ msg1,msg2,msg3 ]]
[{"id":"f4ac1bb7b975cfe5","type":"inject","z":"606b655c5dab1a2b","name":"Push","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":1240,"wires":[["e369a4e879cd0284"]]},{"id":"e369a4e879cd0284","type":"function","z":"606b655c5dab1a2b","name":"Test","func":"let msg1 = { topic: 'A', payload: 1 }\nlet msg2 = { topic: 'B', payload: 2 }\nlet msg3 = { topic: 'C', payload: 3 }\n\nreturn [[msg1,msg2,msg3]];","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":250,"y":1240,"wires":[["08de2729793b1e82"]]},{"id":"b26555d5c16f2b23","type":"function","z":"606b655c5dab1a2b","name":"Topic C","func":"node.status({fill:'grey',shape:'dot',text:msg.payload})\nreturn null;","outputs":0,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":1280,"wires":[]},{"id":"719c7e0c4a54334c","type":"function","z":"606b655c5dab1a2b","name":"Topic B","func":"node.status({fill:'grey',shape:'dot',text:msg.payload})\nreturn null;","outputs":0,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":1240,"wires":[]},{"id":"3f3c860ff5917251","type":"function","z":"606b655c5dab1a2b","name":"Topic A","func":"node.status({fill:'grey',shape:'dot',text:msg.payload})\nreturn null;","outputs":0,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":1200,"wires":[]},{"id":"08de2729793b1e82","type":"switch","z":"606b655c5dab1a2b","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"A","vt":"str"},{"t":"eq","v":"B","vt":"str"},{"t":"eq","v":"C","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":390,"y":1240,"wires":[["3f3c860ff5917251"],["719c7e0c4a54334c"],["b26555d5c16f2b23"]]}]
Tous les messages sont envoyés sur une seule sortie. Le nœud suivant traite les messages séquentiellement, un par un en respectant l’ordre d’arrivé.