diff --git a/main/main.c b/main/main.c index 8824090..6e3b1ec 100644 --- a/main/main.c +++ b/main/main.c @@ -5,6 +5,7 @@ */ #include "dht22.h" +#include "sdkconfig.h" #include "wifi.h" #include "esp_log.h" #include "esp_sntp.h" @@ -61,7 +62,7 @@ typedef struct { my_dht22_data latest_datapoint; my_dht22_data ten_minute_rolling_average; -uint16_t num_samples_last_ten_mins = 0; +uint32_t num_samples_last_ten_mins = 0; void read_from_dht22() { while (run_dht) { @@ -104,8 +105,18 @@ void read_from_dht22() { (latest_datapoint.temp - ten_minute_rolling_average.temp) / num_samples_last_ten_mins; } num_samples_last_ten_mins += 1; - // TODO: If 10 minute average taken, save it and reset num_samples and ten_min_av - // TODO: Write the data out somewhere - into RAM maybe + + // 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. + if (num_samples_last_ten_mins >= + (CONFIG_DHT22_PERIOD_POLL * 1000 * 60 * 10)) { + num_samples_last_ten_mins = 0; + // TODO: Write the data out somewhere - into RAM maybe + // TODO: maybe push the data somewhere - or put a flag up that data can be pushed + // ^ could do a cute Semaphore thingy here - I don't think I've actually used one before + } } } vTaskDelay(pdMS_TO_TICKS(CONFIG_DHT22_PERIOD_POLL));