Sending multiple payloads

1,220 views
Skip to first unread message

Garry Hayne

unread,
Apr 12, 2017, 2:37:39 PM4/12/17
to Node-RED
Hi,

is this code OK (it works), or is there a better way to do it, I want to send multiple messages to a MQTT  broker:

Function node code:

node.send({payload:"4off"});
node.send({payload:"8off"});
return null;

Thanks, Garry

Leif Neland

unread,
Apr 12, 2017, 2:42:45 PM4/12/17
to Node-RED
If it works, it's OK for me ;-)

If it didn't I would have made two outputs on the node, and joining them to the MQTT.

Nick O'Leary

unread,
Apr 12, 2017, 3:07:18 PM4/12/17
to Node-RED Mailing List
Hi Garry,

here's what the docs have to say on the subject: http://nodered.org/docs/writing-functions#multiple-messages

Essentially:

    return  [ [ {payload:"4off"}, {payload:"8off"} ] ]

Nick

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/8dfb9877-e020-4dd6-afb8-8d101dc05778%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Garry Hayne

unread,
Apr 12, 2017, 4:17:54 PM4/12/17
to Node-RED
Yes Nick, I had seen that, I just thought my (borrowed) method was more efficient because it is shorter to code, but wondered if it was "correct". 


On Wednesday, April 12, 2017 at 8:07:18 PM UTC+1, Nick O'Leary wrote:
Hi Garry,

here's what the docs have to say on the subject: http://nodered.org/docs/writing-functions#multiple-messages

Essentially:

    return  [ [ {payload:"4off"}, {payload:"8off"} ] ]

Nick
On 12 April 2017 at 19:42, Leif Neland <lei...@gmail.com> wrote:
If it works, it's OK for me ;-)

If it didn't I would have made two outputs on the node, and joining them to the MQTT.


Den onsdag den 12. april 2017 kl. 20.37.39 UTC+2 skrev Garry Hayne:
Hi,

is this code OK (it works), or is there a better way to do it, I want to send multiple messages to a MQTT  broker:

Function node code:

node.send({payload:"4off"});
node.send({payload:"8off"});
return null;

Thanks, Garry

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Garry Hayne

unread,
Apr 13, 2017, 7:20:59 AM4/13/17
to Node-RED
Nick,

your method is more succinct!!

Garry
Reply all
Reply to author
Forward
0 new messages