Support LittleFS

enhance/v120
Hieromon Ikasamo 5 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> #include <SPIFFS.h>
typedef WebServer WEBServer; typedef WebServer WEBServer;
#endif #endif
#include <FS.h>
#include <AutoConnect.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 HELLO_URI "/hello"
#define PARAM_STYLE "/style.json" #define PARAM_STYLE "/style.json"
// Declare AutoConnectText with only a value. // 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"); ACText(Caption, "Hello, world");
//AutoConnectAux for the custom Web page. //AutoConnectAux for the custom Web page.
@ -54,15 +67,15 @@ String onHello(AutoConnectAux& aux, PageArgument& args) {
return String(); 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) { void loadParam(const char* fileName) {
SPIFFS.begin(); Flash.begin();
File param = SPIFFS.open(fileName, "r"); File param = FlashFS.open(fileName, "r");
if (param) { if (param) {
ElementJson = param.readString(); ElementJson = param.readString();
param.close(); param.close();
} }
SPIFFS.end(); FlashFS.end();
} }
void setup() { void setup() {

@ -23,10 +23,23 @@ https://opensource.org/licenses/MIT
#include <HTTPClient.h> #include <HTTPClient.h>
#define GET_CHIPID() ((uint16_t)(ESP.getEfuseMac()>>32)) #define GET_CHIPID() ((uint16_t)(ESP.getEfuseMac()>>32))
#endif #endif
#include <FS.h>
#include <PubSubClient.h> #include <PubSubClient.h>
#include <AutoConnect.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 PARAM_FILE "/param.json"
#define AUX_SETTING_URI "/mqtt_setting" #define AUX_SETTING_URI "/mqtt_setting"
#define AUX_SAVE_URI "/mqtt_save" #define AUX_SAVE_URI "/mqtt_save"
@ -253,7 +266,7 @@ void getParams(AutoConnectAux& aux) {
// elements defined in /mqtt_setting JSON. // elements defined in /mqtt_setting JSON.
String loadParams(AutoConnectAux& aux, PageArgument& args) { String loadParams(AutoConnectAux& aux, PageArgument& args) {
(void)(args); (void)(args);
File param = SPIFFS.open(PARAM_FILE, "r"); File param = FlashFS.open(PARAM_FILE, "r");
if (param) { if (param) {
if (aux.loadElement(param)) { if (aux.loadElement(param)) {
getParams(aux); getParams(aux);
@ -287,7 +300,7 @@ String saveParams(AutoConnectAux& aux, PageArgument& args) {
// The entered value is owned by AutoConnectAux of /mqtt_setting. // The entered value is owned by AutoConnectAux of /mqtt_setting.
// To retrieve the elements of /mqtt_setting, it is necessary to get // To retrieve the elements of /mqtt_setting, it is necessary to get
// the AutoConnectAux object of /mqtt_setting. // 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" }); mqtt_setting.saveElement(param, { "mqttserver", "channelid", "userkey", "apikey", "uniqueid", "period", "hostname" });
param.close(); param.close();
@ -352,7 +365,7 @@ void setup() {
delay(1000); delay(1000);
Serial.begin(115200); Serial.begin(115200);
Serial.println(); Serial.println();
SPIFFS.begin(); FlashFS.begin();
if (portal.load(FPSTR(AUX_mqtt_setting))) { if (portal.load(FPSTR(AUX_mqtt_setting))) {
AutoConnectAux& mqtt_setting = *portal.aux(AUX_SETTING_URI); AutoConnectAux& mqtt_setting = *portal.aux(AUX_SETTING_URI);

@ -29,10 +29,23 @@
#include <HTTPClient.h> #include <HTTPClient.h>
#define GET_CHIPID() ((uint16_t)(ESP.getEfuseMac()>>32)) #define GET_CHIPID() ((uint16_t)(ESP.getEfuseMac()>>32))
#endif #endif
#include <FS.h>
#include <PubSubClient.h> #include <PubSubClient.h>
#include <AutoConnect.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 PARAM_FILE "/param.json"
#define AUX_MQTTSETTING "/mqtt_setting" #define AUX_MQTTSETTING "/mqtt_setting"
#define AUX_MQTTSAVE "/mqtt_save" #define AUX_MQTTSAVE "/mqtt_save"
@ -110,7 +123,7 @@ int getStrength(uint8_t points) {
String loadParams(AutoConnectAux& aux, PageArgument& args) { String loadParams(AutoConnectAux& aux, PageArgument& args) {
(void)(args); (void)(args);
File param = SPIFFS.open(PARAM_FILE, "r"); File param = FlashFS.open(PARAM_FILE, "r");
if (param) { if (param) {
aux.loadElement(param); aux.loadElement(param);
param.close(); param.close();
@ -144,7 +157,7 @@ String saveParams(AutoConnectAux& aux, PageArgument& args) {
// The entered value is owned by AutoConnectAux of /mqtt_setting. // The entered value is owned by AutoConnectAux of /mqtt_setting.
// To retrieve the elements of /mqtt_setting, it is necessary to get // To retrieve the elements of /mqtt_setting, it is necessary to get
// the AutoConnectAux object of /mqtt_setting. // 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" }); portal.aux("/mqtt_setting")->saveElement(param, { "mqttserver", "channelid", "userkey", "apikey", "period", "uniqueid", "hostname" });
param.close(); param.close();
@ -205,17 +218,17 @@ void handleClearChannel() {
webServer.client().stop(); webServer.client().stop();
} }
// Load AutoConnectAux JSON from SPIFFS. // Load AutoConnectAux JSON from the flash on the board.
bool loadAux(const String auxName) { bool loadAux(const String auxName) {
bool rc = false; bool rc = false;
String fn = auxName + ".json"; String fn = auxName + ".json";
File fs = SPIFFS.open(fn.c_str(), "r"); File fs = FlashFS.open(fn.c_str(), "r");
if (fs) { if (fs) {
rc = portal.load(fs); rc = portal.load(fs);
fs.close(); fs.close();
} }
else else
Serial.println("SPIFFS open failed: " + fn); Serial.println("Filesystem open failed: " + fn);
return rc; return rc;
} }

@ -23,10 +23,23 @@ https://opensource.org/licenses/MIT
#include <HTTPClient.h> #include <HTTPClient.h>
#define GET_CHIPID() ((uint16_t)(ESP.getEfuseMac()>>32)) #define GET_CHIPID() ((uint16_t)(ESP.getEfuseMac()>>32))
#endif #endif
#include <FS.h>
#include <PubSubClient.h> #include <PubSubClient.h>
#include <AutoConnect.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 PARAM_FILE "/param.json"
#define AUX_SETTING_URI "/mqtt_setting" #define AUX_SETTING_URI "/mqtt_setting"
#define AUX_SAVE_URI "/mqtt_save" #define AUX_SAVE_URI "/mqtt_save"
@ -214,7 +227,7 @@ void setup() {
delay(1000); delay(1000);
Serial.begin(115200); Serial.begin(115200);
Serial.println(); Serial.println();
SPIFFS.begin(); FlashFS.begin();
if (uniqueid.checked) { if (uniqueid.checked) {
config.apid = String("ESP") + "-" + String(GET_CHIPID(), HEX); config.apid = String("ESP") + "-" + String(GET_CHIPID(), HEX);

Loading…
Cancel
Save