diff --git a/lib/HanConfigAp/src/configuration.cpp b/lib/HanConfigAp/src/configuration.cpp index 0a14ae95..1db4e11b 100644 --- a/lib/HanConfigAp/src/configuration.cpp +++ b/lib/HanConfigAp/src/configuration.cpp @@ -8,7 +8,7 @@ bool configuration::hasConfig() { bool hasConfig = false; EEPROM.begin(EEPROM_SIZE); - hasConfig = EEPROM.read(EEPROM_CONFIG_ADDRESS) == EEPROM_CHECK_SUM; + hasConfig = EEPROM.read(EEPROM_CONFIG_ADDRESS) >= 71; EEPROM.end(); return hasConfig; } @@ -46,6 +46,7 @@ bool configuration::save() } address += saveInt(address, fuseSize); + address += saveInt(address, distSys); bool success = EEPROM.commit(); EEPROM.end(); @@ -73,6 +74,7 @@ bool configuration::load() authUser = 0; authPass = 0; fuseSize = 0; + distSys = 0; EEPROM.begin(EEPROM_SIZE); int cs = EEPROM.read(address); @@ -118,6 +120,9 @@ bool configuration::load() if(cs >= 73) { address += readInt(address, &fuseSize); } + if(cs >= 74) { + address += readByte(address, &distSys); + } EEPROM.end(); return success; } diff --git a/lib/HanConfigAp/src/configuration.h b/lib/HanConfigAp/src/configuration.h index 68a142ba..76586eaa 100644 --- a/lib/HanConfigAp/src/configuration.h +++ b/lib/HanConfigAp/src/configuration.h @@ -30,6 +30,7 @@ public: char* authPass; int fuseSize; + byte distSys; bool hasConfig(); bool isSecure(); @@ -41,7 +42,7 @@ protected: private: const int EEPROM_SIZE = 512; - const byte EEPROM_CHECK_SUM = 73; // Used to check if config is stored. Change if structure changes + const byte EEPROM_CHECK_SUM = 74; // Used to check if config is stored. Change if structure changes const int EEPROM_CONFIG_ADDRESS = 0; int saveString(int pAddress, char* pString); diff --git a/src/web/AmsWebServer.cpp b/src/web/AmsWebServer.cpp index 4cbdd5ab..efa3ea06 100644 --- a/src/web/AmsWebServer.cpp +++ b/src/web/AmsWebServer.cpp @@ -39,12 +39,6 @@ void AmsWebServer::setup(configuration* config, Stream* debugger) { print(WiFi.localIP()); } println("/"); - - if(config->hasConfig() && config->fuseSize > 0) { - maxPwr = config->fuseSize * 230; - } else { - maxPwr = 20000; - } } void AmsWebServer::loop() { @@ -62,13 +56,12 @@ void AmsWebServer::setJson(StaticJsonDocument<500> json) { i2 = json["data"]["I2"].as(); i3 = json["data"]["I3"].as(); - if(config->hasConfig() && u1 > 0) { - maxPwr = config->fuseSize * u1; + if(maxPwr == 0 && config->hasConfig() && config->fuseSize > 0 && config->distSys > 0) { + int volt = config->distSys == 2 ? 400 : 230; if(u2 > 0) { - maxPwr += config->fuseSize * u2; - if(u3 > 0) { - maxPwr += config->fuseSize * u3; - } + maxPwr = config->fuseSize * sqrt(3) * volt; + } else { + maxPwr = config->fuseSize * 230; } } } else { @@ -182,6 +175,9 @@ void AmsWebServer::configurationHtml() { for(int i = 0; i<64; i++) { html.replace("${config.fuseSize" + String(i) + "}", config->fuseSize == i ? "selected" : ""); } + for(int i = 0; i<3; i++) { + html.replace("${config.distSys" + String(i) + "}", config->distSys == i ? "selected" : ""); + } } else { html.replace("${config.ssid}", ""); html.replace("${config.ssidPassword}", ""); @@ -206,6 +202,9 @@ void AmsWebServer::configurationHtml() { for(int i = 0; i<64; i++) { html.replace("${config.fuseSize" + String(i) + "}", i == 0 ? "selected" : ""); } + for(int i = 0; i<3; i++) { + html.replace("${config.distSys" + String(i) + "}", i == 0 ? "selected" : ""); + } } server.send(200, "text/html", html); } @@ -256,6 +255,15 @@ void AmsWebServer::dataJson() { if(!json.isNull()) { println(" json has data"); + int maxPwr = this->maxPwr; + if(maxPwr == 0) { + if(u2 > 0) { + maxPwr = 25000; + } else { + maxPwr = 15000; + } + } + json["maxPower"] = maxPwr; json["pct"] = min(p*100/maxPwr, 100); json["meterType"] = config->meterType; @@ -324,6 +332,8 @@ void AmsWebServer::handleSave() { config->fuseSize = (int)server.arg("fuseSize").toInt(); + config->distSys = (byte)server.arg("distSys").toInt(); + println("Saving configuration now..."); if (debugger) config->print(debugger); diff --git a/web/configuration.html b/web/configuration.html index 129b1ff5..d8317e81 100644 --- a/web/configuration.html +++ b/web/configuration.html @@ -37,8 +37,18 @@
AMS meter
- -
+ +
+ +
+
+
+ +
diff --git a/web/index.html b/web/index.html index ba7f56d2..69c2edad 100644 --- a/web/index.html +++ b/web/index.html @@ -68,10 +68,10 @@ Release notes
- +