Skip to content

Send message to an output

bartbutenaers edited this page Sep 16, 2018 · 4 revisions

A message can be sent to the blockly node's output port. That message will travel along wires in the flow to other nodes.

CAUTION: take into account the Node-RED guidelines about sending messages.

  1. Try to store your information in the original input message (msg) , instead of creating every time a new empty message object from scratch. By appending your information to the existing input message, you won't lose the original information from that input message. That information (e.g. topic, http response, ...) might be necessary for the next part of the flow.

  2. When sending messages in a loop, the previous rule is not valid. Resending the same messages might result in strange behaviour, since the next part of the flow might change the information in that same message multiple times. As a result it is better - inside a loop - to clone the input message every time (or create a new empty message). As soon as you try to send messages inside a loop, a warning icon will be displayed:

    image

By default the blockly node has a single output port, but extra outputs can be specified if required.

The following animation shows how to accomplish these steps:

  1. Specify that the blockly node needs to have 3 output ports.
  2. Send the input message (msg) to the second output port.
  3. Check in the debug panel that the message has been send to this output number 2.

blockly_send

Output labels can be specified if required, which provide some information the outputs. The following animation marks the first output for errors, the second output for warnings and the third output for info:

blockly_output_labels

Watch out that the specified output number (to which the message needs to be send), doesn't exceed the number of available outputs on the blockly node. Otherwise an error will be generated. The following animation shows what happens when you try to send a message to output 4, while only 3 outputs are available:

blockly_outputs_overflow

In the first example above, the input message (msg) will be forwarded to the output port. In most use cases however:

  • The input message (msg) will be updated, before sending it to the output. The following animation shows how to update the payload field of the input message to 'my payload':

    blockly_send_updated

  • A new output message will be created from scratch. An animation to explain this can be found .