Compare commits

..

2 Commits

Author SHA1 Message Date
Gunnar Skjold
1f7d845a32 Removed debugging 2022-01-14 07:13:43 +01:00
Gunnar Skjold
6de5b719f3 Various changes 2022-01-14 07:12:08 +01:00
6 changed files with 78 additions and 53 deletions

View File

@@ -232,6 +232,8 @@ bool AmsConfiguration::getDebugConfig(DebugConfig& config) {
} }
bool AmsConfiguration::setDebugConfig(DebugConfig& config) { bool AmsConfiguration::setDebugConfig(DebugConfig& config) {
if(!config.serial && !config.telnet)
config.level = 5; // Force error level when debug is disabled
EEPROM.begin(EEPROM_SIZE); EEPROM.begin(EEPROM_SIZE);
EEPROM.put(CONFIG_DEBUG_START, config); EEPROM.put(CONFIG_DEBUG_START, config);
bool ret = EEPROM.commit(); bool ret = EEPROM.commit();

View File

@@ -198,6 +198,9 @@ bool AmsDataStorage::update(AmsData* data) {
float iph = im / hrs; float iph = im / hrs;
float eph = ex / hrs; float eph = ex / hrs;
// There is something wacky going on when it ends up here. The total value (im) is way way lower than it should be, which in
// turn causes low values for all estimates. And then when it returns to the normal case above, the value is waaay higher.
if(debugger->isActive(RemoteDebug::DEBUG)) { if(debugger->isActive(RemoteDebug::DEBUG)) {
debugger->printf("(AmsDataStorage) Since last month update, hours: %.1f, import: %d (%.2f/hr), export: %d (%.2f/hr)\n", hrs, im, iph, ex, eph); debugger->printf("(AmsDataStorage) Since last month update, hours: %.1f, import: %d (%.2f/hr), export: %d (%.2f/hr)\n", hrs, im, iph, ex, eph);
} }
@@ -210,7 +213,7 @@ bool AmsDataStorage::update(AmsData* data) {
} }
month.lastMeterReadTime = month.lastMeterReadTime - (tm.Hour * 3600) - (tm.Minute * 60) - tm.Second; month.lastMeterReadTime = month.lastMeterReadTime - (tm.Hour * 3600) - (tm.Minute * 60) - tm.Second;
if(debugger->isActive(RemoteDebug::DEBUG)) { if(debugger->isActive(RemoteDebug::DEBUG)) {
debugger->printf("(AmsDataStorage) Last month read after resetting to midnight: %lu", month.lastMeterReadTime); debugger->printf("(AmsDataStorage) Last month read after resetting to midnight: %lu\n", month.lastMeterReadTime);
} }
if(tz != NULL) { if(tz != NULL) {

View File

@@ -13,7 +13,9 @@
*/ */
#if defined(ESP8266) #if defined(ESP8266)
ADC_MODE(ADC_VCC); ADC_MODE(ADC_VCC);
#else if defined(ESP32) #endif
#if defined(ESP32)
#include <esp_task_wdt.h> #include <esp_task_wdt.h>
#endif #endif
#define WDT_TIMEOUT 10 #define WDT_TIMEOUT 10

View File

@@ -3,7 +3,6 @@
#include "Timezone.h" #include "Timezone.h"
IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, uint8_t distributionSystem, CosemDateTime packageTimestamp, HDLCConfig* hc) { IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, uint8_t distributionSystem, CosemDateTime packageTimestamp, HDLCConfig* hc) {
uint32_t ui;
double val; double val;
char str[64]; char str[64];
@@ -13,8 +12,8 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, uint8_t distribution
this->packageTimestamp = getTimestamp(packageTimestamp); this->packageTimestamp = getTimestamp(packageTimestamp);
ui = getNumber(AMS_OBIS_ACTIVE_IMPORT, sizeof(AMS_OBIS_ACTIVE_IMPORT), ((char *) (d))); val = getNumber(AMS_OBIS_ACTIVE_IMPORT, sizeof(AMS_OBIS_ACTIVE_IMPORT), ((char *) (d)));
if(ui == 0xFFFFFFFF) { if(val == NOVALUE) {
CosemData* data = getCosemDataAt(1, ((char *) (d))); CosemData* data = getCosemDataAt(1, ((char *) (d)));
// Kaifa special case... // Kaifa special case...
@@ -137,7 +136,7 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, uint8_t distribution
// Kaifa end // Kaifa end
} else { } else {
listType = 1; listType = 1;
activeImportPower = ui; activeImportPower = val;
meterType = AmsTypeUnknown; meterType = AmsTypeUnknown;
CosemData* version = findObis(AMS_OBIS_VERSION, sizeof(AMS_OBIS_VERSION), d); CosemData* version = findObis(AMS_OBIS_VERSION, sizeof(AMS_OBIS_VERSION), d);
@@ -166,95 +165,96 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, uint8_t distribution
this->packageTimestamp = this->packageTimestamp > 0 ? tz.toUTC(this->packageTimestamp) : 0; this->packageTimestamp = this->packageTimestamp > 0 ? tz.toUTC(this->packageTimestamp) : 0;
} }
ui = getString(AMS_OBIS_VERSION, sizeof(AMS_OBIS_VERSION), ((char *) (d)), str); uint8_t str_len = 0;
if(ui > 0) { str_len = getString(AMS_OBIS_VERSION, sizeof(AMS_OBIS_VERSION), ((char *) (d)), str);
if(str_len > 0) {
listId = String(str); listId = String(str);
} }
ui = getNumber(AMS_OBIS_ACTIVE_EXPORT, sizeof(AMS_OBIS_ACTIVE_EXPORT), ((char *) (d))); val = getNumber(AMS_OBIS_ACTIVE_EXPORT, sizeof(AMS_OBIS_ACTIVE_EXPORT), ((char *) (d)));
if(ui != 0xFFFFFFFF) { if(val != NOVALUE) {
activeExportPower = ui; activeExportPower = val;
} }
ui = getNumber(AMS_OBIS_REACTIVE_IMPORT, sizeof(AMS_OBIS_REACTIVE_IMPORT), ((char *) (d))); val = getNumber(AMS_OBIS_REACTIVE_IMPORT, sizeof(AMS_OBIS_REACTIVE_IMPORT), ((char *) (d)));
if(ui != 0xFFFFFFFF) { if(val != NOVALUE) {
reactiveImportPower = ui; reactiveImportPower = val;
} }
ui = getNumber(AMS_OBIS_REACTIVE_EXPORT, sizeof(AMS_OBIS_REACTIVE_EXPORT), ((char *) (d))); val = getNumber(AMS_OBIS_REACTIVE_EXPORT, sizeof(AMS_OBIS_REACTIVE_EXPORT), ((char *) (d)));
if(ui != 0xFFFFFFFF) { if(val != NOVALUE) {
reactiveExportPower = ui; reactiveExportPower = val;
} }
val = getNumber(AMS_OBIS_VOLTAGE_L1, sizeof(AMS_OBIS_VOLTAGE_L1), ((char *) (d))); val = getNumber(AMS_OBIS_VOLTAGE_L1, sizeof(AMS_OBIS_VOLTAGE_L1), ((char *) (d)));
if(val != 0xFFFFFFFF) { if(val != NOVALUE) {
listType = 2; listType = 2;
l1voltage = val; l1voltage = val;
} }
val = getNumber(AMS_OBIS_VOLTAGE_L2, sizeof(AMS_OBIS_VOLTAGE_L2), ((char *) (d))); val = getNumber(AMS_OBIS_VOLTAGE_L2, sizeof(AMS_OBIS_VOLTAGE_L2), ((char *) (d)));
if(val != 0xFFFFFFFF) { if(val != NOVALUE) {
listType = 2; listType = 2;
l2voltage = val; l2voltage = val;
} }
val = getNumber(AMS_OBIS_VOLTAGE_L3, sizeof(AMS_OBIS_VOLTAGE_L3), ((char *) (d))); val = getNumber(AMS_OBIS_VOLTAGE_L3, sizeof(AMS_OBIS_VOLTAGE_L3), ((char *) (d)));
if(val != 0xFFFFFFFF) { if(val != NOVALUE) {
listType = 2; listType = 2;
l3voltage = val; l3voltage = val;
} }
val = getNumber(AMS_OBIS_CURRENT_L1, sizeof(AMS_OBIS_CURRENT_L1), ((char *) (d))); val = getNumber(AMS_OBIS_CURRENT_L1, sizeof(AMS_OBIS_CURRENT_L1), ((char *) (d)));
if(val != 0xFFFFFFFF) { if(val != NOVALUE) {
listType = 2; listType = 2;
l1current = val; l1current = val;
} }
val = getNumber(AMS_OBIS_CURRENT_L2, sizeof(AMS_OBIS_CURRENT_L2), ((char *) (d))); val = getNumber(AMS_OBIS_CURRENT_L2, sizeof(AMS_OBIS_CURRENT_L2), ((char *) (d)));
if(val != 0xFFFFFFFF) { if(val != NOVALUE) {
listType = 2; listType = 2;
l2current = val; l2current = val;
} }
val = getNumber(AMS_OBIS_CURRENT_L3, sizeof(AMS_OBIS_CURRENT_L3), ((char *) (d))); val = getNumber(AMS_OBIS_CURRENT_L3, sizeof(AMS_OBIS_CURRENT_L3), ((char *) (d)));
if(val != 0xFFFFFFFF) { if(val != NOVALUE) {
listType = 2; listType = 2;
l3current = val; l3current = val;
} }
val = getNumber(AMS_OBIS_ACTIVE_IMPORT_COUNT, sizeof(AMS_OBIS_ACTIVE_IMPORT_COUNT), ((char *) (d))); val = getNumber(AMS_OBIS_ACTIVE_IMPORT_COUNT, sizeof(AMS_OBIS_ACTIVE_IMPORT_COUNT), ((char *) (d)));
if(val != 0xFFFFFFFF) { if(val != NOVALUE) {
listType = 3; listType = 3;
activeImportCounter = val / 1000.0; activeImportCounter = val / 1000.0;
} }
val = getNumber(AMS_OBIS_ACTIVE_EXPORT_COUNT, sizeof(AMS_OBIS_ACTIVE_EXPORT_COUNT), ((char *) (d))); val = getNumber(AMS_OBIS_ACTIVE_EXPORT_COUNT, sizeof(AMS_OBIS_ACTIVE_EXPORT_COUNT), ((char *) (d)));
if(val != 0xFFFFFFFF) { if(val != NOVALUE) {
listType = 3; listType = 3;
activeExportCounter = val / 1000.0; activeExportCounter = val / 1000.0;
} }
val = getNumber(AMS_OBIS_REACTIVE_IMPORT_COUNT, sizeof(AMS_OBIS_REACTIVE_IMPORT_COUNT), ((char *) (d))); val = getNumber(AMS_OBIS_REACTIVE_IMPORT_COUNT, sizeof(AMS_OBIS_REACTIVE_IMPORT_COUNT), ((char *) (d)));
if(val != 0xFFFFFFFF) { if(val != NOVALUE) {
listType = 3; listType = 3;
reactiveImportCounter = val / 1000.0; reactiveImportCounter = val / 1000.0;
} }
val = getNumber(AMS_OBIS_REACTIVE_EXPORT_COUNT, sizeof(AMS_OBIS_REACTIVE_EXPORT_COUNT), ((char *) (d))); val = getNumber(AMS_OBIS_REACTIVE_EXPORT_COUNT, sizeof(AMS_OBIS_REACTIVE_EXPORT_COUNT), ((char *) (d)));
if(val != 0xFFFFFFFF) { if(val != NOVALUE) {
listType = 3; listType = 3;
reactiveExportCounter = val / 1000.0; reactiveExportCounter = val / 1000.0;
} }
ui = getString(AMS_OBIS_METER_MODEL, sizeof(AMS_OBIS_METER_MODEL), ((char *) (d)), str); str_len = getString(AMS_OBIS_METER_MODEL, sizeof(AMS_OBIS_METER_MODEL), ((char *) (d)), str);
if(ui > 0) { if(str_len > 0) {
meterModel = String(str); meterModel = String(str);
} else { } else {
ui = getString(AMS_OBIS_METER_MODEL_2, sizeof(AMS_OBIS_METER_MODEL_2), ((char *) (d)), str); str_len = getString(AMS_OBIS_METER_MODEL_2, sizeof(AMS_OBIS_METER_MODEL_2), ((char *) (d)), str);
if(ui > 0) { if(str_len > 0) {
meterModel = String(str); meterModel = String(str);
} }
} }
ui = getString(AMS_OBIS_METER_ID, sizeof(AMS_OBIS_METER_ID), ((char *) (d)), str); str_len = getString(AMS_OBIS_METER_ID, sizeof(AMS_OBIS_METER_ID), ((char *) (d)), str);
if(ui > 0) { if(str_len > 0) {
meterId = String(str); meterId = String(str);
} else { } else {
ui = getString(AMS_OBIS_METER_ID_2, sizeof(AMS_OBIS_METER_ID_2), ((char *) (d)), str); str_len = getString(AMS_OBIS_METER_ID_2, sizeof(AMS_OBIS_METER_ID_2), ((char *) (d)), str);
if(ui > 0) { if(str_len > 0) {
meterId = String(str); meterId = String(str);
} }
} }
@@ -271,19 +271,19 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, uint8_t distribution
} }
val = getNumber(AMS_OBIS_POWER_FACTOR, sizeof(AMS_OBIS_POWER_FACTOR), ((char *) (d))); val = getNumber(AMS_OBIS_POWER_FACTOR, sizeof(AMS_OBIS_POWER_FACTOR), ((char *) (d)));
if(val != 0xFFFFFFFF) { if(val != NOVALUE) {
powerFactor = val; powerFactor = val;
} }
val = getNumber(AMS_OBIS_POWER_FACTOR_L1, sizeof(AMS_OBIS_POWER_FACTOR_L1), ((char *) (d))); val = getNumber(AMS_OBIS_POWER_FACTOR_L1, sizeof(AMS_OBIS_POWER_FACTOR_L1), ((char *) (d)));
if(val != 0xFFFFFFFF) { if(val != NOVALUE) {
l1PowerFactor = val; l1PowerFactor = val;
} }
val = getNumber(AMS_OBIS_POWER_FACTOR_L2, sizeof(AMS_OBIS_POWER_FACTOR_L2), ((char *) (d))); val = getNumber(AMS_OBIS_POWER_FACTOR_L2, sizeof(AMS_OBIS_POWER_FACTOR_L2), ((char *) (d)));
if(val != 0xFFFFFFFF) { if(val != NOVALUE) {
l2PowerFactor = val; l2PowerFactor = val;
} }
val = getNumber(AMS_OBIS_POWER_FACTOR_L3, sizeof(AMS_OBIS_POWER_FACTOR_L3), ((char *) (d))); val = getNumber(AMS_OBIS_POWER_FACTOR_L3, sizeof(AMS_OBIS_POWER_FACTOR_L3), ((char *) (d)));
if(val != 0xFFFFFFFF) { if(val != NOVALUE) {
l3PowerFactor = val; l3PowerFactor = val;
} }
@@ -335,6 +335,7 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, uint8_t distribution
} }
threePhase = l1voltage > 0 && l2voltage > 0 && l3voltage > 0; threePhase = l1voltage > 0 && l2voltage > 0 && l3voltage > 0;
if(!threePhase)
twoPhase = (l1voltage > 0 && l2voltage > 0) || (l2voltage > 0 && l3voltage > 0) || (l3voltage > 0 && l1voltage > 0); twoPhase = (l1voltage > 0 && l2voltage > 0) || (l2voltage > 0 && l3voltage > 0) || (l3voltage > 0 && l1voltage > 0);
// Special case for Norwegian IT/TT meters that does not report all values // Special case for Norwegian IT/TT meters that does not report all values
@@ -342,7 +343,7 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, uint8_t distribution
if(threePhase) { if(threePhase) {
if(l2current == 0.0 && l1current > 0.0 && l3current > 0.0) { if(l2current == 0.0 && l1current > 0.0 && l3current > 0.0) {
l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage; l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
if(activeExportPower == 0) { if(activeExportPower == 0.0) {
l2current = max((float) 0.0, l2current); l2current = max((float) 0.0, l2current);
} }
} }
@@ -453,31 +454,39 @@ double IEC6205675::getNumber(uint8_t* obis, int matchlength, const char* ptr) {
} }
double IEC6205675::getNumber(CosemData* item) { double IEC6205675::getNumber(CosemData* item) {
double val = 0xFFFFFFFF;
if(item != NULL) { if(item != NULL) {
double ret = 0.0;
char* pos = ((char*) item); char* pos = ((char*) item);
switch(item->base.type) { switch(item->base.type) {
case CosemTypeLongUnsigned: case CosemTypeLongUnsigned: {
val = ntohs(item->lu.data); uint16_t u16 = ntohs(item->lu.data);
ret = u16;
pos += 3; pos += 3;
break; break;
case CosemTypeDLongUnsigned: }
val = ntohl(item->dlu.data); case CosemTypeDLongUnsigned: {
uint32_t u32 = ntohl(item->dlu.data);
ret = u32;
pos += 5; pos += 5;
break; break;
case CosemTypeLongSigned: }
val = ntohs(item->lu.data); case CosemTypeLongSigned: {
uint16_t u16 = ntohs(item->lu.data); // ntohs only works for uint16 ?
int16_t i16 = u16; // Cast to int16 before use?
ret = i16; // Who knows, got to try it all...
pos += 3; pos += 3;
break; break;
} }
}
if(pos != NULL) { if(pos != NULL) {
if(*pos++ == 0x02 && *pos++ == 0x02) { if(*pos++ == 0x02 && *pos++ == 0x02) {
int8_t scale = *++pos; int8_t scale = *++pos;
val *= pow(10, scale); ret *= pow(10, scale);
} }
} }
return ret;
} }
return val; return NOVALUE;
} }
time_t IEC6205675::getTimestamp(uint8_t* obis, int matchlength, const char* ptr) { time_t IEC6205675::getTimestamp(uint8_t* obis, int matchlength, const char* ptr) {

View File

@@ -4,6 +4,8 @@
#include "AmsData.h" #include "AmsData.h"
#include "ams/hdlc.h" #include "ams/hdlc.h"
#define NOVALUE 0xFFFFFFFF
struct AmsOctetTimestamp { struct AmsOctetTimestamp {
uint8_t type; uint8_t type;
CosemDateTime dt; CosemDateTime dt;

View File

@@ -14,6 +14,10 @@
#define HEAD_HTML_LEN HEAD32_HTML_LEN #define HEAD_HTML_LEN HEAD32_HTML_LEN
#endif #endif
#if defined(ESP32)
#include <esp_task_wdt.h>
#endif
#include "root/foot_html.h" #include "root/foot_html.h"
#include "root/index_html.h" #include "root/index_html.h"
#include "root/application_js.h" #include "root/application_js.h"
@@ -322,9 +326,6 @@ void AmsWebServer::indexHtml() {
for(int i = 0; i<255; i++) { for(int i = 0; i<255; i++) {
html.replace("${config.boardType" + String(i) + "}", sys.boardType == i ? "selected" : ""); html.replace("${config.boardType" + String(i) + "}", sys.boardType == i ? "selected" : "");
} }
for(int i = 0; i<5; i++) {
html.replace("${config.meterType" + String(i) + "}", sys.boardType == i ? "selected" : "");
}
html.replace("${config.wifiSsid}", wifi.ssid); html.replace("${config.wifiSsid}", wifi.ssid);
html.replace("${config.wifiPassword}", wifi.psk); html.replace("${config.wifiPassword}", wifi.psk);
html.replace("${config.wifiStaticIp}", strlen(wifi.ip) > 0 ? "checked" : ""); html.replace("${config.wifiStaticIp}", strlen(wifi.ip) > 0 ? "checked" : "");
@@ -1561,6 +1562,12 @@ void AmsWebServer::firmwareUpload() {
String filename = upload.filename; String filename = upload.filename;
if(!filename.endsWith(".bin")) { if(!filename.endsWith(".bin")) {
server.send(500, "text/plain", "500: couldn't create file"); server.send(500, "text/plain", "500: couldn't create file");
} else {
#if defined(ESP32)
esp_task_wdt_deinit();
#elif defined(ESP8266)
ESP.wdtDisable();
#endif
} }
} }
uploadFile(FILE_FIRMWARE); uploadFile(FILE_FIRMWARE);