Cleanedup code and added some logging
I think the averaging is working - will need to check the 10 minutes
This commit is contained in:
16
main/main.c
16
main/main.c
@@ -17,6 +17,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
static const char *TAG = "YASPAM";
|
||||
|
||||
@@ -64,9 +65,8 @@ uint32_t num_samples_last_ten_mins = 0;
|
||||
|
||||
void read_from_dht22() {
|
||||
// From datasheet:
|
||||
// Don't start within 1 second of powering on
|
||||
// FIXME - still doesn't actually fix the problem though
|
||||
//vTaskDelay(pdMS_TO_TICKS(20000));
|
||||
// - Don't start within 1 second of powering on
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
|
||||
while (run_dht) {
|
||||
int ret = dht22_read();
|
||||
@@ -96,13 +96,13 @@ void read_from_dht22() {
|
||||
num_samples_last_ten_mins;
|
||||
}
|
||||
num_samples_last_ten_mins += 1;
|
||||
ESP_LOGD(TAG, "ten_minute_average.temp: %"PRIu16", num_samples: %"PRIu32, ten_minute_rolling_average.temp, num_samples_last_ten_mins);
|
||||
|
||||
// This should be: if (number of samples in 10 mins taken)
|
||||
// This _will_ break if sampled too quickly, because we'll have more
|
||||
// samples per 10 minutes than can be stored in a uint32 - I'll
|
||||
// calculate what that is and perhaps raise a compile error if too high.
|
||||
// This should be: if (10 minutes of sample taken)
|
||||
// TODO: check max samples / second that can fit in 10 minutes
|
||||
if (num_samples_last_ten_mins >=
|
||||
((uint32_t) CONFIG_DHT22_PERIOD_POLL * 1000 * 60 * 10)) {
|
||||
((uint32_t)CONFIG_DHT22_PERIOD_POLL * 1000 * 60 * 10)) {
|
||||
ESP_LOGW(TAG, "10 minutes of samples collected. Average temp: %i", ten_minute_rolling_average.temp);
|
||||
num_samples_last_ten_mins = 0;
|
||||
|
||||
time_t epoch;
|
||||
|
||||
Reference in New Issue
Block a user