Migrate to LittleFS under ESP8266
Make ESP8266 use LittleFS instead of deprecated SPIFFS Make framework use the correct filesystem automatically and handle the call the FS.begin() Change default MQTT keepalive to 60 seconds Fix lodash security issue
This commit is contained in:
@ -1,32 +1,32 @@
|
||||
#include <ESP8266React.h>
|
||||
|
||||
ESP8266React::ESP8266React(AsyncWebServer* server, FS* fs) :
|
||||
ESP8266React::ESP8266React(AsyncWebServer* server) :
|
||||
_featureService(server),
|
||||
_securitySettingsService(server, fs),
|
||||
_wifiSettingsService(server, fs, &_securitySettingsService),
|
||||
_securitySettingsService(server, &ESPFS),
|
||||
_wifiSettingsService(server, &ESPFS, &_securitySettingsService),
|
||||
_wifiScanner(server, &_securitySettingsService),
|
||||
_wifiStatus(server, &_securitySettingsService),
|
||||
_apSettingsService(server, fs, &_securitySettingsService),
|
||||
_apSettingsService(server, &ESPFS, &_securitySettingsService),
|
||||
_apStatus(server, &_securitySettingsService, &_apSettingsService),
|
||||
#if FT_ENABLED(FT_NTP)
|
||||
_ntpSettingsService(server, fs, &_securitySettingsService),
|
||||
_ntpSettingsService(server, &ESPFS, &_securitySettingsService),
|
||||
_ntpStatus(server, &_securitySettingsService),
|
||||
#endif
|
||||
#if FT_ENABLED(FT_OTA)
|
||||
_otaSettingsService(server, fs, &_securitySettingsService),
|
||||
_otaSettingsService(server, &ESPFS, &_securitySettingsService),
|
||||
#endif
|
||||
#if FT_ENABLED(FT_UPLOAD_FIRMWARE)
|
||||
_uploadFirmwareService(server, &_securitySettingsService),
|
||||
#endif
|
||||
#if FT_ENABLED(FT_MQTT)
|
||||
_mqttSettingsService(server, fs, &_securitySettingsService),
|
||||
_mqttSettingsService(server, &ESPFS, &_securitySettingsService),
|
||||
_mqttStatus(server, &_mqttSettingsService, &_securitySettingsService),
|
||||
#endif
|
||||
#if FT_ENABLED(FT_SECURITY)
|
||||
_authenticationService(server, &_securitySettingsService),
|
||||
#endif
|
||||
_restartService(server, &_securitySettingsService),
|
||||
_factoryResetService(server, fs, &_securitySettingsService),
|
||||
_factoryResetService(server, &ESPFS, &_securitySettingsService),
|
||||
_systemStatus(server, &_securitySettingsService) {
|
||||
#ifdef PROGMEM_WWW
|
||||
// Serve static resources from PROGMEM
|
||||
@ -63,7 +63,7 @@ ESP8266React::ESP8266React(AsyncWebServer* server, FS* fs) :
|
||||
// OPTIONS get a straight up 200 response
|
||||
server->onNotFound([](AsyncWebServerRequest* request) {
|
||||
if (request->method() == HTTP_GET) {
|
||||
request->send(SPIFFS, "/www/index.html");
|
||||
request->send(ESPFS, "/www/index.html");
|
||||
} else if (request->method() == HTTP_OPTIONS) {
|
||||
request->send(200);
|
||||
} else {
|
||||
@ -81,6 +81,11 @@ ESP8266React::ESP8266React(AsyncWebServer* server, FS* fs) :
|
||||
}
|
||||
|
||||
void ESP8266React::begin() {
|
||||
#ifdef ESP32
|
||||
ESPFS.begin(true);
|
||||
#elif defined(ESP8266)
|
||||
ESPFS.begin();
|
||||
#endif
|
||||
_wifiSettingsService.begin();
|
||||
_apSettingsService.begin();
|
||||
#if FT_ENABLED(FT_NTP)
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <WiFiScanner.h>
|
||||
#include <WiFiSettingsService.h>
|
||||
#include <WiFiStatus.h>
|
||||
#include <ESPFS.h>
|
||||
|
||||
#ifdef PROGMEM_WWW
|
||||
#include <WWWData.h>
|
||||
@ -35,11 +36,15 @@
|
||||
|
||||
class ESP8266React {
|
||||
public:
|
||||
ESP8266React(AsyncWebServer* server, FS* fs);
|
||||
ESP8266React(AsyncWebServer* server);
|
||||
|
||||
void begin();
|
||||
void loop();
|
||||
|
||||
FS* getFS() {
|
||||
return &ESPFS;
|
||||
}
|
||||
|
||||
SecurityManager* getSecurityManager() {
|
||||
return &_securitySettingsService;
|
||||
}
|
||||
|
7
lib/framework/ESPFS.h
Normal file
7
lib/framework/ESPFS.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifdef ESP32
|
||||
#include <SPIFFS.h>
|
||||
#define ESPFS SPIFFS
|
||||
#elif defined(ESP8266)
|
||||
#include <LittleFS.h>
|
||||
#define ESPFS LittleFS
|
||||
#endif
|
@ -15,7 +15,7 @@ void FactoryResetService::handleRequest(AsyncWebServerRequest* request) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete function assumes that all files are stored flat, within the config directory
|
||||
* Delete function assumes that all files are stored flat, within the config directory.
|
||||
*/
|
||||
void FactoryResetService::factoryReset() {
|
||||
#ifdef ESP32
|
||||
@ -27,7 +27,10 @@ void FactoryResetService::factoryReset() {
|
||||
#elif defined(ESP8266)
|
||||
Dir configDirectory = fs->openDir(FS_CONFIG_DIRECTORY);
|
||||
while (configDirectory.next()) {
|
||||
fs->remove(configDirectory.fileName());
|
||||
String path = FS_CONFIG_DIRECTORY;
|
||||
path.concat("/");
|
||||
path.concat(configDirectory.fileName());
|
||||
fs->remove(path);
|
||||
}
|
||||
#endif
|
||||
RestartService::restartNow();
|
||||
|
@ -31,11 +31,11 @@ void SystemStatus::systemStatus(AsyncWebServerRequest* request) {
|
||||
// TODO - Ideally this class will take an *FS and extract the file system information from there.
|
||||
// ESP8266 and ESP32 do not have feature parity in FS.h which currently makes that difficult.
|
||||
#ifdef ESP32
|
||||
root["fs_total"] = SPIFFS.totalBytes();
|
||||
root["fs_used"] = SPIFFS.usedBytes();
|
||||
root["fs_total"] = ESPFS.totalBytes();
|
||||
root["fs_used"] = ESPFS.usedBytes();
|
||||
#elif defined(ESP8266)
|
||||
FSInfo fs_info;
|
||||
SPIFFS.info(fs_info);
|
||||
ESPFS.info(fs_info);
|
||||
root["fs_total"] = fs_info.totalBytes;
|
||||
root["fs_used"] = fs_info.usedBytes;
|
||||
#endif
|
||||
|
@ -4,17 +4,16 @@
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#include <AsyncTCP.h>
|
||||
#include <SPIFFS.h>
|
||||
#elif defined(ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESPAsyncTCP.h>
|
||||
#include <FS.h>
|
||||
#endif
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <AsyncJson.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <SecurityManager.h>
|
||||
#include <ESPFS.h>
|
||||
|
||||
#define MAX_ESP_STATUS_SIZE 1024
|
||||
#define SYSTEM_STATUS_SERVICE_PATH "/rest/systemStatus"
|
||||
|
Reference in New Issue
Block a user