Fix typo in configuration. Relates to #603
Also increase buffer size to read whole config
This commit is contained in:
parent
20a83fcc89
commit
dc66a82695
@ -4,7 +4,7 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#define CONFIG_FILENAME "/config.json"
|
#define CONFIG_FILENAME "/config.json"
|
||||||
#define CONFIG_VERSION 0x00011700 // 0.1.23 // make sure to clean all after change
|
#define CONFIG_VERSION 0x00011800 // 0.1.24 // make sure to clean all after change
|
||||||
|
|
||||||
#define WIFI_MAX_SSID_STRLEN 31
|
#define WIFI_MAX_SSID_STRLEN 31
|
||||||
#define WIFI_MAX_PASSWORD_STRLEN 64
|
#define WIFI_MAX_PASSWORD_STRLEN 64
|
||||||
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#define DEV_MAX_MAPPING_NAME_STRLEN 63
|
#define DEV_MAX_MAPPING_NAME_STRLEN 63
|
||||||
|
|
||||||
#define JSON_BUFFER_SIZE 6144
|
#define JSON_BUFFER_SIZE 12288
|
||||||
|
|
||||||
struct CHANNEL_CONFIG_T {
|
struct CHANNEL_CONFIG_T {
|
||||||
uint16_t MaxChannelPower;
|
uint16_t MaxChannelPower;
|
||||||
|
|||||||
@ -55,7 +55,7 @@ bool ConfigurationClass::write()
|
|||||||
mqtt["password"] = config.Mqtt_Password;
|
mqtt["password"] = config.Mqtt_Password;
|
||||||
mqtt["topic"] = config.Mqtt_Topic;
|
mqtt["topic"] = config.Mqtt_Topic;
|
||||||
mqtt["retain"] = config.Mqtt_Retain;
|
mqtt["retain"] = config.Mqtt_Retain;
|
||||||
mqtt["publish_invterval"] = config.Mqtt_PublishInterval;
|
mqtt["publish_interval"] = config.Mqtt_PublishInterval;
|
||||||
|
|
||||||
JsonObject mqtt_lwt = mqtt.createNestedObject("lwt");
|
JsonObject mqtt_lwt = mqtt.createNestedObject("lwt");
|
||||||
mqtt_lwt["topic"] = config.Mqtt_LwtTopic;
|
mqtt_lwt["topic"] = config.Mqtt_LwtTopic;
|
||||||
@ -192,7 +192,7 @@ bool ConfigurationClass::read()
|
|||||||
strlcpy(config.Mqtt_Password, mqtt["password"] | MQTT_PASSWORD, sizeof(config.Mqtt_Password));
|
strlcpy(config.Mqtt_Password, mqtt["password"] | MQTT_PASSWORD, sizeof(config.Mqtt_Password));
|
||||||
strlcpy(config.Mqtt_Topic, mqtt["topic"] | MQTT_TOPIC, sizeof(config.Mqtt_Topic));
|
strlcpy(config.Mqtt_Topic, mqtt["topic"] | MQTT_TOPIC, sizeof(config.Mqtt_Topic));
|
||||||
config.Mqtt_Retain = mqtt["retain"] | MQTT_RETAIN;
|
config.Mqtt_Retain = mqtt["retain"] | MQTT_RETAIN;
|
||||||
config.Mqtt_PublishInterval = mqtt["publish_invterval"] | MQTT_PUBLISH_INTERVAL;
|
config.Mqtt_PublishInterval = mqtt["publish_interval"] | MQTT_PUBLISH_INTERVAL;
|
||||||
|
|
||||||
JsonObject mqtt_lwt = mqtt["lwt"];
|
JsonObject mqtt_lwt = mqtt["lwt"];
|
||||||
strlcpy(config.Mqtt_LwtTopic, mqtt_lwt["topic"] | MQTT_LWT_TOPIC, sizeof(config.Mqtt_LwtTopic));
|
strlcpy(config.Mqtt_LwtTopic, mqtt_lwt["topic"] | MQTT_LWT_TOPIC, sizeof(config.Mqtt_LwtTopic));
|
||||||
@ -253,21 +253,21 @@ bool ConfigurationClass::read()
|
|||||||
|
|
||||||
void ConfigurationClass::migrate()
|
void ConfigurationClass::migrate()
|
||||||
{
|
{
|
||||||
|
File f = LittleFS.open(CONFIG_FILENAME, "r", false);
|
||||||
|
if (!f) {
|
||||||
|
MessageOutput.println(F("Failed to open file, cancel migration"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
|
// Deserialize the JSON document
|
||||||
|
DeserializationError error = deserializeJson(doc, f);
|
||||||
|
if (error) {
|
||||||
|
MessageOutput.printf("Failed to read file, cancel migration: %s\r\n", error.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (config.Cfg_Version < 0x00011700) {
|
if (config.Cfg_Version < 0x00011700) {
|
||||||
File f = LittleFS.open(CONFIG_FILENAME, "r", false);
|
|
||||||
if (!f) {
|
|
||||||
MessageOutput.println(F("Failed to open file, cancel migration"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
|
||||||
// Deserialize the JSON document
|
|
||||||
DeserializationError error = deserializeJson(doc, f);
|
|
||||||
if (error) {
|
|
||||||
MessageOutput.println(F("Failed to read file, cancel migration"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonArray inverters = doc["inverters"];
|
JsonArray inverters = doc["inverters"];
|
||||||
for (uint8_t i = 0; i < INV_MAX_COUNT; i++) {
|
for (uint8_t i = 0; i < INV_MAX_COUNT; i++) {
|
||||||
JsonObject inv = inverters[i].as<JsonObject>();
|
JsonObject inv = inverters[i].as<JsonObject>();
|
||||||
@ -279,6 +279,13 @@ void ConfigurationClass::migrate()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.Cfg_Version < 0x00011800) {
|
||||||
|
JsonObject mqtt = doc["mqtt"];
|
||||||
|
config.Mqtt_PublishInterval = mqtt["publish_invterval"];
|
||||||
|
}
|
||||||
|
|
||||||
|
f.close();
|
||||||
|
|
||||||
config.Cfg_Version = CONFIG_VERSION;
|
config.Cfg_Version = CONFIG_VERSION;
|
||||||
write();
|
write();
|
||||||
read();
|
read();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user