Hi,
I would like to sum different topics and payloads together.
The output should be a integer value.
But i have the problem that it doesn't not work as intended
The output is at the moment "NaN"
Where is the mistake
var statusbits1=0;
var statusbits2=0;
var statusbits3=0;
var statusbits4=0;
var statusbits5=0;
var statusbits6=0;
var statusbits7=0;
var statusbits8=0;
var i;
if(i===0)
{
flow.set('statusbits1',0);
flow.set('statusbits2',0);
flow.set('statusbits3',0);
flow.set('statusbits4',0);
flow.set('statusbits5',0);
flow.set('statusbits6',0);
flow.set('statusbits7',0);
flow.set('statusbits8',0);
i=1;
}
statusbits1=flow.get('statusbits1');
statusbits2=flow.get('statusbits2');
statusbits3=flow.get('statusbits3');
statusbits4=flow.get('statusbits4');
statusbits5=flow.get('statusbits5');
statusbits6=flow.get('statusbits6');
statusbits7=flow.get('statusbits7');
statusbits8=flow.get('statusbits8');
if(msg.topic=='1')
{
if (msg.payload<'3.5')
{
flow.set('statusbits1',1);
statusbits1=1;
}
else
{
flow.set('statusbits1',0);
statusbits1=0;
}
}
if(msg.topic=='2')
{
if (msg.payload<'3.5')
{
flow.set('statusbits2',2);
statusbits2=2;
}
else
{
flow.set('statusbits2',0);
statusbits2=0;
}
}
if(msg.topic=='3')
{
if (msg.payload<'3.5')
{
flow.set('statusbits3',4);
statusbits3=4;
}
else
{
flow.set('statusbits3',0);
statusbits3=0;
}
}
if(msg.topic=='4')
{
if (msg.payload==1)
{
flow.set('statusbits4',8);
statusbits4=8;
}
else
{
flow.set('statusbits4',0);
statusbits4=0;
}
}
if(msg.topic=='5')
{
if (msg.payload==1)
{
flow.set('statusbits5',16);
statusbits5=16;
}
else
{
flow.set('statusbits5',0);
statusbits5=0;
}
}
if(msg.topic=='6')
{
if (msg.payload==1)
{
flow.set('statusbits6',32);
statusbits6=32;
}
else
{
flow.set('statusbits6',0);
statusbits6=0;
}
}
if(msg.topic=='7')
{
if (msg.payload==1)
{
flow.set('statusbits7',64);
statusbits7=64;
}
else
{
flow.set('statusbits7',0);
statusbits7=0;
}
}
if(msg.topic=='8')
{
if (msg.payload==1)
{
flow.set('statusbits8',128);
statusbits8=128;
}
else
{
flow.set('statusbits8',0);
statusbits8=0;
}
}
msg.payload=(statusbits1+statusbits2+statusbits3+statusbits4+statusbits5+statusbits6+statusbits7+statusbits8);
msg.topic="status";
return msg;