Hi, I´m new to node red and Javascript and got a problem that maybe somebody can help me to short out.
I have a flow that in a point writes three 16bit status arrays in a database. It works ok but I´m trying to filter so it only should be writing a new row when a bit change in the incoming new msg.
To do so I´ve implemented a function node with the following JS code :
var old_State1;
var old_State2;
var old_State3;
if (msg.payload.State1 != old_State1) {
old_State1 = msg.payload.State1;
return msg;
}
if (msg.payload.State2 != old_State1){
old_State2 = msg.payload.State2;
return msg;
}
if (msg.payload.State3 != old_State1){
old_State3 = msg.payload.State2;
return msg;
}
Also at "On Start" section I´ve added the following :
old_State1 = [];
old_State2 = [];
old_State3 = [];
As you can imagine this is nos working so I gess I´m doing something wrong.
My node-red version is 2.2.2 and my node.js version is 16.16.0
Any help would be so much appreciated