From dd164f5236a211978fc0ea160493a5953f298eda Mon Sep 17 00:00:00 2001 From: DanielR92 Date: Tue, 14 May 2024 20:14:55 +0200 Subject: [PATCH 1/2] Shelly Topic MQTT checker - powermeter.h --- src/plugins/zeroExport/powermeter.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/plugins/zeroExport/powermeter.h b/src/plugins/zeroExport/powermeter.h index 20cbf4e1..b3736648 100644 --- a/src/plugins/zeroExport/powermeter.h +++ b/src/plugins/zeroExport/powermeter.h @@ -190,15 +190,28 @@ class powermeter { for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) { if (!mCfg->groups[group].enabled) continue; - if (!mCfg->groups[group].pm_type == zeroExportPowermeterType_t::Mqtt) continue; - if (!strcmp(mCfg->groups[group].pm_src, "")) continue; - if (strcmp(mCfg->groups[group].pm_src, String(topic).c_str())) continue; float power = 0.0; - power = (uint16_t)obj["val"]; + + //TODO: datajson 100 enough? + // this if-statement need to check if value contains a json object. + // is it so, then deserialize it and get the values (Shelly GEN2) + DynamicJsonDocument datajson(100); + if (!deserializeJson(datajson, obj["val"])) + { + switch (mCfg->groups[group].pm_target) { + case 0: power = datajson["a_act_power"]; break; + case 1: power = datajson["b_act_power"]; break; + case 2: power = datajson["c_act_power"]; break; + case 3: power = datajson["total_act_power"]; break; + } + } else { + //TODO: check if parse is possible here? Is that right? + power = (uint16_t)obj["val"]; + } bufferWrite(power, group); From 6fbe9bd636404229a3988c1aaf3820b3b382d3f1 Mon Sep 17 00:00:00 2001 From: tictrick <117273857+tictrick@users.noreply.github.com> Date: Mon, 20 May 2024 21:24:23 +0200 Subject: [PATCH 2/2] Update powermeter.h --- src/plugins/zeroExport/powermeter.h | 33 ++++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/plugins/zeroExport/powermeter.h b/src/plugins/zeroExport/powermeter.h index aed861fb..086a7f61 100644 --- a/src/plugins/zeroExport/powermeter.h +++ b/src/plugins/zeroExport/powermeter.h @@ -191,28 +191,31 @@ class powermeter { for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) { if (!mCfg->groups[group].enabled) continue; + if (!mCfg->groups[group].pm_type == zeroExportPowermeterType_t::Mqtt) continue; + if (!strcmp(mCfg->groups[group].pm_src, "")) continue; + if (strcmp(mCfg->groups[group].pm_src, String(topic).c_str())) continue; float power = 0.0; - //TODO: datajson 100 enough? - // this if-statement need to check if value contains a json object. - // is it so, then deserialize it and get the values (Shelly GEN2) - DynamicJsonDocument datajson(100); - if (!deserializeJson(datajson, obj["val"])) - { - switch (mCfg->groups[group].pm_target) { - case 0: power = datajson["a_act_power"]; break; - case 1: power = datajson["b_act_power"]; break; - case 2: power = datajson["c_act_power"]; break; - case 3: power = datajson["total_act_power"]; break; - } - } else { - //TODO: check if parse is possible here? Is that right? +// //TODO: datajson 100 enough? +// // this if-statement need to check if value contains a json object. +// // is it so, then deserialize it and get the values (Shelly GEN2) +// DynamicJsonDocument datajson(100); +// if (!deserializeJson(datajson, obj["val"])) +// { +// switch (mCfg->groups[group].pm_target) { +// case 0: power = datajson["a_act_power"]; break; +// case 1: power = datajson["b_act_power"]; break; +// case 2: power = datajson["c_act_power"]; break; +// case 3: power = datajson["total_act_power"]; break; +// } +// } else { +// //TODO: check if parse is possible here? Is that right? power = (uint16_t)obj["val"]; - } +// } bufferWrite(power, group);