I have a couple of function nodes in which I am using context in order to compare the current with older message received and check which one is greater than the other and save the new value to node context in case it is the case.
What I am trying to achieve with the code below is to bring the latest value preserved with context when the button is off, but the problem is that I never receive msg in case the button is off, I guess I am ding something wrong here especially with the returning the msg part.
var prevlit = context.get('prevlit')||0;
if(prevlit !== 0)
{
if(prevlit > msg.payload)
{
context.set('prevlit',prevlit);
msg.payload = prevlit;
}
else
{
context.set('prevlit',msg.payload);
}
}
else
{
context.set('prevlit',msg.payload);
}
if (context.global.stat == "off")
{
return msg; //I want to return the value here when the status is off
}
Thank you for your help with this