Search code examples
ibm-cloudiotnode-red

Specify the output on a function node in Node-Red


I want to know how it is possible to specify on which output a function node can return a message (msg).

For example:

if( msg.eui == "00:11:22:33:44:55:66:88"){
    output1(msg); //return on the output 1 only
}
if( msg.eui == "00:11:22:33:44:55:66:99"){
    output2(msg); //return on the output 2 only
}

What needs to be changed?


Solution

  • That can be done. Node-Red uses an array of messages to address the different output ports.

    if( msg.eui == "00:11:22:33:44:55:66:88"){
        return [msg, null]; //return on the output 1 only
    }
    if( msg.eui == "00:11:22:33:44:55:66:99"){
        return [null, msg]; //return on the output 2 only
    }
    

    The output that should not receive the message is set to null, the other to the return message.