diff --git a/RFLink/5_Plugin.cpp b/RFLink/5_Plugin.cpp index 990a20dc..a68f3902 100644 --- a/RFLink/5_Plugin.cpp +++ b/RFLink/5_Plugin.cpp @@ -9,9 +9,15 @@ #include "RFLink.h" #include "2_Signal.h" #include "5_Plugin.h" -#include //used to store current plugins states -#include // To save MQTT parameters +#ifdef AUTOCONNECT_ENABLED +#include "9_AutoConnect.h" +#ifdef ESP8266 +#include // To save plugins parameters #include +#elif ESP32 +#include +#endif +#endif boolean (*Plugin_ptr[PLUGIN_MAX])(byte, char *); // Receive plugins byte Plugin_id[PLUGIN_MAX]; @@ -546,7 +552,6 @@ void PluginInit(void) Plugin_ptr[x] = 0; Plugin_id[x] = 0; Plugin_State[x] = P_Enabled; - //EEPROM.get(x, Plugin_State[x]); } x = 0; @@ -1310,47 +1315,37 @@ void PluginInit(void) // read config file to desactivated protocols #ifdef AUTOCONNECT_ENABLED - Serial.println("mounting FS..."); - if (SPIFFS.begin()) + SPIFFS.begin(); + Serial.print(PROTOCOL_FILE); + File configFile = SPIFFS.open(PROTOCOL_FILE, "r"); + if (configFile) { - Serial.println("mounted file system"); - if (SPIFFS.exists("/protocols.json")) + StaticJsonDocument<6400> doc; + if (deserializeJson(doc, configFile)) + { + Serial.println(F(" failed to load")); + } + else { - //file exists, reading and loading - Serial.println("reading protocols file"); - File configFile = SPIFFS.open("/protocols.json", "r"); - if (configFile) + for (x = 0; x < PLUGIN_MAX; x++) { - Serial.println("opened protocols file"); - size_t size = configFile.size(); - if (size == 0) - { - Serial.println("History file empty"); - } - else - { - StaticJsonDocument<6400> doc; - DeserializationError error = deserializeJson(doc, configFile); - if (error) - { - Serial.println(F("Failed to read file, using default configuration")); - } - - - for (x = 0; x < PLUGIN_MAX; x++) - { - if (doc[x][String(Plugin_id[x])] == 0) - { - Plugin_State[x] = P_Disabled; - } - } - configFile.close(); - - } + if (doc[x][String(Plugin_id[x])] == 0) + Plugin_State[x] = P_Disabled; } + Serial.println(F(" loaded")); } + configFile.close(); + } + else + { + Serial.println(F(" open+r failed")); +#ifdef ESP32 + Serial.println(F("If you get error as 'SPIFFS: mount failed, -10025', Please modify with 'SPIFFS.begin(true)'.")); +#endif // ESP32 } + SPIFFS.end(); + #endif // AUTOCONNECT_ENABLED // Initialiseer alle plugins door aanroep met verwerkingsparameter PLUGIN_INIT diff --git a/RFLink/9_AutoConnect.cpp b/RFLink/9_AutoConnect.cpp index c0416ec8..19258c4f 100644 --- a/RFLink/9_AutoConnect.cpp +++ b/RFLink/9_AutoConnect.cpp @@ -6,30 +6,25 @@ // ************************************* // #include -#include #include "RFLink.h" +#ifdef AUTOCONNECT_ENABLED + #include "4_Display.h" // To allow displaying the last message #include "5_Plugin.h" #include "6_WiFi_MQTT.h" #include "9_AutoConnect.h" -#ifdef AUTOCONNECT_ENABLED - #ifdef ESP8266 #include #include -//#include // Replace with WebServer.h for ESP32 -// #include typedef ESP8266WebServer WebServer; +#include // To save plugins parameters +#include #elif ESP32 #include -//#include #include #include typedef WebServer WebServer; #endif - -//#include // To acces Flash Memory -#include // To save MQTT parameters #include AutoConnect portal; @@ -54,22 +49,21 @@ String saveParams(AutoConnectAux &aux, PageArgument &args); void rootPage() { - WebServer &webServer = portal.host(); if (webServer.hasArg("BtnSave")) { // On n'enregistre les values que si ce n'est pas le bouton "test" qui a été appuyé // === Debug Part === - String message = "Number of args received: "; - message += webServer.args(); //Get number of parameters - message += "\n"; //Add a new line - for (int i = 0; i < webServer.args(); i++) - { - message += "Arg nº" + (String)i + " – > "; //Include the current iteration value - message += webServer.argName(i) + ": "; //Get the name of the parameter - message += webServer.arg(i) + "\n"; //Get the value of the parameter - } - Serial.println(message); + // String message = "Number of args received: "; + // message += webServer.args(); //Get number of parameters + // message += "\n"; //Add a new line + // for (int i = 0; i < webServer.args(); i++) + // { + // message += "Arg nº" + (String)i + " – > "; //Include the current iteration value + // message += webServer.argName(i) + ": "; //Get the name of the parameter + // message += webServer.arg(i) + "\n"; //Get the value of the parameter + // } + // Serial.println(message); // ================== //const int capacity = JSON_ARRAY_SIZE(254) + 2 * JSON_OBJECT_SIZE(2); @@ -98,15 +92,20 @@ void rootPage() } } - File configFile = SPIFFS.open("/protocols.json", "w"); + SPIFFS.begin(); + File configFile = SPIFFS.open(PROTOCOL_FILE, "w"); + Serial.print(PROTOCOL_FILE); + String configString; serializeJson(doc, configString); configFile.print(configString); // === Debug Part === - Serial.println(configString); + // Serial.println(configString); // ================== + Serial.println(F(" saved")); configFile.close(); + SPIFFS.end(); } // This is the Home Page - Choose theme here : https://www.bootstrapcdn.com/bootswatch/?theme @@ -451,7 +450,9 @@ String saveParams(AutoConnectAux &aux, PageArgument &args) echo.value += Adv_Power; echo.value += F("
"); +#ifdef MQTT_ENABLED setup_MQTT(); // Reload settings +#endif return String(""); } diff --git a/RFLink/9_AutoConnect.h b/RFLink/9_AutoConnect.h index 81d46ab1..b7717866 100644 --- a/RFLink/9_AutoConnect.h +++ b/RFLink/9_AutoConnect.h @@ -51,6 +51,7 @@ // Adds MQTT tab to Autoconnect #define PARAM_FILE "/settings.json" +#define PROTOCOL_FILE "/protocols.json" #define AUX_SETTING_URI "/settings" #define AUX_SAVE_URI "/settings_save" //#define AUX_CLEAR_URI "/settings_clear"