Compare commits

...

9 Commits

Author SHA1 Message Date
Gunnar Skjold
fcbfe4d96f Changes to make substituted I2 correct when exporting power 2020-07-25 09:17:39 +02:00
Gunnar Skjold
b4f18de030 Made base64 work for both platforms 2020-07-25 08:48:51 +02:00
Gunnar Skjold
00d5d215cd Switched to internal base64 2020-07-25 08:45:31 +02:00
Gunnar Skjold
8de5a58a6b Changed dependency for Base64 2020-07-06 19:17:45 +02:00
Gunnar Skjold
012794e682 Make web content minifier optional 2020-07-06 19:14:37 +02:00
Gunnar Skjold
38eb2d8c19 Merge pull request #79 from gskjold/dev-v1.3.0
Dev v1.3.0
2020-06-06 20:30:47 +02:00
Gunnar Skjold
d95137adbc Support for Kamstrup IT meters 2020-05-28 18:44:38 +02:00
Gunnar Skjold
cde3f80fca Ensure that GPIO is correctly set after setup 2020-05-28 14:19:03 +02:00
Gunnar Skjold
cdc012743f Changes for building on GitHub actions for all branches 2020-05-27 08:38:59 +02:00
8 changed files with 126 additions and 50 deletions

View File

@@ -9,7 +9,7 @@ on:
- web/**
- platformio.ini
branches:
- master
- '*'
tags:
- '*'
- '!v*.*.*'

View File

@@ -5,10 +5,12 @@
enum class Kamstrup
{
List1PhaseShort = 0x11,
List1PhaseLong = 0x1B,
List3PhaseShort = 0x19,
List3PhaseLong = 0x23,
List1PhaseShort = 0x11,
List1PhaseLong = 0x1B
List3PhaseITShort = 0x17,
List3PhaseITLong = 0x21
};
enum class Kamstrup_List3Phase
@@ -83,5 +85,43 @@ enum class Kamstrup_List1Phase
CumulativeReactiveExportEnergy
};
enum class Kamstrup_List3PhaseIT
{
ListSize,
ListVersionIdentifier,
MeterID_OBIS,
MeterID,
MeterType_OBIS,
MeterType,
ActiveImportPower_OBIS,
ActiveImportPower,
ActiveExportPower_OBIS,
ActiveExportPower,
ReactiveImportPower_OBIS,
ReactiveImportPower,
ReactiveExportPower_OBIS,
ReactiveExportPower,
CurrentL1_OBIS,
CurrentL1,
CurrentL3_OBIS,
CurrentL3,
VoltageL1_OBIS,
VoltageL1,
VoltageL2_OBIS,
VoltageL2,
VoltageL3_OBIS,
VoltageL3,
MeterClock_OBIS,
MeterClock,
CumulativeActiveImportEnergy_OBIS,
CumulativeActiveImportEnergy,
CumulativeActiveExportEnergy_OBIS,
CumulativeActiveExportEnergy,
CumulativeReactiveImportEnergy_OBIS,
CumulativeReactiveImportEnergy,
CumulativeReactiveExportEnergy_OBIS,
CumulativeReactiveExportEnergy
};
#endif

View File

@@ -4,10 +4,10 @@ extra_configs = platformio-user.ini
[common]
framework = arduino
lib_deps = HanReader@1.0.1, ArduinoJson@6.14.1, MQTT@2.4.7, DallasTemperature@3.8.1, EspSoftwareSerial@6.7.1, Base64@1.0.0, RemoteDebug@3.0.5, Time@1.6
lib_deps = HanReader@1.0.1, ArduinoJson@6.14.1, MQTT@2.4.7, DallasTemperature@3.8.1, EspSoftwareSerial@6.7.1, RemoteDebug@3.0.5, Time@1.6
[env:hw1esp12e]
platform = espressif8266@2.3.3
platform = espressif8266@2.5.1
board = esp12e
framework = ${common.framework}
lib_deps = ${common.lib_deps}
@@ -18,7 +18,7 @@ extra_scripts =
scripts/makeweb.py
[env:esp12e]
platform = espressif8266@2.3.3
platform = espressif8266@2.5.1
board = esp12e
framework = ${common.framework}
lib_deps = ${common.lib_deps}
@@ -27,7 +27,7 @@ extra_scripts =
scripts/makeweb.py
[env:d1mini]
platform = espressif8266@2.3.3
platform = espressif8266@2.5.1
board = d1_mini
framework = ${common.framework}
lib_deps = ${common.lib_deps}
@@ -36,7 +36,7 @@ extra_scripts =
scripts/makeweb.py
[env:esp32]
platform = espressif32@1.11.2
platform = espressif32@1.12.1
board = esp32dev
framework = ${common.framework}
lib_deps = ${common.lib_deps}
@@ -45,7 +45,7 @@ extra_scripts =
scripts/makeweb.py
[env:lolind32]
platform = espressif32@1.11.2
platform = espressif32@1.12.1
board = lolin_d32
framework = ${common.framework}
lib_deps = ${common.lib_deps}
@@ -54,7 +54,7 @@ extra_scripts =
scripts/makeweb.py
[env:featheresp32]
platform = espressif32@1.11.2
platform = espressif32@1.12.1
board = featheresp32
framework = ${common.framework}
lib_deps = ${common.lib_deps}
@@ -63,7 +63,7 @@ extra_scripts =
scripts/makeweb.py
[env:az-delivery-devkit-v4]
platform = espressif32@1.11.2
platform = espressif32@1.12.1
board = az-delivery-devkit-v4
framework = ${common.framework}
lib_deps = ${common.lib_deps}
@@ -72,7 +72,7 @@ extra_scripts =
scripts/makeweb.py
[env:esp32doit-devkit-v1]
platform = espressif32@1.11.2
platform = espressif32@1.12.1
board = esp32doit-devkit-v1
framework = ${common.framework}
lib_deps = ${common.lib_deps}

View File

@@ -1,7 +1,12 @@
import os
import re
import shutil
from css_html_js_minify import html_minify, js_minify, css_minify
try:
from css_html_js_minify import html_minify, js_minify, css_minify
except:
print("WARN: Unable to load minifier")
webroot = "web"
srcroot = "src/web/root"
@@ -26,13 +31,16 @@ for filename in os.listdir(webroot):
with open(srcfile, encoding="utf-8") as f:
content = f.read().replace("${version}", version)
if filename.endswith(".html"):
content = html_minify(content)
elif filename.endswith(".css"):
content = css_minify(content)
elif filename.endswith(".js") and filename != 'gaugemeter.js':
content = js_minify(content)
try:
if filename.endswith(".html"):
content = html_minify(content)
elif filename.endswith(".css"):
content = css_minify(content)
elif filename.endswith(".js") and filename != 'gaugemeter.js':
content = js_minify(content)
except:
print("WARN: Unable to minify")
with open(dstfile, "w") as dst:
dst.write("const char ")

View File

@@ -18,7 +18,7 @@ AmsData::AmsData(int meterType, bool substituteMissing, HanReader& hanReader) {
extractFromAidon(hanReader, listSize, substituteMissing);
break;
case METER_TYPE_KAMSTRUP:
extractFromKamstrup(hanReader, listSize);
extractFromKamstrup(hanReader, listSize, substituteMissing);
break;
}
@@ -169,20 +169,22 @@ void AmsData::extractFromAidon(HanReader& hanReader, int listSize, bool substitu
l2voltage = ((double) hanReader.getInt( (int)Aidon_List3PhaseIT::VoltageL2)) / 10;
l3voltage = ((double) hanReader.getInt( (int)Aidon_List3PhaseIT::VoltageL3)) / 10;
if(substituteMissing) {
l2current = ((activeImportPower * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
}
break;
}
}
}
void AmsData::extractFromKamstrup(HanReader& hanReader, int listSize) {
void AmsData::extractFromKamstrup(HanReader& hanReader, int listSize, bool substituteMissing) {
switch(listSize) {
case (int)Kamstrup::List3PhaseITShort:
case (int)Kamstrup::List3PhaseShort:
threePhase = true;
case (int)Kamstrup::List1PhaseShort:
listType = 2;
break;
case (int)Kamstrup::List3PhaseITLong:
case (int)Kamstrup::List3PhaseLong:
threePhase = true;
case (int)Kamstrup::List1PhaseLong:
@@ -191,6 +193,23 @@ void AmsData::extractFromKamstrup(HanReader& hanReader, int listSize) {
}
switch(listSize) {
case (int)Kamstrup::List1PhaseLong:
meterTimestamp = hanReader.getTime( (int)Kamstrup_List1Phase::MeterClock);
activeImportCounter = ((double) hanReader.getInt((int)Kamstrup_List1Phase::CumulativeActiveImportEnergy)) / 100;
activeExportCounter = ((double) hanReader.getInt((int)Kamstrup_List1Phase::CumulativeActiveExportEnergy)) / 100;
reactiveImportCounter = ((double) hanReader.getInt((int)Kamstrup_List1Phase::CumulativeReactiveImportEnergy)) / 100;
reactiveExportCounter = ((double) hanReader.getInt((int)Kamstrup_List1Phase::CumulativeReactiveExportEnergy)) / 100;
case (int)Kamstrup::List1PhaseShort:
listId = hanReader.getString( (int)Kamstrup_List1Phase::ListVersionIdentifier);
meterId = hanReader.getString( (int)Kamstrup_List1Phase::MeterID);
meterType = hanReader.getString( (int)Kamstrup_List1Phase::MeterType);
activeImportPower = hanReader.getInt( (int)Kamstrup_List1Phase::ActiveImportPower);
reactiveImportPower = hanReader.getInt( (int)Kamstrup_List1Phase::ReactiveImportPower);
activeExportPower = hanReader.getInt( (int)Kamstrup_List1Phase::ActiveExportPower);
reactiveExportPower = hanReader.getInt( (int)Kamstrup_List1Phase::ReactiveExportPower);
l1current = ((double) hanReader.getInt((int)Kamstrup_List1Phase::CurrentL1)) / 100;
l1voltage = hanReader.getInt( (int)Kamstrup_List1Phase::VoltageL1);
break;
case (int)Kamstrup::List3PhaseLong:
meterTimestamp = hanReader.getTime( (int)Kamstrup_List3Phase::MeterClock);
activeImportCounter = ((double) hanReader.getInt((int)Kamstrup_List3Phase::CumulativeActiveImportEnergy)) / 100;
@@ -212,22 +231,29 @@ void AmsData::extractFromKamstrup(HanReader& hanReader, int listSize) {
l2voltage = hanReader.getInt( (int)Kamstrup_List3Phase::VoltageL2);
l3voltage = hanReader.getInt( (int)Kamstrup_List3Phase::VoltageL3);
break;
case (int)Kamstrup::List1PhaseLong:
meterTimestamp = hanReader.getTime( (int)Kamstrup_List1Phase::MeterClock);
activeImportCounter = ((double) hanReader.getInt((int)Kamstrup_List1Phase::CumulativeActiveImportEnergy)) / 100;
activeExportCounter = ((double) hanReader.getInt((int)Kamstrup_List1Phase::CumulativeActiveExportEnergy)) / 100;
reactiveImportCounter = ((double) hanReader.getInt((int)Kamstrup_List1Phase::CumulativeReactiveImportEnergy)) / 100;
reactiveExportCounter = ((double) hanReader.getInt((int)Kamstrup_List1Phase::CumulativeReactiveExportEnergy)) / 100;
case (int)Kamstrup::List1PhaseShort:
listId = hanReader.getString( (int)Kamstrup_List1Phase::ListVersionIdentifier);
meterId = hanReader.getString( (int)Kamstrup_List1Phase::MeterID);
meterType = hanReader.getString( (int)Kamstrup_List1Phase::MeterType);
activeImportPower = hanReader.getInt( (int)Kamstrup_List1Phase::ActiveImportPower);
reactiveImportPower = hanReader.getInt( (int)Kamstrup_List1Phase::ReactiveImportPower);
activeExportPower = hanReader.getInt( (int)Kamstrup_List1Phase::ActiveExportPower);
reactiveExportPower = hanReader.getInt( (int)Kamstrup_List1Phase::ReactiveExportPower);
l1current = ((double) hanReader.getInt((int)Kamstrup_List1Phase::CurrentL1)) / 100;
l1voltage = hanReader.getInt( (int)Kamstrup_List1Phase::VoltageL1);
case (int)Kamstrup::List3PhaseITLong:
meterTimestamp = hanReader.getTime( (int)Kamstrup_List3Phase::MeterClock);
activeImportCounter = ((double) hanReader.getInt((int)Kamstrup_List3Phase::CumulativeActiveImportEnergy)) / 100;
activeExportCounter = ((double) hanReader.getInt((int)Kamstrup_List3Phase::CumulativeActiveExportEnergy)) / 100;
reactiveImportCounter = ((double) hanReader.getInt((int)Kamstrup_List3Phase::CumulativeReactiveImportEnergy)) / 100;
reactiveExportCounter = ((double) hanReader.getInt((int)Kamstrup_List3Phase::CumulativeReactiveExportEnergy)) / 100;
case (int)Kamstrup::List3PhaseITShort:
listId = hanReader.getString( (int)Kamstrup_List3Phase::ListVersionIdentifier);
meterId = hanReader.getString( (int)Kamstrup_List3Phase::MeterID);
meterType = hanReader.getString( (int)Kamstrup_List3Phase::MeterType);
activeImportPower = hanReader.getInt( (int)Kamstrup_List3Phase::ActiveImportPower);
reactiveImportPower = hanReader.getInt( (int)Kamstrup_List3Phase::ReactiveImportPower);
activeExportPower = hanReader.getInt( (int)Kamstrup_List3Phase::ActiveExportPower);
reactiveExportPower = hanReader.getInt( (int)Kamstrup_List3Phase::ReactiveExportPower);
l1current = ((double) hanReader.getInt((int)Kamstrup_List3Phase::CurrentL1)) / 100;
l2current = 0;
l3current = ((double) hanReader.getInt((int)Kamstrup_List3Phase::CurrentL3)) / 100;
l1voltage = hanReader.getInt( (int)Kamstrup_List3Phase::VoltageL1);
l2voltage = hanReader.getInt( (int)Kamstrup_List3Phase::VoltageL2);
l3voltage = hanReader.getInt( (int)Kamstrup_List3Phase::VoltageL3);
if(substituteMissing) {
l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
}
break;
}
}

View File

@@ -61,7 +61,7 @@ private:
void extractFromKaifa(HanReader& hanReader, int listSize);
void extractFromAidon(HanReader& hanReader, int listSize, bool substituteMissing);
void extractFromKamstrup(HanReader& hanReader, int listSize);
void extractFromKamstrup(HanReader& hanReader, int listSize, bool substituteMissing);
};
#endif

View File

@@ -21,7 +21,7 @@
#include "root/delete_html.h"
#include "root/reset_html.h"
#include "Base64.h"
#include "base64.h"
AmsWebServer::AmsWebServer(RemoteDebug* Debug, HwTools* hw) {
this->debugger = Debug;
@@ -97,15 +97,9 @@ bool AmsWebServer::checkSecurity(byte level) {
String providedPwd = server.header("Authorization");
providedPwd.replace("Basic ", "");
char inputString[providedPwd.length()];
providedPwd.toCharArray(inputString, providedPwd.length()+1);
int inputStringLength = sizeof(inputString);
int decodedLength = Base64.decodedLength(inputString, inputStringLength);
char decodedString[decodedLength];
Base64.decode(decodedString, inputString, inputStringLength);
printD("Received auth: %s", decodedString);
access = String(decodedString).equals(expectedAuth);
String expectedBase64 = base64::encode(expectedAuth);
access = providedPwd.equals(expectedBase64);
}
if(!access) {
@@ -557,6 +551,14 @@ void AmsWebServer::handleSetup() {
server.sendHeader("Location", String("/"), true);
server.send (302, "text/plain", "");
} else {
config->setLedPin(0xFF);
config->setLedPinRed(0xFF);
config->setLedPinGreen(0xFF);
config->setLedPinBlue(0xFF);
config->setApPin(0xFF);
config->setTempSensorPin(0xFF);
config->setVccPin(0xFF);
config->setBoardType(server.arg("board").toInt());
config->setVccMultiplier(1.0);
config->setVccBootLimit(0);

View File

@@ -59,7 +59,7 @@ $(function() {
// For config-meter
$('.subtitute-dependent').on('change', function() {
console.log("test");
if($('#meterType').val() == 2 && $('#distributionSystem').val() == 1) {
if(($('#meterType').val() == 2 || $('#meterType').val() == 3) && $('#distributionSystem').val() == 1) {
$('#substitute').show();
} else {
$('#substitute').hide();