mirror of
https://github.com/s00500/ESPUI.git
synced 2024-12-22 19:30:50 +00:00
Implement LITTLEFS as requested by @thomastech in #144
Signed-off-by: Lukas Bachschwell <lukas@lbsfilm.at>
This commit is contained in:
parent
3cbae2ff1b
commit
e1fe13bac6
@ -49,6 +49,7 @@ This library is dependent on the following libraries to function properly.
|
||||
|
||||
- (_For ESP8266_) [ESPAsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP)
|
||||
- (_For ESP32_) [AsyncTCP](https://github.com/me-no-dev/AsyncTCP)
|
||||
- (_For ESP32_) [lorol/LittleFS_esp32](https://github.com/lorol/LITTLEFS)
|
||||
|
||||
## How to Install
|
||||
|
||||
@ -89,13 +90,13 @@ Go to Sketch>Include Library>Add .zip Library> Select the Downloaded .zip File.
|
||||
## Getting started
|
||||
|
||||
ESPUI serves several files to the browser to build up its web interface. This
|
||||
can be achieved in 2 ways: _PROGMEM_ or _SPIFFS_
|
||||
can be achieved in 2 ways: _PROGMEM_ or _LITTLEFS_
|
||||
|
||||
_When `ESPUI.begin()` is called the default is serving files from Memory and
|
||||
ESPUI should work out of the box!_
|
||||
|
||||
**OPTIONAL:** But if this causes your program to _use too much memory_ you can
|
||||
burn the files into the SPIFFS filesystem on the ESP. There are now two ways to
|
||||
burn the files into the LITTLEFS filesystem on the ESP. There are now two ways to
|
||||
do this: you can either use the ESP file upload tool or you use the library
|
||||
function `ESPUI.prepareFileSystem()`
|
||||
|
||||
@ -296,7 +297,7 @@ Then all widgets for the tab need to be added to it by specifying the tab as the
|
||||
### Initialisation of the UI
|
||||
|
||||
After all the elements are configured you can use `ESPUI.begin("Some Title");`
|
||||
to start the UI interface. (Or `ESPUI.beginSPIFFS("Some Title");` respectively)
|
||||
to start the UI interface. (Or `ESPUI.beginLITTLEFS("Some Title");` respectively)
|
||||
Make sure you setup a working network connection or AccesPoint **before** (See
|
||||
gui.ino example). The web interface can then be used from multiple devices at once and
|
||||
also shows an connection status in the top bar.
|
||||
|
@ -21,6 +21,7 @@ slider KEYWORD2
|
||||
|
||||
begin KEYWORD2
|
||||
beginSPIFFS KEYWORD2
|
||||
beginLITTLEFS KEYWORD2
|
||||
print KEYWORD2
|
||||
updateSwitcher KEYWORD2
|
||||
updateSlider KEYWORD2
|
||||
|
22
library.json
22
library.json
@ -6,13 +6,16 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/s00500/ESPUI.git"
|
||||
},
|
||||
"authors": [{
|
||||
"name": "Lukas Bachschwell",
|
||||
"email": "lukas@lbsfilm.at",
|
||||
"url": "https://lbsfilm.at",
|
||||
"maintainer": true
|
||||
}],
|
||||
"dependencies": [{
|
||||
"authors": [
|
||||
{
|
||||
"name": "Lukas Bachschwell",
|
||||
"email": "lukas@lbsfilm.at",
|
||||
"url": "https://lbsfilm.at",
|
||||
"maintainer": true
|
||||
}
|
||||
],
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "ESP Async WebServer",
|
||||
"authors": "Hristo Gochkov",
|
||||
"frameworks": "arduino"
|
||||
@ -21,6 +24,11 @@
|
||||
"name": "ArduinoJson",
|
||||
"authors": "Benoit Blanchon",
|
||||
"frameworks": "arduino"
|
||||
},
|
||||
{
|
||||
"name": "LittleFS_esp32",
|
||||
"authors": "lorol",
|
||||
"frameworks": "arduino"
|
||||
}
|
||||
],
|
||||
"version": "2.0.2",
|
||||
|
@ -14,3 +14,12 @@ board = nodemcuv2
|
||||
framework = arduino
|
||||
|
||||
lib_extra_dirs = ../../
|
||||
|
||||
[env:esp32]
|
||||
platform = espressif32
|
||||
board = esp32dev
|
||||
framework = arduino
|
||||
|
||||
lib_extra_dirs = ../../
|
||||
|
||||
lib_deps = lorol/LittleFS_esp32
|
||||
|
@ -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); });
|
||||
|
13
src/ESPUI.h
13
src/ESPUI.h
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user