Problem with average, or i dont understand, how it works.

Jan Maly on 13 Apr 2022
Latest activity Reply by Jan Maly on 14 Apr 2022

Hello,

can someone please help me to understand, how average works? I send data from temperature sensor to Thingspeak roughly every 5 min(DIFF column in seconds). If i dont use average, i can see temperature in more less 5min slots around 20 degrees. See DATUM and TEPLOTA field on first image(Vlhkost is humidity).

I supposed, if i use parameter average=60, it will calculate average temperature in time slot 60min and extract it. But if you check second image with same data, only parameter average=60 added, results are crazy. I can see rows per hour, but values are crazy, around 7 degrees. I really dont understand what system calculate. I get exactly same result on thingspeak page in channel setup, so problem is not with my page.

Thingspeak screenshots 1day without average

1day with average 60

settings i changed

Vinod
Vinod on 14 Apr 2022

I believe your code is updating separate fields of data in each update. You can confirm this by exporting the data in your channel from the "Import/Export data" tab of your channel. What you will find is that there is a pattern where field 1 & 2 are updated, but fields 3-8 are NULL. In a separate update fields 1 & 2 are NULL and 3 & 4 have a value and others are NULL. In a 3rd update, fields 1-4 are NULL and fields 5-8 have a value.

Note that when the average is calculated, the NULLs are treated as zeros. You can avoid this situation by updating all 8 fields simultaneously rather than the current pattern you have.

Jan Maly
Jan Maly on 14 Apr 2022

Hello, many thanks for advice. You are right, i checked export and problem found. But this is not good way of working, NULL isn't same as 0(zero). Is there a way to prevent this wrong calculating and force system to use correct formula? average=sum values / count of values and not average=sum values / count of rows ? Thanks a lot for your help.

Vinod
Vinod on 14 Apr 2022 (Edited on 14 Apr 2022)

The treatment of NULL as 0 goes back to NULL becoming NaN (not a number), which then gets counted as a zero for aggregate operations. It is not ideal, but it is what it is.

Why is it not possible to modify how your device updates the channel? Why not update all fields at once?

If you really must do what you are doing, you can use a MATLAB Analysis app to read the data and calculate a different aggregate than we currently implement and write that to a new channel.

Jan Maly
Jan Maly on 14 Apr 2022

Hello, stay cool mate, i dont wanted angry you. It was just question, because im newbie and started with thingspeak few days ago. Its an amazing service and you have my thanks for perfect project. I just wanted to know, if there is way to prevent this issue with average. Reason why > I use 4 different sensors connected to one arduino. Initially i stored sensor values in variables and once per 5min i connect to thingspeak and send all data at once. But later i found, that im not able recognize datetime, when sensor read data. So i changed my mind and i send data immediately, when sensor send it to arduino. Now im able to see every sensor with related timestamp. Of course, i can always use average=0 and count average from received result on my javascript page, or i can use 4 different channels...there is a way, but i wanted to know, if there is some simple way on thingspeak to ignore NULL.

Anyway, thanks a lot for your patience and help.

Christopher Stapels
Christopher Stapels on 14 Apr 2022 (Edited on 14 Apr 2022)

You can also use the MATLAB Visualizations app to plot the values with the appropriate averaging on your channel. It just doesn't live update on every data point like the field plots do.

By the way, MATLAB 'NULL' is capitalized, I don't think Vinod was yelling at you :) He's a really nice guy, I can vouch for him.

Vinod
Vinod on 14 Apr 2022

My apologies if I came across as angry - I am not :) I was just providing you the details of the behavior on ThingSpeak and suggestions for how to work around it.

Jan Maly
Jan Maly on 14 Apr 2022

Guys, really appreciate your help to newbie(me). So again, thanks a lot for help to both of you.

Tags

No tags entered yet.