From 7ad97daf86da7d2eb0f8bbe68ddd4d382bb39e75 Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Thu, 23 May 2024 22:20:01 +0200 Subject: [PATCH] Some cleanup --- .../include/AmsConfiguration.h | 7 --- lib/AmsConfiguration/src/AmsConfiguration.cpp | 58 ------------------- lib/SvelteUi/include/AmsWebHeaders.h | 1 - lib/SvelteUi/include/AmsWebServer.h | 8 ++- lib/SvelteUi/json/peak.json | 4 -- lib/SvelteUi/json/tempsensor.json | 7 --- lib/SvelteUi/src/AmsWebServer.cpp | 10 ++-- src/AmsToMqttBridge.cpp | 16 +++-- 8 files changed, 20 insertions(+), 91 deletions(-) delete mode 100644 lib/SvelteUi/json/peak.json delete mode 100644 lib/SvelteUi/json/tempsensor.json diff --git a/lib/AmsConfiguration/include/AmsConfiguration.h b/lib/AmsConfiguration/include/AmsConfiguration.h index e0e9360d..218f556a 100644 --- a/lib/AmsConfiguration/include/AmsConfiguration.h +++ b/lib/AmsConfiguration/include/AmsConfiguration.h @@ -214,11 +214,6 @@ struct EnergyAccountingConfig { uint8_t hours; }; // 21 -struct EnergyAccountingConfig101 { - uint8_t thresholds[10]; - uint8_t hours; -}; // 11 - struct UiConfig { uint8_t showImport; uint8_t showExport; @@ -354,8 +349,6 @@ private: bool sysChanged = false, networkChanged, mqttChanged, meterChanged = true, ntpChanged = true, priceChanged = false, energyAccountingChanged = true, cloudChanged = true, uiLanguageChanged = false; - bool relocateConfig101(); // 2.2.0 through 2.2.8 - bool relocateConfig102(); // 2.2.9 through 2.2.11 bool relocateConfig103(); // 2.2.12, until, but not including 2.3 void saveToFs(); diff --git a/lib/AmsConfiguration/src/AmsConfiguration.cpp b/lib/AmsConfiguration/src/AmsConfiguration.cpp index 71ecda91..ca84f164 100644 --- a/lib/AmsConfiguration/src/AmsConfiguration.cpp +++ b/lib/AmsConfiguration/src/AmsConfiguration.cpp @@ -948,22 +948,6 @@ bool AmsConfiguration::hasConfig() { } } else { switch(configVersion) { - case 101: - configVersion = -1; // Prevent loop - if(relocateConfig101()) { - configVersion = 102; - } else { - configVersion = 0; - return false; - } - case 102: - configVersion = -1; // Prevent loop - if(relocateConfig102()) { - configVersion = 103; - } else { - configVersion = 0; - return false; - } case 103: configVersion = -1; // Prevent loop if(relocateConfig103()) { @@ -986,48 +970,6 @@ int AmsConfiguration::getConfigVersion() { return configVersion; } -bool AmsConfiguration::relocateConfig101() { - EEPROM.begin(EEPROM_SIZE); - - EnergyAccountingConfig config; - EnergyAccountingConfig101 config101; - EEPROM.get(CONFIG_ENERGYACCOUNTING_START_103, config101); - for(uint8_t i = 0; i < 9; i++) { - config.thresholds[i] = config101.thresholds[i]; - } - config.thresholds[9] = 0xFFFF; - config.hours = config101.hours; - EEPROM.put(CONFIG_ENERGYACCOUNTING_START_103, config); - - EEPROM.put(EEPROM_CONFIG_ADDRESS, 102); - bool ret = EEPROM.commit(); - EEPROM.end(); - return ret; -} - -bool AmsConfiguration::relocateConfig102() { - EEPROM.begin(EEPROM_SIZE); - - GpioConfig103 gpioConfig; - EEPROM.get(CONFIG_GPIO_START_103, gpioConfig); - gpioConfig.hanPinPullup = true; - EEPROM.put(CONFIG_GPIO_START_103, gpioConfig); - - HomeAssistantConfig haconf; - clearHomeAssistantConfig(haconf); - EEPROM.put(CONFIG_HA_START_103, haconf); - - PriceServiceConfig entsoe; - EEPROM.get(CONFIG_ENTSOE_START_103, entsoe); - entsoe.unused2 = 0; - EEPROM.put(CONFIG_ENTSOE_START_103, entsoe); - - EEPROM.put(EEPROM_CONFIG_ADDRESS, 103); - bool ret = EEPROM.commit(); - EEPROM.end(); - return ret; -} - bool AmsConfiguration::relocateConfig103() { EEPROM.begin(EEPROM_SIZE); diff --git a/lib/SvelteUi/include/AmsWebHeaders.h b/lib/SvelteUi/include/AmsWebHeaders.h index 8295577f..f49634b1 100644 --- a/lib/SvelteUi/include/AmsWebHeaders.h +++ b/lib/SvelteUi/include/AmsWebHeaders.h @@ -13,7 +13,6 @@ static const char HEADER_LOCATION[] PROGMEM = "Location"; static const char CACHE_CONTROL_NO_CACHE[] PROGMEM = "no-cache, no-store, must-revalidate"; static const char CONTENT_ENCODING_GZIP[] PROGMEM = "gzip"; -static const char CACHE_1HR[] PROGMEM = "public, max-age=3600"; static const char CACHE_1DA[] PROGMEM = "public, max-age=86400"; static const char CACHE_1MO[] PROGMEM = "public, max-age=2630000"; static const char CACHE_1YR[] PROGMEM = "public, max-age=31536000"; diff --git a/lib/SvelteUi/include/AmsWebServer.h b/lib/SvelteUi/include/AmsWebServer.h index f8553c24..2f7e8dc5 100644 --- a/lib/SvelteUi/include/AmsWebServer.h +++ b/lib/SvelteUi/include/AmsWebServer.h @@ -33,7 +33,11 @@ #include #include #include + #if defined(CONFIG_IDF_TARGET_ESP32C3) + #warning "Cloud disabled" + #else #include "CloudConnector.h" + #endif #else #warning "Unsupported board type" #endif @@ -45,7 +49,7 @@ public: AmsWebServer(uint8_t* buf, RemoteDebug* Debug, HwTools* hw, ResetDataContainer* rdc); void setup(AmsConfiguration*, GpioConfig*, AmsData*, AmsDataStorage*, EnergyAccounting*, RealtimePlot*); void loop(); - #if defined(ESP32) + #if defined(_CLOUDCONNECTOR_H) void setCloud(CloudConnector* cloud); #endif void setTimezone(Timezone* tz); @@ -76,7 +80,7 @@ private: RealtimePlot* rtp = NULL; AmsMqttHandler* mqttHandler = NULL; ConnectionHandler* ch = NULL; - #if defined(ESP32) + #if defined(_CLOUDCONNECTOR_H) CloudConnector* cloud = NULL; #endif bool uploading = false; diff --git a/lib/SvelteUi/json/peak.json b/lib/SvelteUi/json/peak.json deleted file mode 100644 index 7f58d14c..00000000 --- a/lib/SvelteUi/json/peak.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "d": %d, - "v": %.2f -} \ No newline at end of file diff --git a/lib/SvelteUi/json/tempsensor.json b/lib/SvelteUi/json/tempsensor.json deleted file mode 100644 index 573b756c..00000000 --- a/lib/SvelteUi/json/tempsensor.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "i" : %d, - "a" : "%s", - "n" : "%s", - "c" : %d, - "v" : %.1f -}, \ No newline at end of file diff --git a/lib/SvelteUi/src/AmsWebServer.cpp b/lib/SvelteUi/src/AmsWebServer.cpp index 31aba62e..e4344d78 100644 --- a/lib/SvelteUi/src/AmsWebServer.cpp +++ b/lib/SvelteUi/src/AmsWebServer.cpp @@ -15,11 +15,9 @@ #include "html/index_js.h" #include "html/favicon_svg.h" #include "html/data_json.h" -#include "html/tempsensor_json.h" #include "html/response_json.h" #include "html/sysinfo_json.h" #include "html/tariff_json.h" -#include "html/peak_json.h" #include "html/conf_general_json.h" #include "html/conf_meter_json.h" #include "html/conf_wifi_json.h" @@ -168,7 +166,7 @@ void AmsWebServer::setup(AmsConfiguration* config, GpioConfig* gpioConfig, AmsDa mqttEnabled = strlen(mqttConfig.host) > 0; } -#if defined(ESP32) +#if defined(_CLOUDCONNECTOR_H) void AmsWebServer::setCloud(CloudConnector* cloud) { this->cloud = cloud; } @@ -705,7 +703,7 @@ void AmsWebServer::temperatureJson() { if(data == NULL) continue; char* pos = buf+strlen(buf); - snprintf_P(pos, 72, TEMPSENSOR_JSON, + snprintf_P(pos, 72, PSTR("{\"i\":%d,\"a\":\"%s\",\"n\":\"%s\",\"c\":%d,\"v\":%.1f},"), i, toHex(data->address, 8).c_str(), "", @@ -1098,7 +1096,7 @@ void AmsWebServer::translationsJson() { void AmsWebServer::cloudkeyJson() { if(!checkSecurity(1)) return; - #if defined(ESP32) + #if defined(_CLOUDCONNECTOR_H) if(cloud == NULL) notFound(); @@ -2004,7 +2002,7 @@ void AmsWebServer::tariffJson() { String peaks; for(uint8_t x = 0;x < min((uint8_t) 5, eac->hours); x++) { EnergyAccountingPeak peak = ea->getPeak(x+1); - int len = snprintf_P(buf, BufferSize, PEAK_JSON, + int len = snprintf_P(buf, BufferSize, PSTR("{\"d\":%d,\"v\":%.2f}"), peak.day, peak.value / 100.0 ); diff --git a/src/AmsToMqttBridge.cpp b/src/AmsToMqttBridge.cpp index a89a0968..cf956837 100644 --- a/src/AmsToMqttBridge.cpp +++ b/src/AmsToMqttBridge.cpp @@ -23,8 +23,12 @@ ADC_MODE(ADC_VCC); #include "Update.h" #include #include +#if defined(CONFIG_IDF_TARGET_ESP32C3) +#warning "Cloud disabled" +#else #include "CloudConnector.h" #endif +#endif #define WDT_TIMEOUT 120 @@ -159,7 +163,7 @@ bool ntpEnabled = false; bool mdnsEnabled = false; AmsDataStorage ds(&Debug); -#if defined(ESP32) +#if defined(_CLOUDCONNECTOR_H) CloudConnector *cloud = NULL; __NOINIT_ATTR EnergyAccountingRealtimeData rtd; #else @@ -667,7 +671,7 @@ void loop() { } } - #if defined(ESP32) + #if defined(_CLOUDCONNECTOR_H) if(config.isCloudChanged()) { CloudConfig cc; if(config.getCloudConfig(cc) && cc.enabled) { @@ -919,7 +923,7 @@ void handleEnergyAccountingChanged() { config.getEnergyAccountingConfig(*eac); ea.setup(&ds, eac); config.ackEnergyAccountingChange(); - #if defined(ESP32) + #if defined(_CLOUDCONNECTOR_H) if(cloud != NULL) { cloud->setEnergyAccountingConfig(*eac); } @@ -1060,7 +1064,7 @@ void handlePriceService(unsigned long now) { ps = new PriceService(&Debug); ea.setPriceService(ps); ws.setPriceService(ps); - #if defined(ESP32) + #if defined(_CLOUDCONNECTOR_H) if(cloud != NULL) { cloud->setPriceConfig(price); } @@ -1179,7 +1183,7 @@ void connectToNetwork() { } ch->connect(network, sysConfig); ws.setConnectionHandler(ch); - #if defined(ESP32) + #if defined(_CLOUDCONNECTOR_H) if(cloud != NULL) cloud->setConnectionHandler(ch); #endif @@ -1339,7 +1343,7 @@ void handleDataSuccess(AmsData* data) { if(tm.Minute == 0 && data->getListType() >= 3) { debugV_P(PSTR(" using actual data")); saveData = ds.update(data); - #if defined(ESP32) + #if defined(_CLOUDCONNECTOR_H) if(saveData && cloud != NULL) cloud->forceUpdate(); #endif } else if(tm.Minute == 1) {