From e929f87ea9539dba371d0f2fc44d5a358838994c Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Sat, 23 Oct 2021 10:38:53 +0200 Subject: [PATCH] Fixed decimals in json --- src/mqtt/DomoticzMqttHandler.cpp | 72 ++++++++++++++------------------ src/web/AmsWebServer.cpp | 2 +- web/data.json | 10 ++--- web/json3.json | 8 ++-- 4 files changed, 42 insertions(+), 50 deletions(-) diff --git a/src/mqtt/DomoticzMqttHandler.cpp b/src/mqtt/DomoticzMqttHandler.cpp index 288a105b..262b2d92 100644 --- a/src/mqtt/DomoticzMqttHandler.cpp +++ b/src/mqtt/DomoticzMqttHandler.cpp @@ -23,55 +23,47 @@ bool DomoticzMqttHandler::publish(AmsData* data, AmsData* previousState) { return ret; if (config.vl1idx > 0){ - if (data->getL1Voltage() > 0.1){ - char val[16]; - snprintf(val, 16, "%.2f", data->getL1Voltage()); - char json[192]; - snprintf_P(json, sizeof(json), DOMOTICZ_JSON, - config.vl1idx, - val - ); - ret |= mqtt->publish("domoticz/in", json); - } + char val[16]; + snprintf(val, 16, "%.2f", data->getL1Voltage()); + char json[192]; + snprintf_P(json, sizeof(json), DOMOTICZ_JSON, + config.vl1idx, + val + ); + ret |= mqtt->publish("domoticz/in", json); } if (config.vl2idx > 0){ - if (data->getL2Voltage() > 0.1){ - char val[16]; - snprintf(val, 16, "%.2f", data->getL2Voltage()); - char json[192]; - snprintf_P(json, sizeof(json), DOMOTICZ_JSON, - config.vl2idx, - val - ); - ret |= mqtt->publish("domoticz/in", json); - } + char val[16]; + snprintf(val, 16, "%.2f", data->getL2Voltage()); + char json[192]; + snprintf_P(json, sizeof(json), DOMOTICZ_JSON, + config.vl2idx, + val + ); + ret |= mqtt->publish("domoticz/in", json); } if (config.vl3idx > 0){ - if (data->getL3Voltage() > 0.1){ - char val[16]; - snprintf(val, 16, "%.2f", data->getL3Voltage()); - char json[192]; - snprintf_P(json, sizeof(json), DOMOTICZ_JSON, - config.vl3idx, - val - ); - ret |= mqtt->publish("domoticz/in", json); - } + char val[16]; + snprintf(val, 16, "%.2f", data->getL3Voltage()); + char json[192]; + snprintf_P(json, sizeof(json), DOMOTICZ_JSON, + config.vl3idx, + val + ); + ret |= mqtt->publish("domoticz/in", json); } if (config.cl1idx > 0){ - if(data->getL1Current() > 0.0) { - char val[16]; - snprintf(val, 16, "%.1f;%.1f;%.1f", data->getL1Current(), data->getL2Current(), data->getL3Current()); - char json[192]; - snprintf_P(json, sizeof(json), DOMOTICZ_JSON, - config.cl1idx, - val - ); - ret |= mqtt->publish("domoticz/in", json); - } + char val[16]; + snprintf(val, 16, "%.1f;%.1f;%.1f", data->getL1Current(), data->getL2Current(), data->getL3Current()); + char json[192]; + snprintf_P(json, sizeof(json), DOMOTICZ_JSON, + config.cl1idx, + val + ); + ret |= mqtt->publish("domoticz/in", json); } return ret; } diff --git a/src/web/AmsWebServer.cpp b/src/web/AmsWebServer.cpp index 7a89719f..eb0418bc 100644 --- a/src/web/AmsWebServer.cpp +++ b/src/web/AmsWebServer.cpp @@ -695,7 +695,7 @@ void AmsWebServer::dataJson() { mqttStatus = 3; } - char json[284]; + char json[290]; snprintf_P(json, sizeof(json), DATA_JSON, maxPwr == 0 ? meterState->isThreePhase() ? 20000 : 10000 : maxPwr, meterConfig->productionCapacity, diff --git a/web/data.json b/web/data.json index 1b8e266f..8322d217 100644 --- a/web/data.json +++ b/web/data.json @@ -6,10 +6,10 @@ "e" : %d, "ri" : %d, "re" : %d, - "ic" : %.1f, - "ec" : %.1f, - "ric" : %.1f, - "rec" : %.1f, + "ic" : %.2f, + "ec" : %.2f, + "ric" : %.2f, + "rec" : %.2f, "u1" : %.2f, "u2" : %.2f, "u3" : %.2f, @@ -18,7 +18,7 @@ "i3" : %.2f, "v" : %.3f, "r" : %d, - "t" : %.1f, + "t" : %.2f, "u" : %lu, "m" : %lu, "em" : %d, diff --git a/web/json3.json b/web/json3.json index 2f23e9ba..6edc56fe 100644 --- a/web/json3.json +++ b/web/json3.json @@ -20,10 +20,10 @@ "U1" : %.2f, "U2" : %.2f, "U3" : %.2f, - "tPI" : %.1f, - "tPO" : %.1f, - "tQI" : %.1f, - "tQO" : %.1f, + "tPI" : %.2f, + "tPO" : %.2f, + "tQI" : %.2f, + "tQO" : %.2f, "rtc" : %lu } }