I'm wondering if there is any other (or better) way to find the daily rolling average temperature than this psudocode:
//variables
x = current temp
y = previous cumulative daily temp
z = new cumulative daily temp
a = average daily temp
i = number of readings taken (increases every reading)
//--------------------------------
i +1 (increase to show how many times we've taken a reading)
z = y + x
a = z / i
y = z (make previous cumulative daily temp new cumulative daily temp)
My only concern is by some freak event the temperature is zero degrees C all day and it crashes. It's very unlikely to ever see exactly zero as the sensor spits out a float to 2dp, however its still something I'd like to mitigate against.
that would give you the average from the moment you start your ESP and until your overflow the double or the unsigned long
usually you don't want an average over such a long period, you just want to average the last 10 readings or something like that or have a running average
Please do yourself a favor and give your variables a proper name...
Either z or y is not needed....
sum = sum + cur_temp;
What would be the problem if it is 0 degrees all day?
How many floats will you add? Every minute or every second? You might loose accuracy if sum >> cur_temp.
The variables will be named properly when I come to write the code, I was looking at the method rather than the variable names.
I did forget to say I'd only be taking a reading every 30min, so 48 readings a day then the counter would reset. The method seems sound to me thank you.
The issue with 0 all day is, I thought, we don't like dividing into or by 0?