BREAKING CHANGE: Removed deprecated config parsing method
After this commit its not possible to migrate from the old binary blob config to the new json based config!! If you still running a old version before 12. October please upgrade to a version before this commit. See https://github.com/tbnobody/OpenDTU/discussions/285
This commit is contained in:
parent
5f55414c0a
commit
daf847e7b3
@ -3,8 +3,7 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#define CONFIG_FILENAME "/config.bin"
|
#define CONFIG_FILENAME "/config.json"
|
||||||
#define CONFIG_FILENAME_JSON "/config.json"
|
|
||||||
#define CONFIG_VERSION 0x00011600 // 0.1.22 // make sure to clean all after change
|
#define CONFIG_VERSION 0x00011600 // 0.1.22 // make sure to clean all after change
|
||||||
|
|
||||||
#define WIFI_MAX_SSID_STRLEN 31
|
#define WIFI_MAX_SSID_STRLEN 31
|
||||||
@ -15,7 +14,6 @@
|
|||||||
#define NTP_MAX_TIMEZONE_STRLEN 50
|
#define NTP_MAX_TIMEZONE_STRLEN 50
|
||||||
#define NTP_MAX_TIMEZONEDESCR_STRLEN 50
|
#define NTP_MAX_TIMEZONEDESCR_STRLEN 50
|
||||||
|
|
||||||
#define MQTT_MAX_HOSTNAME_OLD_STRLEN 31
|
|
||||||
#define MQTT_MAX_HOSTNAME_STRLEN 128
|
#define MQTT_MAX_HOSTNAME_STRLEN 128
|
||||||
#define MQTT_MAX_USERNAME_STRLEN 32
|
#define MQTT_MAX_USERNAME_STRLEN 32
|
||||||
#define MQTT_MAX_PASSWORD_STRLEN 32
|
#define MQTT_MAX_PASSWORD_STRLEN 32
|
||||||
@ -54,7 +52,6 @@ struct CONFIG_T {
|
|||||||
char Ntp_TimezoneDescr[NTP_MAX_TIMEZONEDESCR_STRLEN + 1];
|
char Ntp_TimezoneDescr[NTP_MAX_TIMEZONEDESCR_STRLEN + 1];
|
||||||
|
|
||||||
bool Mqtt_Enabled;
|
bool Mqtt_Enabled;
|
||||||
char Mqtt_Hostname_Short[MQTT_MAX_HOSTNAME_OLD_STRLEN + 1]; // Deprecated but for config compatibility
|
|
||||||
uint Mqtt_Port;
|
uint Mqtt_Port;
|
||||||
char Mqtt_Username[MQTT_MAX_USERNAME_STRLEN + 1];
|
char Mqtt_Username[MQTT_MAX_USERNAME_STRLEN + 1];
|
||||||
char Mqtt_Password[MQTT_MAX_PASSWORD_STRLEN + 1];
|
char Mqtt_Password[MQTT_MAX_PASSWORD_STRLEN + 1];
|
||||||
@ -94,9 +91,6 @@ public:
|
|||||||
CONFIG_T& get();
|
CONFIG_T& get();
|
||||||
|
|
||||||
INVERTER_CONFIG_T* getFreeInverterSlot();
|
INVERTER_CONFIG_T* getFreeInverterSlot();
|
||||||
|
|
||||||
private:
|
|
||||||
bool readJson();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ConfigurationClass Configuration;
|
extern ConfigurationClass Configuration;
|
||||||
@ -12,59 +12,11 @@ CONFIG_T config;
|
|||||||
void ConfigurationClass::init()
|
void ConfigurationClass::init()
|
||||||
{
|
{
|
||||||
memset(&config, 0x0, sizeof(config));
|
memset(&config, 0x0, sizeof(config));
|
||||||
config.Cfg_SaveCount = 0;
|
|
||||||
config.Cfg_Version = CONFIG_VERSION;
|
|
||||||
|
|
||||||
// WiFi Settings
|
|
||||||
strlcpy(config.WiFi_Ssid, WIFI_SSID, sizeof(config.WiFi_Ssid));
|
|
||||||
strlcpy(config.WiFi_Password, WIFI_PASSWORD, sizeof(config.WiFi_Password));
|
|
||||||
config.WiFi_Dhcp = WIFI_DHCP;
|
|
||||||
strlcpy(config.WiFi_Hostname, APP_HOSTNAME, sizeof(config.WiFi_Hostname));
|
|
||||||
|
|
||||||
// NTP Settings
|
|
||||||
strlcpy(config.Ntp_Server, NTP_SERVER, sizeof(config.Ntp_Server));
|
|
||||||
strlcpy(config.Ntp_Timezone, NTP_TIMEZONE, sizeof(config.Ntp_Timezone));
|
|
||||||
strlcpy(config.Ntp_TimezoneDescr, NTP_TIMEZONEDESCR, sizeof(config.Ntp_TimezoneDescr));
|
|
||||||
|
|
||||||
// MqTT Settings
|
|
||||||
config.Mqtt_Enabled = MQTT_ENABLED;
|
|
||||||
strlcpy(config.Mqtt_Hostname, MQTT_HOST, sizeof(config.Mqtt_Hostname));
|
|
||||||
config.Mqtt_Port = MQTT_PORT;
|
|
||||||
strlcpy(config.Mqtt_Username, MQTT_USER, sizeof(config.Mqtt_Username));
|
|
||||||
strlcpy(config.Mqtt_Password, MQTT_PASSWORD, sizeof(config.Mqtt_Password));
|
|
||||||
strlcpy(config.Mqtt_Topic, MQTT_TOPIC, sizeof(config.Mqtt_Topic));
|
|
||||||
config.Mqtt_Retain = MQTT_RETAIN;
|
|
||||||
config.Mqtt_Tls = MQTT_TLS;
|
|
||||||
strlcpy(config.Mqtt_RootCaCert, MQTT_ROOT_CA_CERT, sizeof(config.Mqtt_RootCaCert));
|
|
||||||
strlcpy(config.Mqtt_LwtTopic, MQTT_LWT_TOPIC, sizeof(config.Mqtt_LwtTopic));
|
|
||||||
strlcpy(config.Mqtt_LwtValue_Online, MQTT_LWT_ONLINE, sizeof(config.Mqtt_LwtValue_Online));
|
|
||||||
strlcpy(config.Mqtt_LwtValue_Offline, MQTT_LWT_OFFLINE, sizeof(config.Mqtt_LwtValue_Offline));
|
|
||||||
config.Mqtt_PublishInterval = MQTT_PUBLISH_INTERVAL;
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < INV_MAX_COUNT; i++) {
|
|
||||||
config.Inverter[i].Serial = 0;
|
|
||||||
strlcpy(config.Inverter[i].Name, "", 0);
|
|
||||||
for (uint8_t c = 0; c < INV_MAX_CHAN_COUNT; c++) {
|
|
||||||
config.Inverter[0].MaxChannelPower[c] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
config.Dtu_Serial = DTU_SERIAL;
|
|
||||||
config.Dtu_PollInterval = DTU_POLL_INTERVAL;
|
|
||||||
config.Dtu_PaLevel = DTU_PA_LEVEL;
|
|
||||||
|
|
||||||
config.Mqtt_Hass_Enabled = MQTT_HASS_ENABLED;
|
|
||||||
config.Mqtt_Hass_Expire = MQTT_HASS_EXPIRE;
|
|
||||||
config.Mqtt_Hass_Retain = MQTT_HASS_RETAIN;
|
|
||||||
strlcpy(config.Mqtt_Hass_Topic, MQTT_HASS_TOPIC, sizeof(config.Mqtt_Hass_Topic));
|
|
||||||
config.Mqtt_Hass_IndividualPanels = MQTT_HASS_INDIVIDUALPANELS;
|
|
||||||
|
|
||||||
strlcpy(config.Security_Password, ACCESS_POINT_PASSWORD, sizeof(config.Security_Password));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigurationClass::write()
|
bool ConfigurationClass::write()
|
||||||
{
|
{
|
||||||
File f = LittleFS.open(CONFIG_FILENAME_JSON, "w");
|
File f = LittleFS.open(CONFIG_FILENAME, "w");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -150,30 +102,7 @@ bool ConfigurationClass::write()
|
|||||||
|
|
||||||
bool ConfigurationClass::read()
|
bool ConfigurationClass::read()
|
||||||
{
|
{
|
||||||
if (!LittleFS.exists(CONFIG_FILENAME_JSON)) {
|
File f = LittleFS.open(CONFIG_FILENAME, "r", false);
|
||||||
Serial.println("Converting binary config to json... ");
|
|
||||||
File f = LittleFS.open(CONFIG_FILENAME, "r");
|
|
||||||
if (!f) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
uint8_t* bytes = reinterpret_cast<uint8_t*>(&config);
|
|
||||||
for (unsigned int i = 0; i < sizeof(CONFIG_T); i++) {
|
|
||||||
bytes[i] = f.read();
|
|
||||||
}
|
|
||||||
f.close();
|
|
||||||
write();
|
|
||||||
Serial.println("done");
|
|
||||||
LittleFS.remove(CONFIG_FILENAME);
|
|
||||||
}
|
|
||||||
return readJson();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ConfigurationClass::readJson()
|
|
||||||
{
|
|
||||||
File f = LittleFS.open(CONFIG_FILENAME_JSON, "r", false);
|
|
||||||
if (!f) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
// Deserialize the JSON document
|
// Deserialize the JSON document
|
||||||
@ -285,76 +214,6 @@ bool ConfigurationClass::readJson()
|
|||||||
|
|
||||||
void ConfigurationClass::migrate()
|
void ConfigurationClass::migrate()
|
||||||
{
|
{
|
||||||
if (config.Cfg_Version < 0x00010400) {
|
|
||||||
strlcpy(config.Ntp_Server, NTP_SERVER, sizeof(config.Ntp_Server));
|
|
||||||
strlcpy(config.Ntp_Timezone, NTP_TIMEZONE, sizeof(config.Ntp_Timezone));
|
|
||||||
strlcpy(config.Ntp_TimezoneDescr, NTP_TIMEZONEDESCR, sizeof(config.Ntp_TimezoneDescr));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.Cfg_Version < 0x00010500) {
|
|
||||||
config.Mqtt_Enabled = MQTT_ENABLED;
|
|
||||||
strlcpy(config.Mqtt_Hostname, MQTT_HOST, sizeof(config.Mqtt_Hostname));
|
|
||||||
config.Mqtt_Port = MQTT_PORT;
|
|
||||||
strlcpy(config.Mqtt_Username, MQTT_USER, sizeof(config.Mqtt_Username));
|
|
||||||
strlcpy(config.Mqtt_Password, MQTT_PASSWORD, sizeof(config.Mqtt_Password));
|
|
||||||
strlcpy(config.Mqtt_Topic, MQTT_TOPIC, sizeof(config.Mqtt_Topic));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.Cfg_Version < 0x00010600) {
|
|
||||||
config.Mqtt_Retain = MQTT_RETAIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.Cfg_Version < 0x00010700) {
|
|
||||||
strlcpy(config.Mqtt_LwtTopic, MQTT_LWT_TOPIC, sizeof(config.Mqtt_LwtTopic));
|
|
||||||
strlcpy(config.Mqtt_LwtValue_Online, MQTT_LWT_ONLINE, sizeof(config.Mqtt_LwtValue_Online));
|
|
||||||
strlcpy(config.Mqtt_LwtValue_Offline, MQTT_LWT_OFFLINE, sizeof(config.Mqtt_LwtValue_Offline));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.Cfg_Version < 0x00010800) {
|
|
||||||
for (uint8_t i = 0; i < INV_MAX_COUNT; i++) {
|
|
||||||
config.Inverter[i].Serial = 0;
|
|
||||||
strlcpy(config.Inverter[i].Name, "", 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.Cfg_Version < 0x00010900) {
|
|
||||||
config.Dtu_Serial = DTU_SERIAL;
|
|
||||||
config.Dtu_PollInterval = DTU_POLL_INTERVAL;
|
|
||||||
config.Dtu_PaLevel = DTU_PA_LEVEL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.Cfg_Version < 0x00011000) {
|
|
||||||
config.Mqtt_PublishInterval = MQTT_PUBLISH_INTERVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.Cfg_Version < 0x00011100) {
|
|
||||||
init(); // Config will be completly incompatible after this update
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.Cfg_Version < 0x00011200) {
|
|
||||||
config.Mqtt_Hass_Enabled = MQTT_HASS_ENABLED;
|
|
||||||
config.Mqtt_Hass_Retain = MQTT_HASS_RETAIN;
|
|
||||||
strlcpy(config.Mqtt_Hass_Topic, MQTT_HASS_TOPIC, sizeof(config.Mqtt_Hass_Topic));
|
|
||||||
config.Mqtt_Hass_IndividualPanels = MQTT_HASS_INDIVIDUALPANELS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.Cfg_Version < 0x00011300) {
|
|
||||||
config.Mqtt_Tls = MQTT_TLS;
|
|
||||||
strlcpy(config.Mqtt_RootCaCert, MQTT_ROOT_CA_CERT, sizeof(config.Mqtt_RootCaCert));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.Cfg_Version < 0x00011400) {
|
|
||||||
strlcpy(config.Mqtt_Hostname, config.Mqtt_Hostname_Short, sizeof(config.Mqtt_Hostname_Short));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.Cfg_Version < 0x00011500) {
|
|
||||||
config.Mqtt_Hass_Expire = MQTT_HASS_EXPIRE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.Cfg_Version < 0x00011600) {
|
|
||||||
strlcpy(config.Security_Password, ACCESS_POINT_PASSWORD, sizeof(config.Security_Password));
|
|
||||||
}
|
|
||||||
|
|
||||||
config.Cfg_Version = CONFIG_VERSION;
|
config.Cfg_Version = CONFIG_VERSION;
|
||||||
write();
|
write();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,7 @@ void WebApiConfigClass::onConfigGet(AsyncWebServerRequest* request)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
request->send(LittleFS, CONFIG_FILENAME_JSON, String(), true);
|
request->send(LittleFS, CONFIG_FILENAME, String(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebApiConfigClass::onConfigDelete(AsyncWebServerRequest* request)
|
void WebApiConfigClass::onConfigDelete(AsyncWebServerRequest* request)
|
||||||
@ -96,7 +96,7 @@ void WebApiConfigClass::onConfigDelete(AsyncWebServerRequest* request)
|
|||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
|
|
||||||
LittleFS.remove(CONFIG_FILENAME_JSON);
|
LittleFS.remove(CONFIG_FILENAME);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ void WebApiConfigClass::onConfigUpload(AsyncWebServerRequest* request, String fi
|
|||||||
|
|
||||||
if (!index) {
|
if (!index) {
|
||||||
// open the file on first call and store the file handle in the request object
|
// open the file on first call and store the file handle in the request object
|
||||||
request->_tempFile = LittleFS.open(CONFIG_FILENAME_JSON, "w");
|
request->_tempFile = LittleFS.open(CONFIG_FILENAME, "w");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len) {
|
if (len) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user