mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-02-27 01:10:31 +00:00
Added option for electric distribution system (230/400)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<double>();
|
||||
i3 = json["data"]["I3"].as<double>();
|
||||
|
||||
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);
|
||||
|
||||
@@ -37,8 +37,18 @@
|
||||
<div class="my-3 p-3 bg-white rounded shadow">
|
||||
<h6 class="border-bottom border-gray pb-2 mb-4">AMS meter</h6>
|
||||
<div class="row form-group">
|
||||
<label class="col-4">Meter type</label>
|
||||
<div class="col-8">
|
||||
<label class="col-6">Distribution system</label>
|
||||
<div class="col-6">
|
||||
<select class="form-control" name="distSys">
|
||||
<option value="" ${config.distSys0}></option>
|
||||
<option value="1" ${config.distSys1}>IT (230V)</option>
|
||||
<option value="2" ${config.distSys2}>TN (400V)</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row form-group">
|
||||
<label class="col-6">Meter type</label>
|
||||
<div class="col-6">
|
||||
<select class="form-control" name="meterType">
|
||||
<option value="0" ${config.meterType0} disabled></option>
|
||||
<option value="1" ${config.meterType1}>Kaifa</option>
|
||||
@@ -48,8 +58,8 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="row form-group">
|
||||
<label class="col-4">Main fuse</label>
|
||||
<div class="col-8">
|
||||
<label class="col-6">Main fuse</label>
|
||||
<div class="col-6">
|
||||
<select class="form-control" name="fuseSize">
|
||||
<option value="" ${config.fuseSize0}></option>
|
||||
<option value="25" ${config.fuseSize25}>25A</option>
|
||||
|
||||
@@ -68,10 +68,10 @@
|
||||
<a href="https://github.com/gskjold/AmsToMqttBridge/releases" class="btn btn-outline-secondary">Release notes</a>
|
||||
</div>
|
||||
<div class="col-6 text-right">
|
||||
<a href="/configuration" class="btn btn-primary">Configuration</a>
|
||||
<a href="configuration" class="btn btn-primary">Configuration</a>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<script src="/index.js"></script>
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user