So I am almost done with programming but there appeared some logic questions because my solution is ânot perfectâ
Question #1:
I am doing the rolling 1h and rolling 24h rain amount like this:
double rainAmountCurrentMinute = 0;
double rainAmountLastHour = 0;
byte rainAmountLastHourRollingIndex = 0;
double rainAmountLastHourRolling [60];
double rainAmountLast24Hours = 0;
byte rainAmountLast24HoursRollingIndex = 0;
double rainAmountLast24HoursRolling [24];
byte rainAmountLast24HoursRollingCounter = 0;
//gets called every and once a minute
void everyMinute()
{
//insert the new value to the rolling last hour array
rainAmountLastHourRolling[rainAmountLastHourRollingIndex] = rainAmountCurrentMinute;
//reset the rainAmountCurrentMinute
rainAmountCurrentMinute = 0;
//caculate the next rainAmountLastHourRollingIndex
if (++rainAmountLastHourRollingIndex >= 60)
{
//reset the counter
rainAmountLastHourRollingIndex = 0;
}
//reset the rain amount last hour variable
rainAmountLastHour = 0;
//calculate the current rolling last hour rain amount
for (int i = 0; i < 60; i++)
{
//sum the rain amount
rainAmountLastHour = rainAmountLastHour + rainAmountLastHourRolling[i];
}
//update the last hour rain amount to the last 24 hour rolling array
rainAmountLast24HoursRolling[rainAmountLast24HoursRollingIndex] = rainAmountLastHour;
//if 60min = 1 hour has passed
if ( ++rainAmountLast24HoursRollingCounter >= 60)
{
//reset the counter
rainAmountLast24HoursRollingCounter = 0;
//caculate the next rainAmountLastHourRollingIndex
if (++rainAmountLast24HoursRollingIndex >= 24)
{
rainAmountLast24HoursRollingIndex = 0;
}
//insert the new value to the rolling last hour array and override the oldest value by doing so
rainAmountLast24HoursRolling[rainAmountLast24HoursRollingIndex] = rainAmountLastHour;
}
//reset the rain amount last 24 hour variable
rainAmountLast24Hours = 0;
//calculate the current rolling last 24 hour rain amount
for (int i = 0; i < 24; i++)
{
//sum the rain amount
rainAmountLast24Hours = rainAmountLast24Hours + rainAmountLast24HoursRolling[i];
}
}
Probably the double array is a bit over kill for the rolling values but anywaysâŠ
For the last 1h I store every minute the new value to the array and sum up the array elements to have the rain amount of the last 1h. Everything OK.
For the last 24 hours, the way I do it only stores the last 23 hours and constantly saves the rain amount of the current started hour.
So everytime 23 hours, I drop the oldest hour value und save the current hour rain constantly into the new value.
I have a few ideas how to give a more accurate rolling value, but this always includes to save the rain amount on a minute based array (a lot of storage will be used by that with 1440 doubles⊠of maybe floats).
What do you think about that?
Question #2:
I am using a mobile wifi connection in my garden.
This is sometimes a little weak on stormy/bad weather and also reconnects once a day.
The reconnection takes sometimes a little while and the time is set by the provider.
So my devices are not 100% online all the time and the âoffline timeâ is random.
At the end of each day, I send the rain amount of this day to the bar graph (superchart) for the daylie rain chart.
I do this also in the everyMinute() function by this:
//send all raingauge data at the last minute of the day
if ( (hour() == 23) && (minute() == 59) )
{
//send the todays rain amount to visualize it on a bar chart
sendTodaysRainAmountforBarChart();
}
If the device is offline in that periode, the data will be lost for that day, right?
I can store the values to âplaceholderâ variables fot that purpose, but I will not be able to save this value to the day before into the bar chart Iâm afraid.
Do you have an idea for this?
Question #3:
I am also saving the values of the rain for todays, yesterday, 2days ago and 3days ago (calender days) into a ânormalâ blynk value (not a super chart).
It is a really rare case, but If I turn off the device or there happens power outage, is it possible to let the device request the time when the values have been saved to the server?
This way, it would be possible to sync the values at startup even if a (or more) day/s has passed.
Thanks again for your advices and help @PeteKnight