diff --git a/src/NodeHeizung.h b/src/NodeHeizung.h index 7d8840c..3ea35ad 100644 --- a/src/NodeHeizung.h +++ b/src/NodeHeizung.h @@ -9,6 +9,10 @@ class NodeHeizung final : public Node { + const unsigned long MAX_AGE_SECONDS = 10; + + const unsigned long OVERDUE_SECONDS = 60; + DHT22 keller; Max6675Sensor abgas; @@ -37,19 +41,19 @@ class NodeHeizung final : public Node { public: - NodeHeizung() : keller(13, "keller", 0.5, 2, 0.5, 60), - abgas(27, 26, 25, "heizung/abgas", 2, 60), + NodeHeizung() : keller(13, "keller", 0.5, 2, 0.5, MAX_AGE_SECONDS, OVERDUE_SECONDS), + abgas(27, 26, 25, "heizung/abgas", 2, MAX_AGE_SECONDS, OVERDUE_SECONDS), dallas(14), - pufferVorlauf(dallas, 0xAA0121125E4A7528, "heizung/puffer/vorlauf", 1.0, 60), - pufferRuecklauf(dallas, 0x3E0121126A163B28, "heizung/puffer/ruecklauf", 1.0, 60), - pufferEingang(dallas, 0x0201211240EE3128, "heizung/puffer/eingang", 1.0, 60), - pufferSpeicher(dallas, 0x1001211233D3A428, "heizung/puffer/speicher", 1.0, 60), - pufferAusgang(dallas, 0xE80121126FFD9328, "heizung/puffer/ausgang", 1.0, 60), - pufferZirkulation(dallas, 0x540121124A48FD28, "heizung/puffer/zirkulation", 1.0, 60), - heizkreisVorlauf(dallas, 0x330121126F984728, "heizung/heizkreis/vorlauf", 1.0, 60), - heizkreisRuecklauf(dallas, 0x4201211270337B28, "heizung/heizkreis/ruecklauf", 1.0, 60), - abwasser(dallas, 0x810121126EE53828, "abwasser", 1.0, 60), - reserve(dallas, 0x0D0121126716CF28, "__RESERVE__", 1.0, 60) { + pufferVorlauf(dallas, 0xAA0121125E4A7528, "heizung/puffer/vorlauf", 1.0, MAX_AGE_SECONDS, OVERDUE_SECONDS), + pufferRuecklauf(dallas, 0x3E0121126A163B28, "heizung/puffer/ruecklauf", 1.0, MAX_AGE_SECONDS, OVERDUE_SECONDS), + pufferEingang(dallas, 0x0201211240EE3128, "heizung/puffer/eingang", 1.0, MAX_AGE_SECONDS, OVERDUE_SECONDS), + pufferSpeicher(dallas, 0x1001211233D3A428, "heizung/puffer/speicher", 1.0, MAX_AGE_SECONDS, OVERDUE_SECONDS), + pufferAusgang(dallas, 0xE80121126FFD9328, "heizung/puffer/ausgang", 1.0, MAX_AGE_SECONDS, OVERDUE_SECONDS), + pufferZirkulation(dallas, 0x540121124A48FD28, "heizung/puffer/zirkulation", 1.0, MAX_AGE_SECONDS, OVERDUE_SECONDS), + heizkreisVorlauf(dallas, 0x330121126F984728, "heizung/heizkreis/vorlauf", 1.0, MAX_AGE_SECONDS, OVERDUE_SECONDS), + heizkreisRuecklauf(dallas, 0x4201211270337B28, "heizung/heizkreis/ruecklauf", 1.0, MAX_AGE_SECONDS, OVERDUE_SECONDS), + abwasser(dallas, 0x810121126EE53828, "abwasser", 1.0, MAX_AGE_SECONDS, OVERDUE_SECONDS), + reserve(dallas, 0x0D0121126716CF28, "__RESERVE__", 1.0, MAX_AGE_SECONDS, OVERDUE_SECONDS) { // }; diff --git a/src/NodeTest.h b/src/NodeTest.h index d379a66..75795ec 100644 --- a/src/NodeTest.h +++ b/src/NodeTest.h @@ -10,6 +10,10 @@ class NodeTest final : public Node { + const unsigned long MAX_AGE_SECONDS = 10; + + const unsigned long OVERDUE_SECONDS = 60; + Dallas dallas; DallasSensor test; @@ -19,8 +23,8 @@ class NodeTest final : public Node { public: NodeTest() : dallas(27), - test(dallas, 0xC90417C1C5C0FF28, "test/ds18b20", 1.0, 60), - testraum(26, "test/dht22", 0.5, 2, 1, 605) { + test(dallas, 0xC90417C1C5C0FF28, "test/ds18b20", 1.0, MAX_AGE_SECONDS, OVERDUE_SECONDS), + testraum(26, "test/dht22", 0.5, 2, 1, MAX_AGE_SECONDS, OVERDUE_SECONDS) { // }; diff --git a/src/patrix/sensor/DHT22.h b/src/patrix/sensor/DHT22.h index 71862e5..567cf78 100644 --- a/src/patrix/sensor/DHT22.h +++ b/src/patrix/sensor/DHT22.h @@ -22,12 +22,13 @@ public: const double temperatureThreshold, const double humidityRelativeThreshold, const double humidityAbsoluteThreshold, - const unsigned long dueSeconds + const unsigned long maxAgeSeconds, + const unsigned long overdueSeconds ) : Sensor(name), sensor(pin, DHT_TYPE_22), - temperature("temperature", temperatureThreshold, dueSeconds), - humidityRelative("humidityRelative", humidityRelativeThreshold, dueSeconds), - humidityAbsolute("humidityAbsolute", humidityAbsoluteThreshold, dueSeconds) { + temperature(name, "temperature", temperatureThreshold, maxAgeSeconds, overdueSeconds), + humidityRelative(name, "humidityRelative", humidityRelativeThreshold, maxAgeSeconds, overdueSeconds), + humidityAbsolute(name, "humidityAbsolute", humidityAbsoluteThreshold, maxAgeSeconds, overdueSeconds) { // } @@ -48,7 +49,7 @@ public: json[name][humidityAbsolute.getName()] = humidityAbsolute.getCurrentValue(); } - bool isDue() const override { + bool isDue() override { return temperature.isDue() || humidityRelative.isDue() || humidityAbsolute.isDue(); } diff --git a/src/patrix/sensor/Dallas.h b/src/patrix/sensor/Dallas.h index 869f3bd..766a0d9 100644 --- a/src/patrix/sensor/Dallas.h +++ b/src/patrix/sensor/Dallas.h @@ -5,7 +5,7 @@ #include "OneWire.h" #include "DallasTemperature.h" -#define DALLAS_TIMEOUT_MILLISECONDS 3000 +#define DALLAS_INTERVAL_MILLISECONDS 2000 class Dallas { @@ -29,7 +29,7 @@ public: } void loop() { - if (lastMillis == 0 || millis() - lastMillis > DALLAS_TIMEOUT_MILLISECONDS) { + if (lastMillis == 0 || millis() - lastMillis > DALLAS_INTERVAL_MILLISECONDS) { if (converting) { error("Dallas timeout!"); } diff --git a/src/patrix/sensor/DallasSensor.h b/src/patrix/sensor/DallasSensor.h index d0fc9cd..11d5149 100644 --- a/src/patrix/sensor/DallasSensor.h +++ b/src/patrix/sensor/DallasSensor.h @@ -21,11 +21,12 @@ public: const uint64_t address, const char *name, const double threshold, - const unsigned long dueSeconds + const unsigned long maxAgeSeconds, + const unsigned long overdueSeconds ) : Sensor(name), sensors(sensors), address(address), - temperature("temperature", threshold, dueSeconds) { + temperature(name, "temperature", threshold, maxAgeSeconds, overdueSeconds) { // } @@ -40,7 +41,7 @@ public: json[name][temperature.getName()] = temperature.getCurrentValue(); } - bool isDue() const override { + bool isDue() override { return temperature.isDue(); } diff --git a/src/patrix/sensor/Max6675Sensor.h b/src/patrix/sensor/Max6675Sensor.h index 9fe7628..cb0c079 100644 --- a/src/patrix/sensor/Max6675Sensor.h +++ b/src/patrix/sensor/Max6675Sensor.h @@ -22,10 +22,11 @@ public: const int8_t pinCLK, const char *name, const double threshold, - const unsigned long dueSeconds + const unsigned long maxAgeSeconds, + const unsigned long overdueSeconds ) : Sensor(name), sensor(pinCLK, pinCS, pinMISO), - temperature("temperature", threshold, dueSeconds) { + temperature(name, "temperature", threshold, maxAgeSeconds, overdueSeconds) { // } @@ -39,7 +40,7 @@ public: json[name][temperature.getName()] = temperature.getCurrentValue(); } - bool isDue() const override { + bool isDue() override { return temperature.isDue(); } diff --git a/src/patrix/sensor/Sensor.h b/src/patrix/sensor/Sensor.h index 0cd5010..b04e20b 100644 --- a/src/patrix/sensor/Sensor.h +++ b/src/patrix/sensor/Sensor.h @@ -21,7 +21,7 @@ public: virtual void toJson(JsonDocument& json) = 0; - virtual bool isDue() const = 0; + virtual bool isDue() = 0; virtual void markSent() = 0; diff --git a/src/patrix/sensor/Value.h b/src/patrix/sensor/Value.h index 096e914..f164a10 100644 --- a/src/patrix/sensor/Value.h +++ b/src/patrix/sensor/Value.h @@ -1,49 +1,62 @@ #ifndef VALUE_H #define VALUE_H +#include class Value { + const char *parent; + const char *name; double threshold; - unsigned long dueSeconds; + unsigned long maxAgeMillis; + + unsigned long overdueSeconds; double currentValue = NAN; - unsigned long currentInterval = 0; + unsigned long currentMillis = 0; double sentValue = NAN; - unsigned long sentInterval = 0; + time_t sentInterval = 0; public: Value( + const char *parent, const char *name, const double threshold, - const unsigned long dueSeconds - ) : name(name), + const unsigned long maxAgeSeconds, + const unsigned long overdueSeconds + ) : parent(parent), + name(name), threshold(threshold), - dueSeconds(dueSeconds) { + maxAgeMillis(maxAgeSeconds * 1000), + overdueSeconds(overdueSeconds) { // } void update(const double value) { currentValue = value; - currentInterval = time(nullptr) / dueSeconds; + currentMillis = millis(); } - bool isDue() const { + bool isDue() { + if (!isnan(currentValue) && millis() - currentMillis > maxAgeMillis) { + warn("Value too old: %s/%s", parent, name); + update(NAN); + } const auto dueToNAN = isnan(currentValue) != isnan(sentValue); const auto dueToThreshold = abs(sentValue - currentValue) >= threshold; - const auto dueToTime = currentInterval != sentInterval; + const auto dueToTime = sentInterval != time(nullptr) / overdueSeconds; return dueToNAN || dueToThreshold || dueToTime; } void markSent() { sentValue = currentValue; - sentInterval = currentInterval; + sentInterval = time(nullptr) / overdueSeconds; } const char *getName() const {