Switch to Filter Messages followed by Join

Two nodes "A" and "B" emit payload.MotionDetected with a value of either 1 or 0 and a Function node adds a timestamp, payload.Time, with Date.now() and a Change node applies a Topic (to differentiate A from B).

A Switch then filters these messages, allowing through only MotionDetected values of 1. These are then Joined to create a key/value object using Topic as the key.

The goal is to compare the timestamps to see which is greater (happened most recently).

The comparison in a Function node is trivial, but I am unsure how I can ensure I only act when I have a pair of messages from BOTH - rather than a pair of messages from ONE.

I'm thinking of discarding a message from A that is not accompanied by one from B within a certain timeout OR if the next message was also from A to discard the first (and continue waiting for one from B) and vice-versa. I think I need something like a reverse deadband RBE node somewhere, but I can't get my head around this (whereas the act of drafting a question usually clarifies it for me)

Any ideas/help gratefully acceppted!

Can you show a screenshot of how you have configured the Join node please? You can paste an image here.

Here it is.
Screenshot 2022-02-16 at 14.15.37

You will never get that with the configuration you have, as you have said it has to receive messages with two different topics.
However, if useful, you could also specify a timeout time then if two messages arrive within that time then they will be passed on, but if only one arrives in that time then it will be passed on anyway, and you can check in your function which one(s) are present and take appropriate action.

Ah! So as the key has to be unique it dictates that the topics need to be different.

I'll try the timeout suggestion and see how far I get. Thank you.

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