Data bucket with empty value

Hi all, I have a variable defined as:

int TotalDia;

which is associated with a bucket as:

thing["TotalDiario"] >> outputValue (TotalDia);

and is updated in the loop with the following code:

 if (TotalDia > 0)
          {
            thing.write_bucket("Con2",thing["TotalDia"]); 
          }

question is, how is it possible that I’m getting updates with empty values as can be seen here:

Screen Shot 2022-08-22 at 17.27.35

What am I missing?
Many thanks in advance for any help.
Best!

Hi,

This situation is often related with wrong value type, if the bucket gets the first data as number and it receives not a number (NaN) type value, it does not store it.

How can you store a not a number into a int type value? if you run a for loop that writes something into an array, and the iteration goes beyond the array size (for example) it writes according the loop instruction in that memory address (right next the array address), destroying the data and writing into it, then if you read that address as int it could have a NaN value.

Hope this helps.

Thanks @ega for the hint, will search if I’m trying to write a NaN value, which I don’t think is the case.

Hi,

Which uC are you using?

For debugging purposes I would use the isnan() function and if it is, to write a property to see the variable value.

Something like:

if (isnan(TotalDia))
{
//set the property 
}
else
{
//write the bucket
}

This should warranty that you are writing a number to the bucket.

Hope this helps.

Hi @ega, I’m using an Arduino Yun and I’ll try your suggestion.
In the meantime I’ve made some changes to my code and it seems it is not happening anymore.

Once again, many thanks for your hints.

Regards