Cleanedup code and added some logging

I think the averaging is working - will need to check the 10 minutes
This commit is contained in:
2023-10-31 21:24:21 +00:00
parent 6a3e39342e
commit 7b29ea24db
2 changed files with 11 additions and 20 deletions

View File

@@ -76,10 +76,7 @@ dht22_error dht22_read() {
if (elapsed_time == DHT22_TIMEOUT_ERROR) {
portENABLE_INTERRUPTS();
return DHT22_TIMEOUT_ERROR;
} /*else if (elapsed_time > 50) {
portENABLE_INTERRUPTS();
return DHT22_TIMING_ERROR;
}*/
}
/*
* From datasheet:
@@ -91,19 +88,13 @@ dht22_error dht22_read() {
if (elapsed_time == DHT22_TIMEOUT_ERROR) {
portENABLE_INTERRUPTS();
return DHT22_TIMEOUT_ERROR;
} /*else if (elapsed_time < 50 || elapsed_time > 110) {
portENABLE_INTERRUPTS();
return DHT22_TIMING_ERROR;
}*/
}
elapsed_time = wait_for_signal_to_change_from(1);
if (elapsed_time == DHT22_TIMEOUT_ERROR) {
portENABLE_INTERRUPTS();
return DHT22_TIMEOUT_ERROR;
} /*else if (elapsed_time < 50 || elapsed_time > 110) {
portENABLE_INTERRUPTS();
return DHT22_TIMING_ERROR;
}*/
}
/*
* From datasheet:

View File

@@ -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;