From c28087ec86dba0833c310d349e757d652a3c82a9 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Thu, 7 Jul 2022 19:05:50 +0200 Subject: [PATCH] Fix #21: Display DC power in Live Data overview --- include/WebApi_ws_live.h | 2 +- src/WebApi_ws_live.cpp | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/WebApi_ws_live.h b/include/WebApi_ws_live.h index 0f57bd9..6ce210b 100644 --- a/include/WebApi_ws_live.h +++ b/include/WebApi_ws_live.h @@ -11,7 +11,7 @@ public: private: AsyncWebSocket* _ws; - void addField(JsonDocument& root, uint8_t idx, std::shared_ptr inv, uint8_t channel, uint8_t fieldId); + void addField(JsonDocument& root, uint8_t idx, std::shared_ptr inv, uint8_t channel, uint8_t fieldId, String topic = ""); uint32_t _lastWsPublish = 0; uint32_t _lastInvUpdateCheck = 0; diff --git a/src/WebApi_ws_live.cpp b/src/WebApi_ws_live.cpp index 8d9fc6e..1756a5f 100644 --- a/src/WebApi_ws_live.cpp +++ b/src/WebApi_ws_live.cpp @@ -50,7 +50,11 @@ void WebApiWsLiveClass::loop() for (uint8_t c = 0; c <= inv->getChannelCount(); c++) { addField(root, i, inv, c, FLD_UDC); addField(root, i, inv, c, FLD_IDC); - addField(root, i, inv, c, FLD_PDC); + if (c == 0) { + addField(root, i, inv, c, FLD_PDC, F("Power DC")); + } else { + addField(root, i, inv, c, FLD_PDC); + } addField(root, i, inv, c, FLD_YD); addField(root, i, inv, c, FLD_YT); addField(root, i, inv, c, FLD_UAC); @@ -79,10 +83,16 @@ void WebApiWsLiveClass::loop() } } -void WebApiWsLiveClass::addField(JsonDocument& root, uint8_t idx, std::shared_ptr inv, uint8_t channel, uint8_t fieldId) +void WebApiWsLiveClass::addField(JsonDocument& root, uint8_t idx, std::shared_ptr inv, uint8_t channel, uint8_t fieldId, String topic) { if (inv->hasChannelFieldValue(channel, fieldId)) { - root[idx][String(channel)][inv->getChannelFieldName(channel, fieldId)]["v"] = inv->getChannelFieldValue(channel, fieldId); - root[idx][String(channel)][inv->getChannelFieldName(channel, fieldId)]["u"] = inv->getChannelFieldUnit(channel, fieldId); + String chanName; + if (topic == "") { + chanName = inv->getChannelFieldName(channel, fieldId); + } else { + chanName = topic; + } + root[idx][String(channel)][chanName]["v"] = inv->getChannelFieldValue(channel, fieldId); + root[idx][String(channel)][chanName]["u"] = inv->getChannelFieldUnit(channel, fieldId); } } \ No newline at end of file