Cleanedup code and added some logging
I think the averaging is working - will need to check the 10 minutes
This commit is contained in:
@@ -76,10 +76,7 @@ dht22_error dht22_read() {
|
|||||||
if (elapsed_time == DHT22_TIMEOUT_ERROR) {
|
if (elapsed_time == DHT22_TIMEOUT_ERROR) {
|
||||||
portENABLE_INTERRUPTS();
|
portENABLE_INTERRUPTS();
|
||||||
return DHT22_TIMEOUT_ERROR;
|
return DHT22_TIMEOUT_ERROR;
|
||||||
} /*else if (elapsed_time > 50) {
|
}
|
||||||
portENABLE_INTERRUPTS();
|
|
||||||
return DHT22_TIMING_ERROR;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* From datasheet:
|
* From datasheet:
|
||||||
@@ -91,19 +88,13 @@ dht22_error dht22_read() {
|
|||||||
if (elapsed_time == DHT22_TIMEOUT_ERROR) {
|
if (elapsed_time == DHT22_TIMEOUT_ERROR) {
|
||||||
portENABLE_INTERRUPTS();
|
portENABLE_INTERRUPTS();
|
||||||
return DHT22_TIMEOUT_ERROR;
|
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);
|
elapsed_time = wait_for_signal_to_change_from(1);
|
||||||
if (elapsed_time == DHT22_TIMEOUT_ERROR) {
|
if (elapsed_time == DHT22_TIMEOUT_ERROR) {
|
||||||
portENABLE_INTERRUPTS();
|
portENABLE_INTERRUPTS();
|
||||||
return DHT22_TIMEOUT_ERROR;
|
return DHT22_TIMEOUT_ERROR;
|
||||||
} /*else if (elapsed_time < 50 || elapsed_time > 110) {
|
}
|
||||||
portENABLE_INTERRUPTS();
|
|
||||||
return DHT22_TIMING_ERROR;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* From datasheet:
|
* From datasheet:
|
||||||
|
|||||||
14
main/main.c
14
main/main.c
@@ -17,6 +17,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
static const char *TAG = "YASPAM";
|
static const char *TAG = "YASPAM";
|
||||||
|
|
||||||
@@ -64,9 +65,8 @@ uint32_t num_samples_last_ten_mins = 0;
|
|||||||
|
|
||||||
void read_from_dht22() {
|
void read_from_dht22() {
|
||||||
// From datasheet:
|
// From datasheet:
|
||||||
// Don't start within 1 second of powering on
|
// - Don't start within 1 second of powering on
|
||||||
// FIXME - still doesn't actually fix the problem though
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
//vTaskDelay(pdMS_TO_TICKS(20000));
|
|
||||||
|
|
||||||
while (run_dht) {
|
while (run_dht) {
|
||||||
int ret = dht22_read();
|
int ret = dht22_read();
|
||||||
@@ -96,13 +96,13 @@ void read_from_dht22() {
|
|||||||
num_samples_last_ten_mins;
|
num_samples_last_ten_mins;
|
||||||
}
|
}
|
||||||
num_samples_last_ten_mins += 1;
|
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 should be: if (10 minutes of sample taken)
|
||||||
// This _will_ break if sampled too quickly, because we'll have more
|
// TODO: check max samples / second that can fit in 10 minutes
|
||||||
// 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 >=
|
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;
|
num_samples_last_ten_mins = 0;
|
||||||
|
|
||||||
time_t epoch;
|
time_t epoch;
|
||||||
|
|||||||
Reference in New Issue
Block a user