Add timeout handling for RG15 (#22768)

This commit is contained in:
Theo Arends 2025-01-06 16:14:47 +01:00
parent b472e821cf
commit fe2f4d031f
29 changed files with 224 additions and 11 deletions

View File

@ -215,6 +215,7 @@
#define D_JSON_UV_INDEX_TEXT "UvIndexText"
#define D_JSON_UV_LEVEL "UvLevel"
#define D_JSON_UV_POWER "UvPower"
#define D_JSON_VALID "Valid"
#define D_JSON_VCC "Vcc"
#define D_JSON_VERSION "Version"
#define D_JSON_VOLTAGE "Voltage"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Wagwoord geverifieer" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Fout" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Password verified" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Грешка" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Дебитомер"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Количество днес"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Mot de pas verificat" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Error" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Cabal"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Password verified" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Error" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Übereinstimmung" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Fehler" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Durchflussmesser"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Menge heute"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Password verified" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Error" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Password verified" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Error" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Clave Correcta" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Error" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1217,6 +1217,13 @@
#define D_FP_PASSVERIFY "Mot-de-passe vérifié" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Erreur" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Débit"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Quantité aujourd'hui"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Password verified" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Error" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Password verified" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Error" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1223,6 +1223,13 @@
#define D_FP_PASSVERIFY "Jelszó ellenőrizve" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Hiba" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Password verificata" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Errore" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Portata"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Valore odierno"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Password verified" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Error" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Wachtwoord herkend" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Fout" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Zweryfikowano poprawnie" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Błąd" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Przepływ"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Wartość dzisiaj"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Senha verificada" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Erro" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Palavra-passe verificada" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Erro" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Quantidade Hoje"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Password verified" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Error" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1217,6 +1217,13 @@
#define D_FP_PASSVERIFY "Password verified" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Error" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Password verified" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Error" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Password verified" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Error" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Password verified" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Error" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Password verified" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Error" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Password verified" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Error" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Password verified" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Error" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -1216,6 +1216,13 @@
#define D_FP_PASSVERIFY "Password verified" // 0x21 Verify the fingerprint passed
#define D_FP_UNKNOWNERROR "Error" // Any other error
// xsns_90_hrg15.ino
#define D_HRG_VALID "Valid"
#define D_HRG_ACTIVE "Active"
#define D_HRG_EVENT "Event"
#define D_HRG_TOTAL "Total"
#define D_HRG_FLOWRATE "Flow Rate"
// xsns_96_flowratemeter.ino
#define D_FLOWRATEMETER_NAME "Flowrate"
#define D_FLOWRATEMETER_AMOUNT_TODAY "Amount Today"

View File

@ -36,16 +36,18 @@
#define RG15_READ_TIMEOUT 500
#define RG15_EVENT_TIMEOUT 60
#define RG15_BUFFER_SIZE 150
#define RG15_RCV_TIMEOUT 70 // Receiver timeout in seconds
#include <TasmotaSerial.h>
#ifdef USE_WEBSERVER
const char HTTP_RG15[] PROGMEM =
// {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
"{s}" RG15_NAME " " D_JSON_ACTIVE "{m}%2_f " D_UNIT_MILLIMETER "{e}"
"{s}" RG15_NAME " " D_JSON_EVENT "{m}%2_f " D_UNIT_MILLIMETER "{e}"
"{s}" RG15_NAME " " D_JSON_TOTAL "{m}%2_f " D_UNIT_MILLIMETER "{e}"
"{s}" RG15_NAME " " D_JSON_FLOWRATE "{m}%2_f " D_UNIT_MILLIMETER "/" D_UNIT_HOUR "{e}";
"{s}" RG15_NAME " " D_HRG_VALID "{m}%d{e}"
"{s}" RG15_NAME " " D_HRG_ACTIVE "{m}%2_f " D_UNIT_MILLIMETER "{e}"
"{s}" RG15_NAME " " D_HRG_EVENT "{m}%2_f " D_UNIT_MILLIMETER "{e}"
"{s}" RG15_NAME " " D_HRG_TOTAL "{m}%2_f " D_UNIT_MILLIMETER "{e}"
"{s}" RG15_NAME " " D_HRG_FLOWRATE "{m}%2_f " D_UNIT_MILLIMETER "/" D_UNIT_HOUR "{e}";
#endif // USE_WEBSERVER
TasmotaSerial *HydreonSerial = nullptr;
@ -55,8 +57,10 @@ struct RG15 {
float event = NAN;
float total = NAN;
float rate = NAN;
uint32_t data_received = 0;
uint16_t time = RG15_EVENT_TIMEOUT;
uint8_t init_step;
bool sensor_valid = false;
} Rg15;
/*********************************************************************************************/
@ -163,11 +167,19 @@ void Rg15Init(void) {
AddLog(LOG_LEVEL_DEBUG, PSTR("HRG: Serial UART%d"), HydreonSerial->getUart());
#endif
Rg15.init_step = 5; // Perform RG-15 init
Rg15.data_received = TasmotaGlobal.uptime;
}
}
}
}
void Rg15SensorValidChanged(bool new_status) {
AddLog(LOG_LEVEL_DEBUG, PSTR("HRG: Valid changed %d"), new_status);
Rg15.sensor_valid = new_status;
// todo trigger teleperiod or publish status
}
void Rg15Poll(void) {
bool publish = false;
@ -187,10 +199,20 @@ void Rg15Poll(void) {
Rg15ReadLine(rg15_buffer);
if (Rg15Process(rg15_buffer)) { // Do NOT use "publish = Rg15Process(rg15_buffer)"
publish = true;
Rg15.data_received = TasmotaGlobal.uptime;
if (!Rg15.sensor_valid) {
Rg15SensorValidChanged(true); // Reset timeout
}
}
}
}
if ((TasmotaGlobal.uptime - Rg15.data_received) > RG15_RCV_TIMEOUT) {
if (Rg15.sensor_valid) {
Rg15SensorValidChanged(false); // Timeout
}
}
if (publish && !TasmotaGlobal.global_state.mqtt_down) {
MqttPublishSensor();
}
@ -214,17 +236,17 @@ void Rg15Poll(void) {
void Rg15Show(bool json) {
if (json) {
// if the parsing wasn't completely successful then skip the update
if( !isnan(Rg15.acc) && !isnan(Rg15.event) && !isnan(Rg15.total) && !isnan(Rg15.rate) ) {
if (Rg15.sensor_valid && !isnan(Rg15.acc) && !isnan(Rg15.event) && !isnan(Rg15.total) && !isnan(Rg15.rate)) {
ResponseAppend_P(PSTR(",\"" RG15_NAME "\":{"));
ResponseAppend_P(PSTR("\"%s\":%2_f,"), D_JSON_ACTIVE, &Rg15.acc);
ResponseAppend_P(PSTR("\"%s\":%2_f,"), D_JSON_EVENT, &Rg15.event);
ResponseAppend_P(PSTR("\"%s\":%2_f,"), D_JSON_TOTAL, &Rg15.total);
ResponseAppend_P(PSTR("\"%s\":%2_f"), D_JSON_FLOWRATE, &Rg15.rate);
ResponseAppend_P(PSTR("\"" D_JSON_ACTIVE "\":%2_f,"), &Rg15.acc);
ResponseAppend_P(PSTR("\"" D_JSON_EVENT "\":%2_f,"), &Rg15.event);
ResponseAppend_P(PSTR("\"" D_JSON_TOTAL "\":%2_f,"), &Rg15.total);
ResponseAppend_P(PSTR("\"" D_JSON_FLOWRATE "\":%2_f"), &Rg15.rate);
ResponseAppend_P(PSTR("}"));
}
#ifdef USE_WEBSERVER
} else {
WSContentSend_PD(HTTP_RG15, &Rg15.acc, &Rg15.event, &Rg15.total, &Rg15.rate);
WSContentSend_PD(HTTP_RG15, Rg15.sensor_valid, &Rg15.acc, &Rg15.event, &Rg15.total, &Rg15.rate);
#endif // USE_WEBSERVER
}
}
@ -264,7 +286,8 @@ bool Xsns90(uint32_t function) {
else if (HydreonSerial) {
switch (function) {
case FUNC_EVERY_SECOND:
if((TasmotaGlobal.uptime % 60) == 0) { // every minute
if ((TasmotaGlobal.uptime % 60) == 0) { // every minute
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("HRG: Valid %d"), Rg15.sensor_valid);
ExecuteCommand("Sensor90 R", SRC_SENSOR);
}
Rg15Poll();