Value.maxAgeSeconds
This commit is contained in:
parent
32401a6560
commit
8418821e77
@ -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) {
|
||||
//
|
||||
};
|
||||
|
||||
|
||||
@ -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) {
|
||||
//
|
||||
};
|
||||
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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!");
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ public:
|
||||
|
||||
virtual void toJson(JsonDocument& json) = 0;
|
||||
|
||||
virtual bool isDue() const = 0;
|
||||
virtual bool isDue() = 0;
|
||||
|
||||
virtual void markSent() = 0;
|
||||
|
||||
|
||||
@ -1,49 +1,62 @@
|
||||
#ifndef VALUE_H
|
||||
#define VALUE_H
|
||||
#include <patrix/log.h>
|
||||
|
||||
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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user