diff --git a/include/configuration.h b/include/configuration.h index b59a713..b961fc4 100644 --- a/include/configuration.h +++ b/include/configuration.h @@ -194,13 +194,13 @@ public: REMOTE_MANAGEMENT remoteManagement; MQTT mqtt; + void setup(); void setDefaultValues(); bool writeFile(); - Configuration(); private: bool readFile(); String _filePath; }; -#endif \ No newline at end of file +#endif diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 0fd5d11..14c1854 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -101,6 +101,7 @@ String firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seven void setup() { Serial.begin(115200); + Config.setup(); POWER_Utils::setup(); Utils::setupDisplay(); LoRa_Utils::setup(); @@ -217,4 +218,4 @@ void loop() { Utils::checkRebootTime(); Utils::checkSleepByLowBatteryVoltage(1); } -} \ No newline at end of file +} diff --git a/src/configuration.cpp b/src/configuration.cpp index adbcc3b..7d9715c 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -25,11 +25,29 @@ bool shouldSleepStop = true; +void Configuration::setup() { + if (!SPIFFS.begin(false)) { + Serial.println("SPIFFS Mount Failed"); + return; + } else { + Serial.println("SPIFFS Mounted"); + } + + bool exists = SPIFFS.exists("/igate_conf.json"); + if (!exists) { + setDefaultValues(); + writeFile(); + delay(1000); + ESP.restart(); + } + + readFile(); +} bool Configuration::writeFile() { Serial.println("Saving configuration..."); - StaticJsonDocument<3584> data; + DynamicJsonDocument data(3584); File configFile = SPIFFS.open("/igate_conf.json", "w"); if (!configFile) { @@ -539,22 +557,3 @@ void Configuration::setDefaultValues() { Serial.println("New Data Created... All is Written!"); } - -Configuration::Configuration() { - if (!SPIFFS.begin(false)) { - Serial.println("SPIFFS Mount Failed"); - return; - } else { - Serial.println("SPIFFS Mounted"); - } - - bool exists = SPIFFS.exists("/igate_conf.json"); - if (!exists) { - setDefaultValues(); - writeFile(); - delay(1000); - ESP.restart(); - } - - readFile(); -} \ No newline at end of file