Only get and convert time when using it

This commit is contained in:
2023-10-28 17:33:49 +01:00
parent 5c6a89df87
commit 556e0786da

View File

@@ -81,18 +81,6 @@ void read_from_dht22() {
// if/when we've got an actual time to do that with. I think that'd
// avoid some weird bugs (time changing from 1970 -> current time within
// a 10 min period)
time_t epoch;
time(&epoch);
struct tm *timeinfo = localtime(&epoch);
// There must be a better way - I couldn't figure out how to do it
// nicely all at once
latest_datapoint.time.myt_sec = timeinfo->tm_sec;
latest_datapoint.time.myt_min = timeinfo->tm_min;
latest_datapoint.time.myt_hour = timeinfo->tm_hour;
latest_datapoint.time.myt_day = timeinfo->tm_mday;
latest_datapoint.time.myt_month = timeinfo->tm_mon;
latest_datapoint.time.myt_year = timeinfo->tm_year;
if (num_samples_last_ten_mins == 0) {
ten_minute_rolling_average.rh = latest_datapoint.rh;
@@ -114,6 +102,21 @@ void read_from_dht22() {
if (num_samples_last_ten_mins >=
(CONFIG_DHT22_PERIOD_POLL * 1000 * 60 * 10)) {
num_samples_last_ten_mins = 0;
time_t epoch;
time(&epoch);
struct tm *timeinfo = localtime(&epoch);
// There must be a better way - I couldn't figure out how to do it
// nicely all at once
latest_datapoint.time.myt_sec = timeinfo->tm_sec;
// -5 to get the middle of the averaged window
latest_datapoint.time.myt_min = timeinfo->tm_min - 5;
latest_datapoint.time.myt_hour = timeinfo->tm_hour;
latest_datapoint.time.myt_day = timeinfo->tm_mday;
latest_datapoint.time.myt_month = timeinfo->tm_mon;
latest_datapoint.time.myt_year = timeinfo->tm_year;
// 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