Hello
I just started using node red and i have this challenge, i want to write a function that can pass more than on payload and topic. Please anyone help with explanations, and ways forward.
Hi @Chenko
the docs cover how to send multiple messages: https://nodered.org/docs/user-guide/writing-functions#multiple-messages
Hi knolleary
Thank you i have red through the document. I will try to understand it
Do you mean you want to send multiple messages, or that you want to send one message but with more in it than payload and topic? If the latter then in a function node you can say
msg.someAttribute = something
You can also do that with a Change node.
As well as the link suggested look at the page on Working with Messages.
Hi @Chenko
Here is a little function that sends multiple msg's. I don't know what your inputs are but I hope this helps you figure a method.
var IPS = msg.payload.ip.split("|");
var TOPIC = msg.payload.message.split("|");
for (var i in IPS) {
msg.payload = {"ip": IPS[i]};
msg.topic = TOPIC[i];
node.send(msg);
}
return;
msg.payload = "1.1.1.1|2.2.2.2|.3.3.3.3"
msg.topic = "topic1|topic2|topic3"
This will send multipe messages (3)
{"msg", {"payload":{"ip": "1.1.1.1"}, "topic": "topic1"}}
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.