diff --git a/examples/HelloWorld/HelloWorld.ino b/examples/HelloWorld/HelloWorld.ino index df4bf7e..d84238a 100644 --- a/examples/HelloWorld/HelloWorld.ino +++ b/examples/HelloWorld/HelloWorld.ino @@ -22,14 +22,27 @@ typedef ESP8266WebServer WEBServer; #include typedef WebServer WEBServer; #endif -#include #include +/* + AC_USE_SPIFFS indicates SPIFFS or LittleFS as available file systems that + will become the AUTOCONNECT_USE_SPIFFS identifier and is exported as showng + the valid file system. After including AutoConnect.h, the Sketch can determine + whether to use FS.h or LittleFS.h by AUTOCONNECT_USE_SPIFFS definition. +*/ +#ifdef AUTOCONNECT_USE_SPIFFS +#include +FS& FlashFS = SPIFFS; +#else +#include +FS& FlashFS = LittleFS; +#endif + #define HELLO_URI "/hello" #define PARAM_STYLE "/style.json" // Declare AutoConnectText with only a value. -// Qualify the Caption by reading style attributes from the SPIFFS style.json file. +// Qualify the Caption by reading style attributes from the style.json file. ACText(Caption, "Hello, world"); //AutoConnectAux for the custom Web page. @@ -54,15 +67,15 @@ String onHello(AutoConnectAux& aux, PageArgument& args) { return String(); } -// Load the element from specified file in SPIFFS. +// Load the element from specified file in the flash on board. void loadParam(const char* fileName) { - SPIFFS.begin(); - File param = SPIFFS.open(fileName, "r"); + Flash.begin(); + File param = FlashFS.open(fileName, "r"); if (param) { ElementJson = param.readString(); param.close(); } - SPIFFS.end(); + FlashFS.end(); } void setup() { diff --git a/examples/mqttRSSI/mqttRSSI.ino b/examples/mqttRSSI/mqttRSSI.ino index d389b31..8862f42 100644 --- a/examples/mqttRSSI/mqttRSSI.ino +++ b/examples/mqttRSSI/mqttRSSI.ino @@ -23,10 +23,23 @@ https://opensource.org/licenses/MIT #include #define GET_CHIPID() ((uint16_t)(ESP.getEfuseMac()>>32)) #endif -#include #include #include +/* + AC_USE_SPIFFS indicates SPIFFS or LittleFS as available file systems that + will become the AUTOCONNECT_USE_SPIFFS identifier and is exported as showng + the valid file system. After including AutoConnect.h, the Sketch can determine + whether to use FS.h or LittleFS.h by AUTOCONNECT_USE_SPIFFS definition. +*/ +#ifdef AUTOCONNECT_USE_SPIFFS +#include +FS& FlashFS = SPIFFS; +#else +#include +FS& FlashFS = LittleFS; +#endif + #define PARAM_FILE "/param.json" #define AUX_SETTING_URI "/mqtt_setting" #define AUX_SAVE_URI "/mqtt_save" @@ -253,7 +266,7 @@ void getParams(AutoConnectAux& aux) { // elements defined in /mqtt_setting JSON. String loadParams(AutoConnectAux& aux, PageArgument& args) { (void)(args); - File param = SPIFFS.open(PARAM_FILE, "r"); + File param = FlashFS.open(PARAM_FILE, "r"); if (param) { if (aux.loadElement(param)) { getParams(aux); @@ -287,7 +300,7 @@ String saveParams(AutoConnectAux& aux, PageArgument& args) { // The entered value is owned by AutoConnectAux of /mqtt_setting. // To retrieve the elements of /mqtt_setting, it is necessary to get // the AutoConnectAux object of /mqtt_setting. - File param = SPIFFS.open(PARAM_FILE, "w"); + File param = FlashFS.open(PARAM_FILE, "w"); mqtt_setting.saveElement(param, { "mqttserver", "channelid", "userkey", "apikey", "uniqueid", "period", "hostname" }); param.close(); @@ -352,7 +365,7 @@ void setup() { delay(1000); Serial.begin(115200); Serial.println(); - SPIFFS.begin(); + FlashFS.begin(); if (portal.load(FPSTR(AUX_mqtt_setting))) { AutoConnectAux& mqtt_setting = *portal.aux(AUX_SETTING_URI); diff --git a/examples/mqttRSSI_FS/mqttRSSI_FS.ino b/examples/mqttRSSI_FS/mqttRSSI_FS.ino index 1fa1f9f..f736190 100644 --- a/examples/mqttRSSI_FS/mqttRSSI_FS.ino +++ b/examples/mqttRSSI_FS/mqttRSSI_FS.ino @@ -29,10 +29,23 @@ #include #define GET_CHIPID() ((uint16_t)(ESP.getEfuseMac()>>32)) #endif -#include #include #include +/* + AC_USE_SPIFFS indicates SPIFFS or LittleFS as available file systems that + will become the AUTOCONNECT_USE_SPIFFS identifier and is exported as showng + the valid file system. After including AutoConnect.h, the Sketch can determine + whether to use FS.h or LittleFS.h by AUTOCONNECT_USE_SPIFFS definition. +*/ +#ifdef AUTOCONNECT_USE_SPIFFS +#include +FS& FlashFS = SPIFFS; +#else +#include +FS& FlashFS = LittleFS; +#endif + #define PARAM_FILE "/param.json" #define AUX_MQTTSETTING "/mqtt_setting" #define AUX_MQTTSAVE "/mqtt_save" @@ -110,7 +123,7 @@ int getStrength(uint8_t points) { String loadParams(AutoConnectAux& aux, PageArgument& args) { (void)(args); - File param = SPIFFS.open(PARAM_FILE, "r"); + File param = FlashFS.open(PARAM_FILE, "r"); if (param) { aux.loadElement(param); param.close(); @@ -144,7 +157,7 @@ String saveParams(AutoConnectAux& aux, PageArgument& args) { // The entered value is owned by AutoConnectAux of /mqtt_setting. // To retrieve the elements of /mqtt_setting, it is necessary to get // the AutoConnectAux object of /mqtt_setting. - File param = SPIFFS.open(PARAM_FILE, "w"); + File param = FlashFS.open(PARAM_FILE, "w"); portal.aux("/mqtt_setting")->saveElement(param, { "mqttserver", "channelid", "userkey", "apikey", "period", "uniqueid", "hostname" }); param.close(); @@ -205,17 +218,17 @@ void handleClearChannel() { webServer.client().stop(); } -// Load AutoConnectAux JSON from SPIFFS. +// Load AutoConnectAux JSON from the flash on the board. bool loadAux(const String auxName) { bool rc = false; String fn = auxName + ".json"; - File fs = SPIFFS.open(fn.c_str(), "r"); + File fs = FlashFS.open(fn.c_str(), "r"); if (fs) { rc = portal.load(fs); fs.close(); } else - Serial.println("SPIFFS open failed: " + fn); + Serial.println("Filesystem open failed: " + fn); return rc; } diff --git a/examples/mqttRSSI_NA/mqttRSSI_NA.ino b/examples/mqttRSSI_NA/mqttRSSI_NA.ino index 9ffa751..24101ea 100644 --- a/examples/mqttRSSI_NA/mqttRSSI_NA.ino +++ b/examples/mqttRSSI_NA/mqttRSSI_NA.ino @@ -23,10 +23,23 @@ https://opensource.org/licenses/MIT #include #define GET_CHIPID() ((uint16_t)(ESP.getEfuseMac()>>32)) #endif -#include #include #include +/* + AC_USE_SPIFFS indicates SPIFFS or LittleFS as available file systems that + will become the AUTOCONNECT_USE_SPIFFS identifier and is exported as showng + the valid file system. After including AutoConnect.h, the Sketch can determine + whether to use FS.h or LittleFS.h by AUTOCONNECT_USE_SPIFFS definition. +*/ +#ifdef AUTOCONNECT_USE_SPIFFS +#include +FS& FlashFS = SPIFFS; +#else +#include +FS& FlashFS = LittleFS; +#endif + #define PARAM_FILE "/param.json" #define AUX_SETTING_URI "/mqtt_setting" #define AUX_SAVE_URI "/mqtt_save" @@ -214,7 +227,7 @@ void setup() { delay(1000); Serial.begin(115200); Serial.println(); - SPIFFS.begin(); + FlashFS.begin(); if (uniqueid.checked) { config.apid = String("ESP") + "-" + String(GET_CHIPID(), HEX);