From 378dbbcc99eff98815bf9b95883b6565bebc7c3f Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Wed, 29 Jan 2020 20:38:53 +0100 Subject: [PATCH] Only show phases with power, and always deliver volts and amps to frontend --- src/AmsWebServer.cpp | 36 ++++++++++++++++++++++++++---------- src/index_html.h | 6 +++--- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/AmsWebServer.cpp b/src/AmsWebServer.cpp index c03d75b3..36abe811 100644 --- a/src/AmsWebServer.cpp +++ b/src/AmsWebServer.cpp @@ -52,11 +52,7 @@ void AmsWebServer::loop() { } void AmsWebServer::setJson(StaticJsonDocument<500> json) { - this->json = json; - if(!json.isNull()) { - println(" json has data"); - p = json["data"]["P"].as(); if(json["data"].containsKey("U1")) { u1 = json["data"]["U1"].as(); @@ -75,7 +71,21 @@ void AmsWebServer::setJson(StaticJsonDocument<500> json) { } } } + } else { + if(u1 > 0) { + json["data"]["U1"] = u1; + json["data"]["I1"] = i1; + } + if(u2 > 0) { + json["data"]["U2"] = u2; + json["data"]["I2"] = i2; + } + if(u3 > 0) { + json["data"]["U3"] = u3; + json["data"]["I3"] = i3; + } } + this->json = json; } } @@ -116,12 +126,18 @@ void AmsWebServer::indexHtml() { String html = String((const __FlashStringHelper*) INDEX_HTML); html.replace("${version}", VERSION); html.replace("${data.P}", String(p)); - html.replace("${data.U1}", String(u1, 1)); - html.replace("${data.U2}", String(u2, 1)); - html.replace("${data.U3}", String(u3, 1)); - html.replace("${data.I1}", String(i1, 1)); - html.replace("${data.I2}", String(i2, 1)); - html.replace("${data.I3}", String(i3, 1)); + + html.replace("${data.U1}", u1 > 0 ? String(u1, 1) : ""); + html.replace("${data.I1}", u1 > 0 ? String(i1, 1) : ""); + html.replace("${display.P1}", u1 > 0 ? "" : "none"); + + html.replace("${data.U2}", u2 > 0 ? String(u2, 1) : ""); + html.replace("${data.I2}", u2 > 0 ? String(i2, 1) : ""); + html.replace("${display.P2}", u2 > 0 ? "" : "none"); + + html.replace("${data.U3}", u3 > 0 ? String(u3, 1) : ""); + html.replace("${data.I3}", u3 > 0 ? String(i3, 1) : ""); + html.replace("${display.P3}", u3 > 0 ? "" : "none"); server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); server.sendHeader("Pragma", "no-cache"); diff --git a/src/index_html.h b/src/index_html.h index 4cce682b..3fbeb677 100644 --- a/src/index_html.h +++ b/src/index_html.h @@ -45,17 +45,17 @@ const char INDEX_HTML[] PROGMEM = R"=="==(
-
+
P1
${data.U1} V
${data.I1} A
-
+
P2
${data.U2} V
${data.I2} A
-
+
P3
${data.U3} V
${data.I3} A