I have this function receiving a stream of data from a script running an analog to digital converter.
var t=msg.payload;
if(t!=="")
{
k=t.split(':');
for (i = 0; i < k.length; i++)
{
k[i]=parseFloat(k[i]);
}
msg.topic="Analogues";
if(k[0]&&k[1]&&k[2]&&k[3]&&k[4]&&k[5]&&k[6]&&k[7]&&k[8])
{
msg.payload={"AP0":k[0],"AP1":k[1],"AP2":k[2],"AP3":k[3],"Ah":k[4],"InstP":k[5],"SOC4":k[6],"SOC3":k[7],"SOC5":k[8]};
return msg;
}
}
The function is working fine until any of the values in the stream of data is a 0.
Then, if any of the values is a 0(zero), the function doesn't output anything.
At the beginning of the cycle the script doesn't output all the values. This until all filters have stored enough values to start computing the output. So the first 10 second I have only a couple of variables with values.
Removing the if would cause a lot of errors:
Error: A 400 Bad Request error occurred: {"error":"unable to parse '102 AP0=26.486082000000003,AP1=undefined,AP2=undefined,AP3=undefined,Ah=undefined,InstP=undefined,SOC3=undefined,SOC4=undefined,SOC5=undefined': invalid boolean"}
I need to find another way... However now I do understand better what is happening.
Thanks for your help.