From 4e97554514c9aa0a6a7a547dc76a9fd2042240ec Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Wed, 14 Dec 2022 19:37:32 +0100 Subject: [PATCH] Some changes during testing --- lib/AmsDataStorage/src/AmsDataStorage.cpp | 26 ++++---- lib/ClassicUi/src/AmsWebServer.cpp | 8 +-- lib/EnergyAccounting/src/EnergyAccounting.cpp | 4 +- lib/EntsoePriceApi/src/EntsoeApi.cpp | 2 +- lib/SvelteUi/app/src/App.svelte | 2 +- .../app/src/lib/ConfigurationPanel.svelte | 2 +- lib/SvelteUi/src/AmsWebServer.cpp | 8 +-- src/AmsToMqttBridge.ino | 64 ++++++++++--------- 8 files changed, 60 insertions(+), 56 deletions(-) diff --git a/lib/AmsDataStorage/src/AmsDataStorage.cpp b/lib/AmsDataStorage/src/AmsDataStorage.cpp index 091eef04..5031f2e1 100644 --- a/lib/AmsDataStorage/src/AmsDataStorage.cpp +++ b/lib/AmsDataStorage/src/AmsDataStorage.cpp @@ -21,7 +21,7 @@ bool AmsDataStorage::update(AmsData* data) { } time_t now = time(nullptr); - if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(AmsDataStorage) Time is: %lld\n", (int64_t) now); + if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(AmsDataStorage) Time is: %lu\n", (int32_t) now); if(tz == NULL) { if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(AmsDataStorage) Timezone is missing\n"); return false; @@ -30,18 +30,18 @@ bool AmsDataStorage::update(AmsData* data) { if(data->getMeterTimestamp() > BUILD_EPOCH) { now = data->getMeterTimestamp(); if(debugger->isActive(RemoteDebug::DEBUG)) { - debugger->printf("(AmsDataStorage) Using meter timestamp, which is: %lld\n", (int64_t) now); + debugger->printf("(AmsDataStorage) Using meter timestamp, which is: %lu\n", (int32_t) now); } } else if(data->getPackageTimestamp() > BUILD_EPOCH) { now = data->getPackageTimestamp(); if(debugger->isActive(RemoteDebug::DEBUG)) { - debugger->printf("(AmsDataStorage) Using package timestamp, which is: %lld\n", (int64_t) now); + debugger->printf("(AmsDataStorage) Using package timestamp, which is: %lu\n", (int32_t) now); } } } if(now < BUILD_EPOCH) { if(debugger->isActive(RemoteDebug::VERBOSE)) { - debugger->printf("(AmsDataStorage) Invalid time: %lld\n", (int64_t) now); + debugger->printf("(AmsDataStorage) Invalid time: %lu\n", (int32_t) now); } return false; } @@ -63,7 +63,7 @@ bool AmsDataStorage::update(AmsData* data) { return true; } else { if(debugger->isActive(RemoteDebug::DEBUG)) { - debugger->printf("(AmsDataStorage) Last day update: %lld\n", (int64_t) day.lastMeterReadTime); + debugger->printf("(AmsDataStorage) Last day update: %lu\n", (int32_t) day.lastMeterReadTime); } tmElements_t last; breakTime(day.lastMeterReadTime, last); @@ -86,7 +86,7 @@ bool AmsDataStorage::update(AmsData* data) { month.lastMeterReadTime = now; } else { if(debugger->isActive(RemoteDebug::DEBUG)) { - debugger->printf("(AmsDataStorage) Last month update: %lld\n", (int64_t) month.lastMeterReadTime); + debugger->printf("(AmsDataStorage) Last month update: %lu\n", (int32_t) month.lastMeterReadTime); } tmElements_t last; breakTime(tz->toLocal(month.lastMeterReadTime), last); @@ -156,7 +156,7 @@ bool AmsDataStorage::update(AmsData* data) { setHourExport(last.Hour, exp); if(debugger->isActive(RemoteDebug::INFO)) { - debugger->printf("(AmsDataStorage) Estimated usage for hour %u: %.1f - %.1f (%lld)\n", last.Hour, imp, exp, (int64_t) cur); + debugger->printf("(AmsDataStorage) Estimated usage for hour %u: %.1f - %.1f (%lu)\n", last.Hour, imp, exp, (int32_t) cur); } day.activeImport += imp; @@ -199,7 +199,7 @@ bool AmsDataStorage::update(AmsData* data) { breakTime(tz->toLocal(month.lastMeterReadTime), last); month.lastMeterReadTime = month.lastMeterReadTime - (last.Hour * 3600) - (last.Minute * 60) - last.Second; if(debugger->isActive(RemoteDebug::DEBUG)) { - debugger->printf("(AmsDataStorage) Last month read after resetting to midnight: %lld\n", (int64_t) month.lastMeterReadTime); + debugger->printf("(AmsDataStorage) Last month read after resetting to midnight: %lu\n", (int32_t) month.lastMeterReadTime); } float hrs = (now - month.lastMeterReadTime) / 3600.0; @@ -224,7 +224,7 @@ bool AmsDataStorage::update(AmsData* data) { setDayExport(last.Day, exp); if(debugger->isActive(RemoteDebug::INFO)) { - debugger->printf("(AmsDataStorage) Estimated usage for day %u: %.1f - %.1f (%lld)\n", last.Day, imp, exp, (int64_t) cur); + debugger->printf("(AmsDataStorage) Estimated usage for day %u: %.1f - %.1f (%lu)\n", last.Day, imp, exp, (int32_t) cur); } month.activeImport += imp; @@ -383,11 +383,11 @@ bool AmsDataStorage::isDayHappy() { tmElements_t tm, last; if(now < day.lastMeterReadTime) { - if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(AmsDataStorage) Day %lld < %lld\n", (int64_t) now, (int64_t) day.lastMeterReadTime); + if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(AmsDataStorage) Day %lu < %lu\n", (int32_t) now, (int32_t) day.lastMeterReadTime); return false; } if(now-day.lastMeterReadTime > 3600) { - if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(AmsDataStorage) Day %lld - %lld > 3600\n", (int64_t) now, (int64_t) day.lastMeterReadTime); + if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(AmsDataStorage) Day %lu - %lu > 3600\n", (int32_t) now, (int32_t) day.lastMeterReadTime); return false; } breakTime(tz->toLocal(now), tm); @@ -411,11 +411,11 @@ bool AmsDataStorage::isMonthHappy() { tmElements_t tm, last; if(now < month.lastMeterReadTime) { - if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(AmsDataStorage) Month %lld < %lld\n", (int64_t) now, (int64_t) month.lastMeterReadTime); + if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(AmsDataStorage) Month %lu < %lu\n", (int32_t) now, (int32_t) month.lastMeterReadTime); return false; } if(now-month.lastMeterReadTime > 86400) { - if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(AmsDataStorage) Month %lld - %lld > 3600\n", (int64_t) now, (int64_t) month.lastMeterReadTime); + if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(AmsDataStorage) Month %lu - %lu > 3600\n", (int32_t) now, (int32_t) month.lastMeterReadTime); return false; } breakTime(tz->toLocal(now), tm); diff --git a/lib/ClassicUi/src/AmsWebServer.cpp b/lib/ClassicUi/src/AmsWebServer.cpp index f7835a73..253f4029 100644 --- a/lib/ClassicUi/src/AmsWebServer.cpp +++ b/lib/ClassicUi/src/AmsWebServer.cpp @@ -2311,9 +2311,9 @@ void AmsWebServer::configFileDownload() { if(ds != NULL) { DayDataPoints day = ds->getDayData(); - server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("dayplot %d %lld %lu %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"), + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("dayplot %d %lu %lu %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"), day.version, - (int64_t) day.lastMeterReadTime, + (int32_t) day.lastMeterReadTime, day.activeImport, ds->getHourImport(0), ds->getHourImport(1), @@ -2373,9 +2373,9 @@ void AmsWebServer::configFileDownload() { } MonthDataPoints month = ds->getMonthData(); - server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("monthplot %d %lld %lu %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"), + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("monthplot %d %lu %lu %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"), month.version, - (int64_t) month.lastMeterReadTime, + (int32_t) month.lastMeterReadTime, month.activeImport, ds->getDayImport(1), ds->getDayImport(2), diff --git a/lib/EnergyAccounting/src/EnergyAccounting.cpp b/lib/EnergyAccounting/src/EnergyAccounting.cpp index 501fa490..50ac23a4 100644 --- a/lib/EnergyAccounting/src/EnergyAccounting.cpp +++ b/lib/EnergyAccounting/src/EnergyAccounting.cpp @@ -42,7 +42,7 @@ bool EnergyAccounting::update(AmsData* amsData) { if(!init) { currentHour = local.Hour; currentDay = local.Day; - if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(EnergyAccounting) Initializing data at %lld\n", (int64_t) now); + if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(EnergyAccounting) Initializing data at %lu\n", (int32_t) now); if(!load()) { if(debugger->isActive(RemoteDebug::INFO)) debugger->printf("(EnergyAccounting) Unable to load existing data\n"); data = { 5, local.Month, @@ -65,7 +65,7 @@ bool EnergyAccounting::update(AmsData* amsData) { } if(!initPrice && eapi != NULL && eapi->getValueForHour(0) != ENTSOE_NO_VALUE) { - if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(EnergyAccounting) Initializing prices at %lld\n", (int64_t) now); + if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(EnergyAccounting) Initializing prices at %lu\n", (int32_t) now); calcDayCost(); } diff --git a/lib/EntsoePriceApi/src/EntsoeApi.cpp b/lib/EntsoePriceApi/src/EntsoeApi.cpp index 3efe4d5f..ce939c9c 100644 --- a/lib/EntsoePriceApi/src/EntsoeApi.cpp +++ b/lib/EntsoePriceApi/src/EntsoeApi.cpp @@ -153,7 +153,7 @@ bool EntsoeApi::loop() { currentDay = tm.Day; return false; } else if(now > midnightMillis && currentDay != tm.Day) { - if(debugger->isActive(RemoteDebug::INFO)) debugger->printf("(EntsoeApi) Rotating price objects at %lld\n", t); + if(debugger->isActive(RemoteDebug::INFO)) debugger->printf("(EntsoeApi) Rotating price objects at %lu\n", t); if(today != NULL) delete today; if(tomorrow != NULL) { today = tomorrow; diff --git a/lib/SvelteUi/app/src/App.svelte b/lib/SvelteUi/app/src/App.svelte index 63d4d19f..785b1688 100644 --- a/lib/SvelteUi/app/src/App.svelte +++ b/lib/SvelteUi/app/src/App.svelte @@ -64,6 +64,6 @@ {#if sysinfo.upgrading} {:else if sysinfo.booting} - + {/if} diff --git a/lib/SvelteUi/app/src/lib/ConfigurationPanel.svelte b/lib/SvelteUi/app/src/lib/ConfigurationPanel.svelte index 73971c5e..7ccfe51d 100644 --- a/lib/SvelteUi/app/src/lib/ConfigurationPanel.svelte +++ b/lib/SvelteUi/app/src/lib/ConfigurationPanel.svelte @@ -195,7 +195,7 @@
{#if configuration.p.e && sysinfo.chip != 'esp8266'} -
+
{/if}
diff --git a/lib/SvelteUi/src/AmsWebServer.cpp b/lib/SvelteUi/src/AmsWebServer.cpp index 47a17e18..8631a640 100644 --- a/lib/SvelteUi/src/AmsWebServer.cpp +++ b/lib/SvelteUi/src/AmsWebServer.cpp @@ -1830,9 +1830,9 @@ void AmsWebServer::configFileDownload() { if(ds != NULL) { DayDataPoints day = ds->getDayData(); - server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("dayplot %d %lld %lu %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"), + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("dayplot %d %lu %lu %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"), day.version, - (int64_t) day.lastMeterReadTime, + (int32_t) day.lastMeterReadTime, day.activeImport, ds->getHourImport(0), ds->getHourImport(1), @@ -1892,9 +1892,9 @@ void AmsWebServer::configFileDownload() { } MonthDataPoints month = ds->getMonthData(); - server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("monthplot %d %lld %lu %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"), + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("monthplot %d %lu %lu %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"), month.version, - (int64_t) month.lastMeterReadTime, + (int32_t) month.lastMeterReadTime, month.activeImport, ds->getDayImport(1), ds->getDayImport(2), diff --git a/src/AmsToMqttBridge.ino b/src/AmsToMqttBridge.ino index dcbc65fb..4fdcff06 100644 --- a/src/AmsToMqttBridge.ino +++ b/src/AmsToMqttBridge.ino @@ -381,6 +381,7 @@ void setup() { config.ackEnergyAccountingChange(); } ea.setup(&ds, eac); + ea.load(); ea.setEapi(eapi); ws.setup(&config, &gpioConfig, &meterConfig, &meterState, &ds, &ea); @@ -452,9 +453,39 @@ void loop() { wifiReconnectCount = 0; if(!wifiConnected) { wifiConnected = true; - + WiFiConfig wifi; if(config.getWiFiConfig(wifi)) { + #if defined(ESP32) + if(wifi.power >= 195) + WiFi.setTxPower(WIFI_POWER_19_5dBm); + else if(wifi.power >= 190) + WiFi.setTxPower(WIFI_POWER_19dBm); + else if(wifi.power >= 185) + WiFi.setTxPower(WIFI_POWER_18_5dBm); + else if(wifi.power >= 170) + WiFi.setTxPower(WIFI_POWER_17dBm); + else if(wifi.power >= 150) + WiFi.setTxPower(WIFI_POWER_15dBm); + else if(wifi.power >= 130) + WiFi.setTxPower(WIFI_POWER_13dBm); + else if(wifi.power >= 110) + WiFi.setTxPower(WIFI_POWER_11dBm); + else if(wifi.power >= 85) + WiFi.setTxPower(WIFI_POWER_8_5dBm); + else if(wifi.power >= 70) + WiFi.setTxPower(WIFI_POWER_7dBm); + else if(wifi.power >= 50) + WiFi.setTxPower(WIFI_POWER_5dBm); + else if(wifi.power >= 20) + WiFi.setTxPower(WIFI_POWER_2dBm); + else + WiFi.setTxPower(WIFI_POWER_MINUS_1dBm); + #elif defined(ESP8266) + WiFi.setOutputPower(wifi.power / 10.0); + #endif + + WebConfig web; if(config.getWebConfig(web) && web.security > 0) { Debug.setPassword(web.password); @@ -1114,34 +1145,7 @@ void WiFi_connect() { } #endif WiFi.mode(WIFI_STA); - #if defined(ESP32) - if(wifi.power >= 195) - WiFi.setTxPower(WIFI_POWER_19_5dBm); - else if(wifi.power >= 190) - WiFi.setTxPower(WIFI_POWER_19dBm); - else if(wifi.power >= 185) - WiFi.setTxPower(WIFI_POWER_18_5dBm); - else if(wifi.power >= 170) - WiFi.setTxPower(WIFI_POWER_17dBm); - else if(wifi.power >= 150) - WiFi.setTxPower(WIFI_POWER_15dBm); - else if(wifi.power >= 130) - WiFi.setTxPower(WIFI_POWER_13dBm); - else if(wifi.power >= 110) - WiFi.setTxPower(WIFI_POWER_11dBm); - else if(wifi.power >= 85) - WiFi.setTxPower(WIFI_POWER_8_5dBm); - else if(wifi.power >= 70) - WiFi.setTxPower(WIFI_POWER_7dBm); - else if(wifi.power >= 50) - WiFi.setTxPower(WIFI_POWER_5dBm); - else if(wifi.power >= 20) - WiFi.setTxPower(WIFI_POWER_2dBm); - else - WiFi.setTxPower(WIFI_POWER_MINUS_1dBm); - #elif defined(ESP8266) - WiFi.setOutputPower(wifi.power / 10.0); - #endif + if(strlen(wifi.ip) > 0) { IPAddress ip, gw, sn(255,255,255,0), dns1, dns2; ip.fromString(wifi.ip); @@ -1459,7 +1463,7 @@ void MQTT_connect() { #if defined(ESP8266) if(mqttSecureClient) { - debugD("Setting NTP time %lld for secure MQTT connection", epoch); + debugD("Setting NTP time %lu for secure MQTT connection", epoch); mqttSecureClient->setX509Time(epoch); } #endif