There's a bug with the rolling average

Not quite sure where though
This commit is contained in:
2023-10-31 22:12:51 +00:00
parent 0bbae8a254
commit 6ed826ed7a
2 changed files with 65 additions and 10 deletions

View File

@@ -9,7 +9,7 @@ menu "DHT22"
depends on DHT22_ENABLED depends on DHT22_ENABLED
config DHT22_PERIOD_POLL config DHT22_PERIOD_POLL
int "Period to poll the DHT22 in ms" int "Period to poll the DHT22 in seconds"
default 2000 default 2000
depends on DHT22_ENABLED depends on DHT22_ENABLED
endmenu endmenu

View File

@@ -44,7 +44,7 @@ void read_from_pms5003() {
// TODO: actually collect some data // TODO: actually collect some data
ESP_LOGI(TAG, "Got PMS5003 data!"); ESP_LOGI(TAG, "Got PMS5003 data!");
// TODO: Write the data out somewhere // TODO: Write the data out somewhere
vTaskDelay(pdMS_TO_TICKS(CONFIG_PMS5003_PERIOD_POLL)); vTaskDelay(pdMS_TO_TICKS(CONFIG_PMS5003_PERIOD_POLL * 1000));
} }
} }
#endif /* CONFIG_PMS5003_ENABLED */ #endif /* CONFIG_PMS5003_ENABLED */
@@ -82,8 +82,10 @@ void read_from_dht22() {
// avoid some weird bugs (e.g. time changing from 1970 -> current time within // avoid some weird bugs (e.g. time changing from 1970 -> current time within
// a 10 min period or just saving data saying it's from the 70s) // a 10 min period or just saving data saying it's from the 70s)
/* /*
* Appears to be a bug when hitting num samples = 64 There is a bug _somewhere_
* Here's a log:
First log:
W (327852) YASPAM: temperature: 19.500000 & relative humidity: 64.000000 W (327852) YASPAM: temperature: 19.500000 & relative humidity: 64.000000
W (327852) YASPAM: ten_minute_average.temp: 195, num_samples: 62 W (327852) YASPAM: ten_minute_average.temp: 195, num_samples: 62
W (332862) YASPAM: temperature: 19.400000 & relative humidity: 64.100000 W (332862) YASPAM: temperature: 19.400000 & relative humidity: 64.100000
@@ -101,7 +103,7 @@ W (357912) YASPAM: ten_minute_average.temp: 35406, num_samples: 68
W (362922) YASPAM: temperature: 19.400000 & relative humidity: 64.600000 W (362922) YASPAM: temperature: 19.400000 & relative humidity: 64.600000
W (362922) YASPAM: ten_minute_average.temp: 35851, num_samples: 69 W (362922) YASPAM: ten_minute_average.temp: 35851, num_samples: 69
Another log - suggesting it's not to do with 64: Another log:
I (387992) YASPAM: ten_minute_average.temp: 187, num_samples: 74 I (387992) YASPAM: ten_minute_average.temp: 187, num_samples: 74
W (392992) YASPAM: temperature: 18.700000 & relative humidity: 69.900000 W (392992) YASPAM: temperature: 18.700000 & relative humidity: 69.900000
@@ -114,7 +116,60 @@ W (408022) YASPAM: temperature: 18.700000 & relative humidity: 69.800000
I (408032) YASPAM: ten_minute_average.temp: 53805, num_samples: 78 I (408032) YASPAM: ten_minute_average.temp: 53805, num_samples: 78
W (413032) YASPAM: temperature: 18.800000 & relative humidity: 69.600000 W (413032) YASPAM: temperature: 18.800000 & relative humidity: 69.600000
Something overrunning and stomping on my bits? Another log where it corrected itself (decided to print the decitemp
rather than float):
I (22231) YASPAM: latest_datapoint.temp: 188
I (22231) YASPAM: ten_minute_average.temp: 188, num_samples: 1
I (27241) YASPAM: latest_datapoint.temp: 188
I (27241) YASPAM: ten_minute_average.temp: 188, num_samples: 2
I (32251) YASPAM: latest_datapoint.temp: 188
I (32251) YASPAM: ten_minute_average.temp: 188, num_samples: 3
I (37261) YASPAM: latest_datapoint.temp: 187
I (37261) YASPAM: ten_minute_average.temp: 22033, num_samples: 4
I (42271) YASPAM: latest_datapoint.temp: 187
I (42271) YASPAM: ten_minute_average.temp: 16571, num_samples: 5
I (47281) YASPAM: latest_datapoint.temp: 187
I (47281) YASPAM: ten_minute_average.temp: 26401, num_samples: 6
I (52291) YASPAM: latest_datapoint.temp: 187
I (52291) YASPAM: ten_minute_average.temp: 186, num_samples: 7
I (57301) YASPAM: latest_datapoint.temp: 187
I (57301) YASPAM: ten_minute_average.temp: 186, num_samples: 8
I (62311) YASPAM: latest_datapoint.temp: 188
I (62311) YASPAM: ten_minute_average.temp: 186, num_samples: 9
I think someone might be stomping on my bits perhaps?
There's potentially a bug with the average temp calculation (or storing)
I (152421) YASPAM: latest_datapoint.temp: 187
I (152421) YASPAM: ten_minute_average.temp: 187, num_samples: 27
I (157431) YASPAM: latest_datapoint.temp: 188
I (157431) YASPAM: ten_minute_average.temp: 187, num_samples: 28
I (162441) YASPAM: latest_datapoint.temp: 188
I (162441) YASPAM: ten_minute_average.temp: 187, num_samples: 29
... increase temperature for a while
I (558231) YASPAM: latest_datapoint.temp: 246
I (558231) YASPAM: ten_minute_average.temp: 187, num_samples: 108
I (563241) YASPAM: latest_datapoint.temp: 245
I (563241) YASPAM: ten_minute_average.temp: 187, num_samples: 109
I (568241) YASPAM: latest_datapoint.temp: 244
I (568241) YASPAM: ten_minute_average.temp: 187, num_samples: 110
... no change in average
I (618321) YASPAM: latest_datapoint.temp: 234
I (618321) YASPAM: ten_minute_average.temp: 187, num_samples: 120
W (618331) YASPAM: 10 minutes of samples collected. Average temp: 187
I (623331) YASPAM: latest_datapoint.temp: 233
I (623331) YASPAM: ten_minute_average.temp: 233, num_samples: 1
I (628331) YASPAM: latest_datapoint.temp: 231
I (628331) YASPAM: ten_minute_average.temp: 231, num_samples: 2
I (633341) YASPAM: latest_datapoint.temp: 231
I (633341) YASPAM: ten_minute_average.temp: 231, num_samples: 3
I (638341) YASPAM: latest_datapoint.temp: 229
I (638341) YASPAM: ten_minute_average.temp: 22075, num_samples: 4
I (643351) YASPAM: latest_datapoint.temp: 228
I (643351) YASPAM: ten_minute_average.temp: 16613, num_samples: 5
^ Did capture 10 mins of samples though! And appears to reset correctly.
*/ */
@@ -126,7 +181,7 @@ Something overrunning and stomping on my bits?
(latest_datapoint.rh - ten_minute_rolling_average.rh) / (latest_datapoint.rh - ten_minute_rolling_average.rh) /
num_samples_last_ten_mins; num_samples_last_ten_mins;
ten_minute_rolling_average.temp += ten_minute_rolling_average.temp +=
(latest_datapoint.temp - ten_minute_rolling_average.temp) / (latest_datapoint.temp - ten_minute_rolling_aevrage.temp) /
num_samples_last_ten_mins; num_samples_last_ten_mins;
} }
num_samples_last_ten_mins += 1; num_samples_last_ten_mins += 1;
@@ -136,7 +191,7 @@ Something overrunning and stomping on my bits?
// This should be: if (10 minutes of sample taken) // This should be: if (10 minutes of sample taken)
// TODO: check max samples / second that can fit in 10 minutes // TODO: check max samples / second that can fit in 10 minutes
if (num_samples_last_ten_mins >= if (num_samples_last_ten_mins >=
((uint32_t)CONFIG_DHT22_PERIOD_POLL * 1000 * 60 * 10)) { ((10 * 60) / (CONFIG_DHT22_PERIOD_POLL))) {
ESP_LOGW(TAG, "10 minutes of samples collected. Average temp: %i", ten_minute_rolling_average.temp); ESP_LOGW(TAG, "10 minutes of samples collected. Average temp: %i", ten_minute_rolling_average.temp);
num_samples_last_ten_mins = 0; num_samples_last_ten_mins = 0;
@@ -162,7 +217,7 @@ Something overrunning and stomping on my bits?
} }
} }
} }
vTaskDelay(pdMS_TO_TICKS(CONFIG_DHT22_PERIOD_POLL)); vTaskDelay(pdMS_TO_TICKS(CONFIG_DHT22_PERIOD_POLL * 1000));
} }
} }
#endif /* CONFIG DHT22_ENABLED */ #endif /* CONFIG DHT22_ENABLED */