Support LittleFS

enhance/v120
Hieromon Ikasamo 4 years ago
parent 3e7b7e0ecf
commit 0c81023981
  1. 25
      examples/HelloWorld/HelloWorld.ino
  2. 21
      examples/mqttRSSI/mqttRSSI.ino
  3. 25
      examples/mqttRSSI_FS/mqttRSSI_FS.ino
  4. 17
      examples/mqttRSSI_NA/mqttRSSI_NA.ino

@ -22,14 +22,27 @@ typedef ESP8266WebServer WEBServer;
#include <SPIFFS.h>
typedef WebServer WEBServer;
#endif
#include <FS.h>
#include <AutoConnect.h>
/*
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.h>
FS& FlashFS = SPIFFS;
#else
#include <LittleFS.h>
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() {

@ -23,10 +23,23 @@ https://opensource.org/licenses/MIT
#include <HTTPClient.h>
#define GET_CHIPID() ((uint16_t)(ESP.getEfuseMac()>>32))
#endif
#include <FS.h>
#include <PubSubClient.h>
#include <AutoConnect.h>
/*
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.h>
FS& FlashFS = SPIFFS;
#else
#include <LittleFS.h>
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);

@ -29,10 +29,23 @@
#include <HTTPClient.h>
#define GET_CHIPID() ((uint16_t)(ESP.getEfuseMac()>>32))
#endif
#include <FS.h>
#include <PubSubClient.h>
#include <AutoConnect.h>
/*
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.h>
FS& FlashFS = SPIFFS;
#else
#include <LittleFS.h>
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;
}

@ -23,10 +23,23 @@ https://opensource.org/licenses/MIT
#include <HTTPClient.h>
#define GET_CHIPID() ((uint16_t)(ESP.getEfuseMac()>>32))
#endif
#include <FS.h>
#include <PubSubClient.h>
#include <AutoConnect.h>
/*
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.h>
FS& FlashFS = SPIFFS;
#else
#include <LittleFS.h>
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);

Loading…
Cancel
Save