Some cleanup

This commit is contained in:
Gunnar Skjold
2024-05-23 22:20:01 +02:00
parent 3b155d78b1
commit 7ad97daf86
8 changed files with 20 additions and 91 deletions

View File

@@ -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();

View File

@@ -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);

View File

@@ -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";

View File

@@ -33,7 +33,11 @@
#include <HTTPClient.h>
#include <HTTPUpdate.h>
#include <ESP32SSDP.h>
#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;

View File

@@ -1,4 +0,0 @@
{
"d": %d,
"v": %.2f
}

View File

@@ -1,7 +0,0 @@
{
"i" : %d,
"a" : "%s",
"n" : "%s",
"c" : %d,
"v" : %.1f
},

View File

@@ -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
);