From 2f12e66b79b2861fa0545fb80c210f8cb4199df5 Mon Sep 17 00:00:00 2001 From: Toni Arte Date: Thu, 9 Feb 2017 12:41:15 +0200 Subject: [PATCH] Add a separate incremental energy counter into the Domoticz MQTT interface --- code/espurna/emon.ino | 6 ++++-- code/espurna/pow.ino | 6 ++++-- code/espurna/web.ino | 2 ++ code/html/index.html | 6 ++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/code/espurna/emon.ino b/code/espurna/emon.ino index 62d1abf0..20d40a28 100644 --- a/code/espurna/emon.ino +++ b/code/espurna/emon.ino @@ -158,8 +158,8 @@ void powerMonitorLoop() { snprintf(power, 6, "%d", _power); double energy_inc = (double) _power * EMON_INTERVAL * EMON_MEASUREMENTS / 1000.0 / 3600.0; - char energy_buf[10]; - dtostrf(energy_inc, 9, 2, energy_buf); + char energy_buf[11]; + dtostrf(energy_inc, 11, 3, energy_buf); char *e = energy_buf; while ((unsigned char) *e == ' ') ++e; @@ -171,6 +171,8 @@ void powerMonitorLoop() { char buffer[20]; snprintf(buffer, 20, "%s;%s", power, e); domoticzSend("dczPowIdx", 0, buffer); + snprintf(buffer, 20, "%s", e); + domoticzSend("dczEnergyIdx", 0, buffer); snprintf(buffer, 20, "%d", voltage); domoticzSend("dczVoltIdx", 0, buffer); snprintf(buffer, 20, "%s", String(current).c_str()); diff --git a/code/espurna/pow.ino b/code/espurna/pow.ino index 08dfba31..450dcecb 100644 --- a/code/espurna/pow.ino +++ b/code/espurna/pow.ino @@ -219,8 +219,8 @@ void powLoop() { if (factor > 100) factor = 100; double energy_inc = (double) power * POW_REPORT_EVERY * POW_UPDATE_INTERVAL / 1000.0 / 3600.0; - char energy_buf[10]; - dtostrf(energy_inc, 9, 2, energy_buf); + char energy_buf[11]; + dtostrf(energy_inc, 11, 3, energy_buf); char *e = energy_buf; while ((unsigned char) *e == ' ') ++e; @@ -237,6 +237,8 @@ void powLoop() { char buffer[20]; snprintf(buffer, 20, "%d;%s", power, e); domoticzSend("dczPowIdx", 0, buffer); + snprintf(buffer, 20, "%s", e); + domoticzSend("dczEnergyIdx", 0, buffer); snprintf(buffer, 20, "%d", voltage); domoticzSend("dczVoltIdx", 0, buffer); snprintf(buffer, 20, "%s", String(current).c_str()); diff --git a/code/espurna/web.ino b/code/espurna/web.ino index 1f647524..3dafb0b1 100644 --- a/code/espurna/web.ino +++ b/code/espurna/web.ino @@ -350,12 +350,14 @@ void _wsStart(uint32_t client_id) { #if ENABLE_EMON root["dczPowIdx"] = getSetting("dczPowIdx").toInt(); + root["dczEnergyIdx"] = getSetting("dczEnergyIdx").toInt(); root["dczVoltIdx"] = getSetting("dczVoltIdx").toInt(); root["dczCurrentIdx"] = getSetting("dczCurrentIdx").toInt(); #endif #if ENABLE_POW root["dczPowIdx"] = getSetting("dczPowIdx").toInt(); + root["dczEnergyIdx"] = getSetting("dczEnergyIdx").toInt(); root["dczVoltIdx"] = getSetting("dczVoltIdx").toInt(); root["dczCurrentIdx"] = getSetting("dczCurrentIdx").toInt(); #endif diff --git a/code/html/index.html b/code/html/index.html index b0206acb..f0c0eab1 100644 --- a/code/html/index.html +++ b/code/html/index.html @@ -409,6 +409,12 @@
Set to 0 to disable notifications.
+
+ +
+
Set to 0 to disable notifications.
+
+