I have a button (on/off) - connected to another node that only shows msg when it is turned on.
I have another mqtt in, that is connected along with the first node to a function node.
What I would like to achieve in node-red is to get the max of all the input msg from mqtt in when the button is on.
I have tried to use the code below in a function but it seems doesn't show the output as array when I check the debug output:
var newmsg = {lit:msg.payload};
if( context.global.stat =="on")
{
var litarray = []; //define empty array to get max later
while(context.global.stat =="on")
{
litarray.push(newmsg);
return[litarray,null];
}
}
if (context.global.stat == "off")
{
return[null, null];
}