From c3c0ca0a1b87ae79810261d180bb04f58b26d58a Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Mon, 4 May 2020 16:07:23 +0200 Subject: [PATCH] Added option to substitute missing I2 for Aidon IT meters. Also cleaned up some more UI --- src/AmsConfiguration.cpp | 37 ++++++++---- src/AmsConfiguration.h | 35 +++++------ src/AmsData.cpp | 10 ++-- src/AmsData.h | 4 +- src/AmsToMqttBridge.ino | 17 +----- src/web/AmsWebServer.cpp | 4 +- web/configdomoticz.html | 2 +- web/configmeter.html | 105 +++++++++++++++++++-------------- web/configmqtt.html | 4 +- web/configsystem.html | 2 +- web/configweb.html | 42 +++++++------- web/configwifi.html | 121 ++++++++++++++++++++------------------- web/delete.html | 2 +- web/index.html | 2 +- web/upload.html | 8 +-- 15 files changed, 212 insertions(+), 183 deletions(-) diff --git a/src/AmsConfiguration.cpp b/src/AmsConfiguration.cpp index c9ab9877..bc913588 100644 --- a/src/AmsConfiguration.cpp +++ b/src/AmsConfiguration.cpp @@ -254,6 +254,14 @@ void AmsConfiguration::setProductionCapacity(uint8_t productionCapacity) { config.productionCapacity = productionCapacity; } +bool AmsConfiguration::isSubstituteMissing() { + return config.substituteMissing; +} + +void AmsConfiguration::setSubstituteMissing(bool substituteMissing) { + config.substituteMissing = substituteMissing; +} + bool AmsConfiguration::isDebugTelnet() { return config.debugTelnet; } @@ -278,43 +286,43 @@ void AmsConfiguration::setDebugLevel(uint8_t debugLevel) { config.debugLevel = debugLevel; } -int AmsConfiguration::getDomoELIDX() { +uint16_t AmsConfiguration::getDomoELIDX() { return config.domoELIDX; } -int AmsConfiguration::getDomoVL1IDX() { +uint16_t AmsConfiguration::getDomoVL1IDX() { return config.domoVL1IDX; } -int AmsConfiguration::getDomoVL2IDX() { +uint16_t AmsConfiguration::getDomoVL2IDX() { return config.domoVL2IDX; } -int AmsConfiguration::getDomoVL3IDX() { +uint16_t AmsConfiguration::getDomoVL3IDX() { return config.domoVL3IDX; } -int AmsConfiguration::getDomoCL1IDX() { +uint16_t AmsConfiguration::getDomoCL1IDX() { return config.domoCL1IDX; } -void AmsConfiguration::setDomoELIDX(int domoELIDX) { +void AmsConfiguration::setDomoELIDX(uint16_t domoELIDX) { domoChanged |= config.domoELIDX != domoELIDX; config.domoELIDX = domoELIDX; } -void AmsConfiguration::setDomoVL1IDX(int domoVL1IDX) { +void AmsConfiguration::setDomoVL1IDX(uint16_t domoVL1IDX) { domoChanged |= config.domoVL1IDX != domoVL1IDX; config.domoVL1IDX = domoVL1IDX; } -void AmsConfiguration::setDomoVL2IDX(int domoVL2IDX) { +void AmsConfiguration::setDomoVL2IDX(uint16_t domoVL2IDX) { domoChanged |= config.domoVL2IDX != domoVL2IDX; config.domoVL2IDX = domoVL2IDX; } -void AmsConfiguration::setDomoVL3IDX(int domoVL3IDX) { +void AmsConfiguration::setDomoVL3IDX(uint16_t domoVL3IDX) { domoChanged |= config.domoVL3IDX != domoVL3IDX; config.domoVL3IDX = domoVL3IDX; } -void AmsConfiguration::setDomoCL1IDX(int domoCL1IDX) { +void AmsConfiguration::setDomoCL1IDX(uint16_t domoCL1IDX) { domoChanged |= config.domoCL1IDX != domoCL1IDX; config.domoCL1IDX = domoCL1IDX; } @@ -450,14 +458,14 @@ void AmsConfiguration::setVccMultiplier(double vccMultiplier) { } double AmsConfiguration::getVccBootLimit() { - return config.vccBootLimit / 10; + return config.vccBootLimit / 10.0; } void AmsConfiguration::setVccBootLimit(double vccBootLimit) { if(vccBootLimit == 0.0) config.vccBootLimit = 0; else - config.vccBootLimit = max(2.5, min(vccBootLimit, 3.5)) * 10; + config.vccBootLimit = max(25, min((int)(vccBootLimit * 10), 35)); } bool AmsConfiguration::isDomoChanged() { return domoChanged; @@ -800,6 +808,7 @@ void AmsConfiguration::print(Print* debugger) debugger->printf("distSys: %i\r\n", this->getDistributionSystem()); debugger->printf("fuseSize: %i\r\n", this->getMainFuse()); debugger->printf("productionCapacity: %i\r\n", this->getProductionCapacity()); + debugger->printf("Substitute missing: %s\r\n", this->isSubstituteMissing() ? "Yes" : "No"); debugger->printf("HAN pin: %i\r\n", this->getHanPin()); debugger->printf("LED pin: %i\r\n", this->getLedPin()); @@ -811,6 +820,10 @@ void AmsConfiguration::print(Print* debugger) debugger->printf("AP pin: %i\r\n", this->getApPin()); debugger->printf("Temperature pin: %i\r\n", this->getTempSensorPin()); + debugger->printf("Vcc pin: %i\r\n", this->getVccPin()); + debugger->printf("Vcc multiplier: %f\r\n", this->getVccMultiplier()); + debugger->printf("Vcc boot limit: %f\r\n", this->getVccBootLimit()); + if(this->getDomoELIDX() > 0) { debugger->printf("Domoticz ELIDX: %i\r\n", this->getDomoELIDX()); debugger->printf("Domoticz VL1IDX: %i\r\n", this->getDomoVL1IDX()); diff --git a/src/AmsConfiguration.h b/src/AmsConfiguration.h index 65d83aa3..ff102962 100644 --- a/src/AmsConfiguration.h +++ b/src/AmsConfiguration.h @@ -28,6 +28,7 @@ struct ConfigObject { uint8_t distributionSystem; uint8_t mainFuse; uint8_t productionCapacity; + bool substituteMissing; bool debugTelnet; bool debugSerial; @@ -46,11 +47,11 @@ struct ConfigObject { uint16_t vccMultiplier; uint8_t vccBootLimit; - int domoELIDX; - int domoVL1IDX; - int domoVL2IDX; - int domoVL3IDX; - int domoCL1IDX; + uint16_t domoELIDX; + uint16_t domoVL1IDX; + uint16_t domoVL2IDX; + uint16_t domoVL3IDX; + uint16_t domoCL1IDX; }; class AmsConfiguration { @@ -122,6 +123,8 @@ public: void setMainFuse(uint8_t mainFuse); uint8_t getProductionCapacity(); void setProductionCapacity(uint8_t productionCapacity); + bool isSubstituteMissing(); + void setSubstituteMissing(bool substituteMissing); bool isDebugTelnet(); void setDebugTelnet(bool debugTelnet); @@ -161,17 +164,16 @@ public: void print(Print* debugger); - int getDomoELIDX(); - int getDomoVL1IDX(); - int getDomoVL2IDX(); - int getDomoVL3IDX(); - int getDomoCL1IDX(); - double getDomoEnergy(); - void setDomoELIDX(int domoELIDX); - void setDomoVL1IDX(int domoVL1IDX); - void setDomoVL2IDX(int domoVL2IDX); - void setDomoVL3IDX(int domoVL3IDX); - void setDomoCL1IDX(int domoCL1IDX); + uint16_t getDomoELIDX(); + uint16_t getDomoVL1IDX(); + uint16_t getDomoVL2IDX(); + uint16_t getDomoVL3IDX(); + uint16_t getDomoCL1IDX(); + void setDomoELIDX(uint16_t domoELIDX); + void setDomoVL1IDX(uint16_t domoVL1IDX); + void setDomoVL2IDX(uint16_t domoVL2IDX); + void setDomoVL3IDX(uint16_t domoVL3IDX); + void setDomoCL1IDX(uint16_t domoCL1IDX); void clearDomo(); bool isDomoChanged(); @@ -206,6 +208,7 @@ private: 0, // Distribution system 0, // Main fuse 0, // Production capacity + false, // Substitute false, // Debug telnet false, // Debug serial 5, // Debug level diff --git a/src/AmsData.cpp b/src/AmsData.cpp index 656995a9..7d6c6d47 100644 --- a/src/AmsData.cpp +++ b/src/AmsData.cpp @@ -5,7 +5,7 @@ AmsData::AmsData() {} -AmsData::AmsData(int meterType, HanReader& hanReader) { +AmsData::AmsData(int meterType, bool substituteMissing, HanReader& hanReader) { lastUpdateMillis = millis(); packageTimestamp = hanReader.getPackageTime(); @@ -15,7 +15,7 @@ AmsData::AmsData(int meterType, HanReader& hanReader) { extractFromKaifa(hanReader, listSize); break; case METER_TYPE_AIDON: - extractFromAidon(hanReader, listSize); + extractFromAidon(hanReader, listSize, substituteMissing); break; case METER_TYPE_KAMSTRUP: extractFromKamstrup(hanReader, listSize); @@ -87,7 +87,7 @@ void AmsData::extractFromKaifa(HanReader& hanReader, int listSize) { } } -void AmsData::extractFromAidon(HanReader& hanReader, int listSize) { +void AmsData::extractFromAidon(HanReader& hanReader, int listSize, bool substituteMissing) { switch(listSize) { case (int)Aidon::List1: listType = 1; @@ -168,7 +168,9 @@ void AmsData::extractFromAidon(HanReader& hanReader, int listSize) { l1voltage = ((double) hanReader.getInt( (int)Aidon_List3PhaseIT::VoltageL1)) / 10; l2voltage = ((double) hanReader.getInt( (int)Aidon_List3PhaseIT::VoltageL2)) / 10; l3voltage = ((double) hanReader.getInt( (int)Aidon_List3PhaseIT::VoltageL3)) / 10; - //l2current = ((activeImportPower * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage; + if(substituteMissing) { + l2current = ((activeImportPower * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage; + } break; } } diff --git a/src/AmsData.h b/src/AmsData.h index 89245406..1e078d8d 100644 --- a/src/AmsData.h +++ b/src/AmsData.h @@ -12,7 +12,7 @@ class AmsData { public: AmsData(); - AmsData(int meterType, HanReader& hanReader); + AmsData(int meterType, bool substituteMissing, HanReader& hanReader); void apply(AmsData& other); @@ -60,7 +60,7 @@ private: bool threePhase = false; void extractFromKaifa(HanReader& hanReader, int listSize); - void extractFromAidon(HanReader& hanReader, int listSize); + void extractFromAidon(HanReader& hanReader, int listSize, bool substituteMissing); void extractFromKamstrup(HanReader& hanReader, int listSize); }; diff --git a/src/AmsToMqttBridge.ino b/src/AmsToMqttBridge.ino index a4ed2f9a..d64ccb52 100644 --- a/src/AmsToMqttBridge.ino +++ b/src/AmsToMqttBridge.ino @@ -503,7 +503,7 @@ void readHanPort() { else hw.ledBlink(LED_INTERNAL, 1); - AmsData data(config.getMeterType(), hanReader); + AmsData data(config.getMeterType(), config.isSubstituteMissing(), hanReader); if(data.getListType() > 0) { ws.setData(data); @@ -525,20 +525,7 @@ void readHanPort() { // Start DOMOTICZ // } else if(config.getMqttPayloadFormat() == 3) { - // - // This part is also publishing standard json message for now. May be removed. - // - StaticJsonDocument<512> json; - hanToJson(json, data, hw, temperature); - if (Debug.isActive(RemoteDebug::INFO)) { - debugI("Sending data to MQTT"); - if (Debug.isActive(RemoteDebug::DEBUG)) { - serializeJsonPretty(json, Debug); - } - } - String msg; - serializeJson(json, msg); - mqtt.publish(config.getMqttPublishTopic(), msg.c_str()); // keep for now, this is identical to option 0. + debugI("Sending data to MQTT"); // // Special MQTT messages for DOMOTIZ (https://www.domoticz.com/wiki/MQTT) // -All messages should be published to topic "domoticz/in" diff --git a/src/web/AmsWebServer.cpp b/src/web/AmsWebServer.cpp index 63a9cf44..7735a342 100644 --- a/src/web/AmsWebServer.cpp +++ b/src/web/AmsWebServer.cpp @@ -211,6 +211,7 @@ void AmsWebServer::configMeterHtml() { html.replace("${config.mainFuse" + String(i) + "}", config->getMainFuse() == i ? "selected" : ""); } html.replace("${config.productionCapacity}", String(config->getProductionCapacity())); + html.replace("${config.substituteMissing}", config->isSubstituteMissing() ? "checked" : ""); server.setContentLength(html.length()); server.send(200, "text/html", html); @@ -230,7 +231,7 @@ void AmsWebServer::configWifiHtml() { html.replace("${config.wifiSsid}", config->getWifiSsid()); html.replace("${config.wifiPassword}", config->getWifiPassword()); - html.replace("${config.wifiIpType1}", strlen(config->getWifiIp()) > 0 ? "selected" : ""); + html.replace("${config.wifiStaticIp}", strlen(config->getWifiIp()) > 0 ? "checked" : ""); html.replace("${config.wifiIp}", config->getWifiIp()); html.replace("${config.wifiGw}", config->getWifiGw()); html.replace("${config.wifiSubnet}", config->getWifiSubnet()); @@ -639,6 +640,7 @@ void AmsWebServer::handleSave() { config->setDistributionSystem(server.arg("distributionSystem").toInt()); config->setMainFuse(server.arg("mainFuse").toInt()); config->setProductionCapacity(server.arg("productionCapacity").toInt()); + config->setSubstituteMissing(server.hasArg("substituteMissing") && server.arg("substituteMissing") == "true"); } if(server.hasArg("wifiConfig") && server.arg("wifiConfig") == "true") { diff --git a/web/configdomoticz.html b/web/configdomoticz.html index aae8c034..2e898819 100644 --- a/web/configdomoticz.html +++ b/web/configdomoticz.html @@ -4,7 +4,7 @@ AMS reader - WiFi configuration - +
diff --git a/web/configmeter.html b/web/configmeter.html index f8e8af8a..c545f3b0 100644 --- a/web/configmeter.html +++ b/web/configmeter.html @@ -4,7 +4,8 @@ AMS reader - Meter configuration - + +
@@ -41,52 +42,61 @@
-
-
- -
- +
+
+
+ Meter type
+
-
- -
- +
+
+
+
+ Distribution system +
+ +
+
+
+
+
+ Main fuse +
+ +
+
+
+
+
+ Production capacity +
+ +
+ kWp
-
-
- -
- -
-
-
- -
-
- -
kWp
-
-
+
+
+
@@ -102,5 +112,16 @@
+ diff --git a/web/configmqtt.html b/web/configmqtt.html index a40c690e..44732867 100644 --- a/web/configmqtt.html +++ b/web/configmqtt.html @@ -4,8 +4,8 @@ AMS reader - MQTT configuration - - + +
diff --git a/web/configsystem.html b/web/configsystem.html index 647623a7..56fc4f66 100644 --- a/web/configsystem.html +++ b/web/configsystem.html @@ -4,7 +4,7 @@ AMS reader - System configuration - +
diff --git a/web/configweb.html b/web/configweb.html index ac51e93c..85ef2c60 100644 --- a/web/configweb.html +++ b/web/configweb.html @@ -4,8 +4,8 @@ AMS reader - Web configuration - - + +
@@ -42,32 +42,32 @@
-
-
- -
- +
+
+
+ Security
+
-
-
- -
- +
+
+
+ Username
+
-
-
- -
- +
+
+
+ Password
+
diff --git a/web/configwifi.html b/web/configwifi.html index a6c25a4f..7869a166 100644 --- a/web/configwifi.html +++ b/web/configwifi.html @@ -4,8 +4,7 @@ AMS reader - WiFi configuration - - +
@@ -42,67 +41,73 @@
-
-
- -
- -
-
-
- -
- -
-
-
- -
- +
+
+
+ SSID
+
-
-
- -
- -
-
-
- -
- -
-
-
- -
- +
+
+
+ PSK
+
-
-
- -
- +
+
+
+ Hostname
+
-
- -
- +
+
+ +
+
+
+
+
+
+ IP
+
-
- -
- +
+
+
+
+ Subnet
+ +
+
+
+
+
+ Gateway +
+ +
+
+
+
+
+ Primary DNS +
+ +
+
+
+
+
+ Secondary DNS +
+
@@ -119,14 +124,10 @@
diff --git a/web/delete.html b/web/delete.html index 38a27c7f..d966ae4f 100644 --- a/web/delete.html +++ b/web/delete.html @@ -4,7 +4,7 @@ AMS reader - Delete - +
diff --git a/web/index.html b/web/index.html index 4a6b505c..403f4766 100644 --- a/web/index.html +++ b/web/index.html @@ -4,7 +4,7 @@ AMS reader - + diff --git a/web/upload.html b/web/upload.html index 6fbfce9a..706366fd 100644 --- a/web/upload.html +++ b/web/upload.html @@ -4,10 +4,10 @@ AMS reader - Upload - - - - + + + +