Ok, rather than like my previous attempt (may be deleted now) here is the problem:
Two RPIs. They both ping the Gateway and another "real" IP address.
They both report their results and publish them to MQTT.
The messages range from:
OnLine, OffLine. (And if that RPI is powered down/turned off - in which case its messages are ignored.)
So.....
I am looking at "who's" message has higher weight than the other.
If both machines are both sending OnLine messages, which is the one I show?
If either sends OffLine then the other will get priority and it's message will be on-sent (that being OnLine.)
If BOTH are OffLine, then who's message is shown?
That's easy enough for me to determine, but please: Indulge me a bit more.
The above is (say) to the MODEM - say.
Then there is the "uplink", as I call it.
The above will need to be done to the message of the "uplink" status as well.
I'm stuck at how to do this: where both are the same.
Well, thinking about it: I think I don't really get the whole thing other than I concept of what it does. But no real understanding of how to do this.
If you need to make decisions based on the current state of two variables then feed them both into a Join node set to Key/Value pair mode, identified by topic, wait for 2 messages and send on every new message after that, so you then get one message with both values in it each time either of them changes. Then you can perform whatever logic you want on the result.
But reading the info on the node it kind of says it is to be used with the split node.
It joins the two strings. I am missing how I can use this to assign weight to which message is shown.
Could you please expand on how this node is supposed to get two messages and "select" one of the two to on-send. Which one is not fixed. Either in message position or "who" sends it.
Don't use string mode, use key/value mode (as I said, go back and read the original mail again).
Once you have both of them you can look at them and send whatever you want.
Ok, with the join node working and set how you say I get alternate outputs of both machines with their messages.
Though it (from my example above) I am getting: Machine1 modem online Machine2 modem online Machine1 modem online
and so on.
(by edit)
Ok, looked at it again a bit harder, but gee it is difficult to see the difference.
(I am not getting it.)
I can't see how that is useful.
Paul:
Thanks.
That looks interesting.
Seems I have to (maybe) learn about that language/syntax now too.
Colin, yes. But "testing them" is not something I understand.
This is what I have made in the mean time:
var BP = context.get('BedPi')||0; // Has data come in from BedPi?
var TP = context.get('TimePi')||0; // Has data come in from TimePi?
var new_message;
if (msg.topic == 'BedPi Modem')
{
// BedPi message received.
if (msg.state === true)
{
//
context.set('BedPi',1);
context.set('BedPi_message',msg.payload);
} else
{
context.set('BedPi',0)
context.set('BedPi_message',msg.payload);
}
} else
if (msg.topic == 'TimePi Modem')
{
// TimePi message received.
if (msg.state === true)
{
//
context.set('TimePi',1);
context.set('TimePi_message',msg.payload);
} else
{
context.set('TimePi',0)
context.set('TimePi_message',msg.payload);
}
}
// Now The contexts have been set, act depending on what is set.
if (TP == 1)
{
//
// Use TP status and display it.
//
msg.payload = context.get('TimePi_message');
return msg;
} else
if (BP == 1)
{
//
// BedPi is online.
//
msg.payload = context.get('BedPi_message');
return msg;
}