1
0
mirror of https://github.com/s00500/ESPUI.git synced 2025-06-14 02:30:41 +00:00

Implement LITTLEFS as requested by @thomastech in #144

Signed-off-by: Lukas Bachschwell <lukas@lbsfilm.at>
This commit is contained in:
2022-01-04 11:35:43 +01:00
parent 3cbae2ff1b
commit e1fe13bac6
6 changed files with 66 additions and 40 deletions

View File

@ -15,7 +15,7 @@
uint16_t Control::idCounter = 1;
// ################# Spiffs functions
// ################# LITTLEFS functions
#if defined(ESP32)
void listDir(const char* dirname, uint8_t levels)
{
@ -27,7 +27,7 @@ void listDir(const char* dirname, uint8_t levels)
#endif
#if defined(ESP32)
File root = SPIFFS.open(dirname);
File root = LITTLEFS.open(dirname);
#else
File root = LittleFS.open(dirname);
#endif
@ -115,9 +115,9 @@ void listDir(const char* dirname, uint8_t levels)
void ESPUIClass::list()
{
#if defined(ESP32)
if (!SPIFFS.begin())
if (!LITTLEFS.begin())
{
Serial.println(F("SPIFFS Mount Failed"));
Serial.println(F("LITTLEFS Mount Failed"));
return;
}
#else
@ -131,8 +131,8 @@ void ESPUIClass::list()
listDir("/", 1);
#if defined(ESP32)
Serial.println(SPIFFS.totalBytes());
Serial.println(SPIFFS.usedBytes());
Serial.println(LITTLEFS.totalBytes());
Serial.println(LITTLEFS.usedBytes());
#else
FSInfo fs_info;
@ -147,7 +147,7 @@ void ESPUIClass::list()
void deleteFile(const char* path)
{
#if defined(ESP32)
bool exists = SPIFFS.exists(path);
bool exists = LITTLEFS.exists(path);
#else
bool exists = LittleFS.exists(path);
#endif
@ -172,7 +172,7 @@ void deleteFile(const char* path)
#endif
#if defined(ESP32)
bool didRemove = SPIFFS.remove(path);
bool didRemove = LITTLEFS.remove(path);
#else
bool didRemove = LittleFS.remove(path);
#endif
@ -206,7 +206,7 @@ void writeFile(const char* path, const char* data)
#endif
#if defined(ESP32)
File file = SPIFFS.open(path, FILE_WRITE);
File file = LITTLEFS.open(path, FILE_WRITE);
#else
File file = LittleFS.open(path, FILE_WRITE);
#endif
@ -269,7 +269,7 @@ void writeFile(const char* path, const char* data)
file.close();
}
// end Spiffs functions
// end LITTLEFS functions
void ESPUIClass::prepareFileSystem()
{
@ -283,14 +283,14 @@ void ESPUIClass::prepareFileSystem()
#endif
#if defined(ESP32)
SPIFFS.format();
LITTLEFS.format();
if (!SPIFFS.begin(true))
if (!LITTLEFS.begin(true))
{
#if defined(DEBUG_ESPUI)
if (this->verbosity)
{
Serial.println(F("SPIFFS Mount Failed"));
Serial.println(F("LITTLEFS Mount Failed"));
}
#endif
@ -301,7 +301,7 @@ void ESPUIClass::prepareFileSystem()
if (this->verbosity)
{
listDir("/", 1);
Serial.println(F("SPIFFS Mount ESP32 Done"));
Serial.println(F("LITTLEFS Mount ESP32 Done"));
}
#endif
@ -312,7 +312,7 @@ void ESPUIClass::prepareFileSystem()
#if defined(DEBUG_ESPUI)
if (this->verbosity)
{
Serial.println(F("SPIFFS Mount ESP8266 Done"));
Serial.println(F("LITTLEFS Mount ESP8266 Done"));
}
#endif
@ -368,7 +368,7 @@ void ESPUIClass::prepareFileSystem()
#endif
#if defined(ESP32)
SPIFFS.end();
LITTLEFS.end();
#else
LittleFS.end();
#endif
@ -785,7 +785,7 @@ void ESPUIClass::updateControl(Control* control, int clientId)
// function like this and it's clients array is private
int tryId = 0;
for (int count = 0; count < this->ws->count();)
for (size_t count = 0; count < this->ws->count();)
{
if (this->ws->hasClient(tryId))
{
@ -943,7 +943,7 @@ void ESPUIClass::addGraphPoint(uint16_t id, int nValue, int clientId)
// function like this and it's clients array is private
int tryId = 0;
for (int count = 0; count < this->ws->count();)
for (size_t count = 0; count < this->ws->count();)
{
if (this->ws->hasClient(tryId))
{
@ -1080,6 +1080,12 @@ void ESPUIClass::jsonReload()
}
void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const char* password, uint16_t port)
{
// Backwards compatibility wrapper
beginLITTLEFS(_title, username, password, port);
}
void ESPUIClass::beginLITTLEFS(const char* _title, const char* username, const char* password, uint16_t port)
{
ui_title = _title;
this->basicAuthUsername = username;
@ -1098,7 +1104,7 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha
ws = new AsyncWebSocket("/ws");
#if defined(ESP32)
bool fsBegin = SPIFFS.begin();
bool fsBegin = LITTLEFS.begin();
#else
bool fsBegin = LittleFS.begin();
#endif
@ -1107,7 +1113,7 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
Serial.println(F("SPIFFS Mount Failed, PLEASE CHECK THE README ON HOW TO "
Serial.println(F("LITTLEFS Mount Failed, PLEASE CHECK THE README ON HOW TO "
"PREPARE YOUR ESP!!!!!!!"));
}
#endif
@ -1123,7 +1129,7 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha
#endif
#if defined(ESP32)
bool indexExists = SPIFFS.exists("/index.htm");
bool indexExists = LITTLEFS.exists("/index.htm");
#else
bool indexExists = LittleFS.exists("/index.htm");
#endif
@ -1150,7 +1156,7 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha
ws->setAuthentication(ESPUI.basicAuthUsername, ESPUI.basicAuthPassword);
}
#if defined(ESP32)
server->serveStatic("/", SPIFFS, "/").setDefaultFile("index.htm").setAuthentication(username, password);
server->serveStatic("/", LITTLEFS, "/").setDefaultFile("index.htm").setAuthentication(username, password);
#else
server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(username, password);
#endif
@ -1158,7 +1164,7 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha
else
{
#if defined(ESP32)
server->serveStatic("/", SPIFFS, "/").setDefaultFile("index.htm");
server->serveStatic("/", LITTLEFS, "/").setDefaultFile("index.htm");
#else
server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm");
#endif
@ -1171,7 +1177,7 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha
return request->requestAuthentication();
}
request->send(200, "text/plain", String(ESP.getFreeHeap()) + " In SPIFFSmode");
request->send(200, "text/plain", String(ESP.getFreeHeap()) + " In LITTLEFS mode");
});
server->onNotFound([](AsyncWebServerRequest* request) { request->send(404); });

View File

@ -11,8 +11,8 @@
#if defined(ESP32)
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <LITTLEFS.h>
#include "SPIFFS.h"
#include "WiFi.h"
#else
@ -24,7 +24,6 @@
#include <ESPAsyncWebServer.h>
#include <Hash.h>
#include <LittleFS.h>
#include <SPIFFSEditor.h>
#define FILE_WRITE "w"
@ -222,11 +221,13 @@ public:
void begin(const char* _title, const char* username = nullptr, const char* password = nullptr,
uint16_t port = 80); // Setup server and page in Memorymode
void beginSPIFFS(const char* _title, const char* username = nullptr, const char* password = nullptr,
uint16_t port = 80); // Setup server and page in SPIFFSmode
uint16_t port = 80); // Setup server and page in LITTLEFS mode (DEPRECATED, use beginLITTLEFS)
void beginLITTLEFS(const char* _title, const char* username = nullptr, const char* password = nullptr,
uint16_t port = 80); // Setup server and page in LITTLEFS mode
void prepareFileSystem(); // Initially preps the filesystem and loads a lot of
// stuff into SPIFFS
void list(); // Lists SPIFFS directory
// stuff into LITTLEFS
void list(); // Lists LITTLEFS directory
uint16_t addControl(ControlType type, const char* label, const String& value = String(""),
ControlColor color = ControlColor::Turquoise, uint16_t parentControl = Control::noParent,
@ -302,7 +303,7 @@ private:
const char* basicAuthPassword = nullptr;
bool basicAuth = true;
Control *prepareJSONChunk(AsyncWebSocketClient* client, Control *control, JsonArray *items);
Control* prepareJSONChunk(AsyncWebSocketClient* client, Control* control, JsonArray* items);
};
extern ESPUIClass ESPUI;