From 3d5aa52e477ef4f8ccdc0a57b2d0f3c0d194bc3b Mon Sep 17 00:00:00 2001 From: Florian <1technophile@users.noreply.github.com> Date: Thu, 4 Jan 2024 11:30:32 -0600 Subject: [PATCH 1/2] [RN8209] Detect voltage changes Voltage changes > 2V will trigger a data sending --- main/ZsensorRN8209.ino | 10 +++++++--- main/config_RN8209.h | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/main/ZsensorRN8209.ino b/main/ZsensorRN8209.ino index f881cf3026..d0fced60fe 100644 --- a/main/ZsensorRN8209.ino +++ b/main/ZsensorRN8209.ino @@ -49,6 +49,7 @@ void rn8209_loop(void* mode) { uint8_t retc = 1; uint8_t retp = 1; static float previousCurrent = 0; + static float previousVoltage = 0; if (ret) { uint32_t temp_current = 0; retc = rn8209c_read_current(phase_A, &temp_current); @@ -61,21 +62,25 @@ void rn8209_loop(void* mode) { current = current / 10000.0; overLimitCurrent(current); } + if (retv == 0) { + voltage = (float)temp_voltage / 1000.0; + } } unsigned long now = millis(); if ((now > (PublishingTimerRN8209 + TimeBetweenPublishingRN8209) || !PublishingTimerRN8209 || - (abs(current - previousCurrent) > MinCurrentThreshold)) && + (abs(current - previousCurrent) > MinCurrentThreshold) || (abs(voltage - previousVoltage) > MinVoltageThreshold)) && !ProcessLock) { StaticJsonDocument RN8209dataBuffer; JsonObject RN8209data = RN8209dataBuffer.to(); if (retc == 0) { + previousCurrent = current; RN8209data["current"] = round2(current); } uint32_t temp_power = 0; retp = rn8209c_read_power(phase_A, &temp_power); if (retv == 0) { - voltage = (float)temp_voltage / 1000.0; + previousVoltage = voltage; RN8209data["volt"] = round2(voltage); } if (ret == 1) { @@ -88,7 +93,6 @@ void rn8209_loop(void* mode) { RN8209data["power"] = round2(power); } PublishingTimerRN8209 = now; - previousCurrent = current; if (RN8209data) { RN8209data["origin"] = subjectRN8209toMQTT; handleJsonEnqueue(RN8209data, QueueSemaphoreTimeOutTask); diff --git a/main/config_RN8209.h b/main/config_RN8209.h index 74083d4039..744ce3942a 100644 --- a/main/config_RN8209.h +++ b/main/config_RN8209.h @@ -53,4 +53,7 @@ extern void RN8209toMQTT(); #ifndef MinCurrentThreshold # define MinCurrentThreshold 0.1 // (A) Minimum current change that will trigger the publishing of the RN8209 measurements #endif +#ifndef MinVoltageThreshold +# define MinVoltageThreshold 2 // (V) Minimum voltage change that will trigger the publishing of the RN8209 measurements +#endif #endif From ccce77f16289cbbc899d1b791d9d818a2a59e764 Mon Sep 17 00:00:00 2001 From: Florian <1technophile@users.noreply.github.com> Date: Fri, 5 Jan 2024 08:16:22 -0600 Subject: [PATCH 2/2] Add documentation --- docs/use/sensors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/use/sensors.md b/docs/use/sensors.md index abee7a524a..b94c2c20cf 100644 --- a/docs/use/sensors.md +++ b/docs/use/sensors.md @@ -52,7 +52,7 @@ This notification pin can be inverted if driving directly or through a transisto `#define INVERT_LED_NOTIFY true` ### RN8209 -You will receive every `TimeBetweenPublishingRN8209` (set into config_RN8209.h) the RN8209 measurements (every 60s per default), or if the difference between the previous current reading and the new reading is more than 0.1A. +You will receive every `TimeBetweenPublishingRN8209` (set into config_RN8209.h) the RN8209 measurements (every 60s per default), or if the difference between the previous current reading and the new reading is more than 0.1A, or if the difference between the previous voltage reading and the new reading is more than 2V. One reading is done every 0.5s. `home/OpenMQTTGateway/RN8209toMQTT {"volt":120.34,"current":7.92,"power":954.61}`