How implement two inputs for node?

how implement two inputs for node ?
node-red version 3.1.1

I believe this has been raised many (MANY) times before.

A possible solution is to make input 1 and input 2 messages have a different attribute.

eg: msg.indentifier == 1 and msg.identifier == 2 for the two different messages.

Then parse the message structure to determine who sent it.

Also understand that nodes only accept ONE MESSAGE AT A TIME, so two inputs wouldn't really work.

And - back to what I was saying - you WILL HAVE TO store one of the messages in context so when the second one arrives, it has the other one.

Other thought!

Use a join node to receive two messages before onsending it.
Then BOTH messages arrive at the same time.

But that may not work if there is/are overlaps in the message structures.

2 Likes

if you create a custom node with two inputs, it still won't work ? is it limited in the node-red source code itself ?

No a node with two inputs won't work.

Node-red is not synchronous.
Messages arrive at unknown times.

So there will be a problem that one message arrives and it (your node) then has to wait for the second message to arrive.

I offered two ways around that.

I shall say though:
I am still very much in/at the shallow end of knowledge.

Node-RED makes the hard limit of zero or one input to a node - there is no such thing as a 2 input node.

It's an inbuilt assumption.

For reference, just a small selection, where this has been discussed: :sweat_smile:

7 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.