RBE/filter + Rate Limit

I've appreciated this code here from @Colin.

How would I go about comparing objects, for it seems that objects pass through the RBE + rate limit node without reference to the rate limit.

Here is the code:

const minInterval = 5000       // min interval between outputs, msec
const previous = context.get("previous") || {timestamp: 0}
const now = new Date().getTime()
if ( msg.payload == previous.value  && (now - previous.timestamp) < minInterval )
{
    // same value as last one and too soon to send again, so send nothing
    msg = null
} else {
    previous.timestamp = now
    previous.value = msg.payload
    context.set("previous", previous)
}
return msg;

Provided the payload is a reasonable simple object then this should work I think

if ( JSON.stringify(msg.payload) === JSON.stringify(previous.value) && ...

1 Like

Thanks Colin.

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