parseFloat doesn't output zero values

I have this function receiving a stream of data from a script running an analog to digital converter.

var t=msg.payload;
for (i = 0; i < k.length; i++)

		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.

This is the payload:


Since can happen that a specific value is just a 0, how can I solve this inconvenience?
Any help will be appreciated.

0 is falsey in JavaScript so this if clause will be skipped.

1 Like

Got it. Thanks

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.

If you know there must be (for example) 9 or more items then test the length of k immediately after the split.

if(k.length < 9) {
  return null;
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.