mirror of
				https://github.com/s00500/ESPUI.git
				synced 2025-10-30 20:53:24 +00:00 
			
		
		
		
	Implement LITTLEFS as requested by @thomastech in #144
Signed-off-by: Lukas Bachschwell <lukas@lbsfilm.at>
This commit is contained in:
		| @@ -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 ESP8266_) [ESPAsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP) | ||||||
| - (_For ESP32_) [AsyncTCP](https://github.com/me-no-dev/AsyncTCP) | - (_For ESP32_) [AsyncTCP](https://github.com/me-no-dev/AsyncTCP) | ||||||
|  | - (_For ESP32_) [lorol/LittleFS_esp32](https://github.com/lorol/LITTLEFS) | ||||||
|  |  | ||||||
| ## How to Install | ## How to Install | ||||||
|  |  | ||||||
| @@ -89,13 +90,13 @@ Go to Sketch>Include Library>Add .zip Library> Select the Downloaded .zip File. | |||||||
| ## Getting started | ## Getting started | ||||||
|  |  | ||||||
| ESPUI serves several files to the browser to build up its web interface. This | 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 | _When `ESPUI.begin()` is called the default is serving files from Memory and | ||||||
| ESPUI should work out of the box!_ | ESPUI should work out of the box!_ | ||||||
|  |  | ||||||
| **OPTIONAL:** But if this causes your program to _use too much memory_ you can | **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 | do this: you can either use the ESP file upload tool or you use the library | ||||||
| function `ESPUI.prepareFileSystem()` | 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 | ### Initialisation of the UI | ||||||
|  |  | ||||||
| After all the elements are configured you can use `ESPUI.begin("Some Title");` | 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 | 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 | 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. | also shows an connection status in the top bar. | ||||||
|   | |||||||
| @@ -21,6 +21,7 @@ slider	KEYWORD2 | |||||||
|  |  | ||||||
| begin	KEYWORD2 | begin	KEYWORD2 | ||||||
| beginSPIFFS	KEYWORD2 | beginSPIFFS	KEYWORD2 | ||||||
|  | beginLITTLEFS	KEYWORD2 | ||||||
| print	KEYWORD2 | print	KEYWORD2 | ||||||
| updateSwitcher	KEYWORD2 | updateSwitcher	KEYWORD2 | ||||||
| updateSlider	KEYWORD2 | updateSlider	KEYWORD2 | ||||||
|   | |||||||
							
								
								
									
										14
									
								
								library.json
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								library.json
									
									
									
									
									
								
							| @@ -6,13 +6,16 @@ | |||||||
|     "type": "git", |     "type": "git", | ||||||
|     "url": "https://github.com/s00500/ESPUI.git" |     "url": "https://github.com/s00500/ESPUI.git" | ||||||
|   }, |   }, | ||||||
|   "authors": [{ |   "authors": [ | ||||||
|  |     { | ||||||
|       "name": "Lukas Bachschwell", |       "name": "Lukas Bachschwell", | ||||||
|       "email": "lukas@lbsfilm.at", |       "email": "lukas@lbsfilm.at", | ||||||
|       "url": "https://lbsfilm.at", |       "url": "https://lbsfilm.at", | ||||||
|       "maintainer": true |       "maintainer": true | ||||||
|   }], |     } | ||||||
|   "dependencies": [{ |   ], | ||||||
|  |   "dependencies": [ | ||||||
|  |     { | ||||||
|       "name": "ESP Async WebServer", |       "name": "ESP Async WebServer", | ||||||
|       "authors": "Hristo Gochkov", |       "authors": "Hristo Gochkov", | ||||||
|       "frameworks": "arduino" |       "frameworks": "arduino" | ||||||
| @@ -21,6 +24,11 @@ | |||||||
|       "name": "ArduinoJson", |       "name": "ArduinoJson", | ||||||
|       "authors": "Benoit Blanchon", |       "authors": "Benoit Blanchon", | ||||||
|       "frameworks": "arduino" |       "frameworks": "arduino" | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       "name": "LittleFS_esp32", | ||||||
|  |       "authors": "lorol", | ||||||
|  |       "frameworks": "arduino" | ||||||
|     } |     } | ||||||
|   ], |   ], | ||||||
|   "version": "2.0.2", |   "version": "2.0.2", | ||||||
|   | |||||||
| @@ -14,3 +14,12 @@ board = nodemcuv2 | |||||||
| framework = arduino | framework = arduino | ||||||
|  |  | ||||||
| lib_extra_dirs = ../../ | 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; | uint16_t Control::idCounter = 1; | ||||||
|  |  | ||||||
| // ################# Spiffs functions | // ################# LITTLEFS functions | ||||||
| #if defined(ESP32) | #if defined(ESP32) | ||||||
| void listDir(const char* dirname, uint8_t levels) | void listDir(const char* dirname, uint8_t levels) | ||||||
| { | { | ||||||
| @@ -27,7 +27,7 @@ void listDir(const char* dirname, uint8_t levels) | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #if defined(ESP32) | #if defined(ESP32) | ||||||
|     File root = SPIFFS.open(dirname); |     File root = LITTLEFS.open(dirname); | ||||||
| #else | #else | ||||||
|     File root = LittleFS.open(dirname); |     File root = LittleFS.open(dirname); | ||||||
| #endif | #endif | ||||||
| @@ -115,9 +115,9 @@ void listDir(const char* dirname, uint8_t levels) | |||||||
| void ESPUIClass::list() | void ESPUIClass::list() | ||||||
| { | { | ||||||
| #if defined(ESP32) | #if defined(ESP32) | ||||||
|     if (!SPIFFS.begin()) |     if (!LITTLEFS.begin()) | ||||||
|     { |     { | ||||||
|         Serial.println(F("SPIFFS Mount Failed")); |         Serial.println(F("LITTLEFS Mount Failed")); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| #else | #else | ||||||
| @@ -131,8 +131,8 @@ void ESPUIClass::list() | |||||||
|     listDir("/", 1); |     listDir("/", 1); | ||||||
| #if defined(ESP32) | #if defined(ESP32) | ||||||
|  |  | ||||||
|     Serial.println(SPIFFS.totalBytes()); |     Serial.println(LITTLEFS.totalBytes()); | ||||||
|     Serial.println(SPIFFS.usedBytes()); |     Serial.println(LITTLEFS.usedBytes()); | ||||||
|  |  | ||||||
| #else | #else | ||||||
|     FSInfo fs_info; |     FSInfo fs_info; | ||||||
| @@ -147,7 +147,7 @@ void ESPUIClass::list() | |||||||
| void deleteFile(const char* path) | void deleteFile(const char* path) | ||||||
| { | { | ||||||
| #if defined(ESP32) | #if defined(ESP32) | ||||||
|     bool exists = SPIFFS.exists(path); |     bool exists = LITTLEFS.exists(path); | ||||||
| #else | #else | ||||||
|     bool exists = LittleFS.exists(path); |     bool exists = LittleFS.exists(path); | ||||||
| #endif | #endif | ||||||
| @@ -172,7 +172,7 @@ void deleteFile(const char* path) | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #if defined(ESP32) | #if defined(ESP32) | ||||||
|     bool didRemove = SPIFFS.remove(path); |     bool didRemove = LITTLEFS.remove(path); | ||||||
| #else | #else | ||||||
|     bool didRemove = LittleFS.remove(path); |     bool didRemove = LittleFS.remove(path); | ||||||
| #endif | #endif | ||||||
| @@ -206,7 +206,7 @@ void writeFile(const char* path, const char* data) | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #if defined(ESP32) | #if defined(ESP32) | ||||||
|     File file = SPIFFS.open(path, FILE_WRITE); |     File file = LITTLEFS.open(path, FILE_WRITE); | ||||||
| #else | #else | ||||||
|     File file = LittleFS.open(path, FILE_WRITE); |     File file = LittleFS.open(path, FILE_WRITE); | ||||||
| #endif | #endif | ||||||
| @@ -269,7 +269,7 @@ void writeFile(const char* path, const char* data) | |||||||
|     file.close(); |     file.close(); | ||||||
| } | } | ||||||
|  |  | ||||||
| // end Spiffs functions | // end LITTLEFS functions | ||||||
|  |  | ||||||
| void ESPUIClass::prepareFileSystem() | void ESPUIClass::prepareFileSystem() | ||||||
| { | { | ||||||
| @@ -283,14 +283,14 @@ void ESPUIClass::prepareFileSystem() | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #if defined(ESP32) | #if defined(ESP32) | ||||||
|     SPIFFS.format(); |     LITTLEFS.format(); | ||||||
|  |  | ||||||
|     if (!SPIFFS.begin(true)) |     if (!LITTLEFS.begin(true)) | ||||||
|     { |     { | ||||||
| #if defined(DEBUG_ESPUI) | #if defined(DEBUG_ESPUI) | ||||||
|         if (this->verbosity) |         if (this->verbosity) | ||||||
|         { |         { | ||||||
|             Serial.println(F("SPIFFS Mount Failed")); |             Serial.println(F("LITTLEFS Mount Failed")); | ||||||
|         } |         } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| @@ -301,7 +301,7 @@ void ESPUIClass::prepareFileSystem() | |||||||
|     if (this->verbosity) |     if (this->verbosity) | ||||||
|     { |     { | ||||||
|         listDir("/", 1); |         listDir("/", 1); | ||||||
|         Serial.println(F("SPIFFS Mount ESP32 Done")); |         Serial.println(F("LITTLEFS Mount ESP32 Done")); | ||||||
|     } |     } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| @@ -312,7 +312,7 @@ void ESPUIClass::prepareFileSystem() | |||||||
| #if defined(DEBUG_ESPUI) | #if defined(DEBUG_ESPUI) | ||||||
|     if (this->verbosity) |     if (this->verbosity) | ||||||
|     { |     { | ||||||
|         Serial.println(F("SPIFFS Mount ESP8266 Done")); |         Serial.println(F("LITTLEFS Mount ESP8266 Done")); | ||||||
|     } |     } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| @@ -368,7 +368,7 @@ void ESPUIClass::prepareFileSystem() | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #if defined(ESP32) | #if defined(ESP32) | ||||||
|     SPIFFS.end(); |     LITTLEFS.end(); | ||||||
| #else | #else | ||||||
|     LittleFS.end(); |     LittleFS.end(); | ||||||
| #endif | #endif | ||||||
| @@ -785,7 +785,7 @@ void ESPUIClass::updateControl(Control* control, int clientId) | |||||||
|     // function like this and it's clients array is private |     // function like this and it's clients array is private | ||||||
|     int tryId = 0; |     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)) |         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 |     // function like this and it's clients array is private | ||||||
|     int tryId = 0; |     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)) |         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) | 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; |     ui_title = _title; | ||||||
|     this->basicAuthUsername = username; |     this->basicAuthUsername = username; | ||||||
| @@ -1098,7 +1104,7 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha | |||||||
|     ws = new AsyncWebSocket("/ws"); |     ws = new AsyncWebSocket("/ws"); | ||||||
|  |  | ||||||
| #if defined(ESP32) | #if defined(ESP32) | ||||||
|     bool fsBegin = SPIFFS.begin(); |     bool fsBegin = LITTLEFS.begin(); | ||||||
| #else | #else | ||||||
|     bool fsBegin = LittleFS.begin(); |     bool fsBegin = LittleFS.begin(); | ||||||
| #endif | #endif | ||||||
| @@ -1107,7 +1113,7 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha | |||||||
| #if defined(DEBUG_ESPUI) | #if defined(DEBUG_ESPUI) | ||||||
|         if (ESPUI.verbosity) |         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!!!!!!!")); |                              "PREPARE YOUR ESP!!!!!!!")); | ||||||
|         } |         } | ||||||
| #endif | #endif | ||||||
| @@ -1123,7 +1129,7 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #if defined(ESP32) | #if defined(ESP32) | ||||||
|     bool indexExists = SPIFFS.exists("/index.htm"); |     bool indexExists = LITTLEFS.exists("/index.htm"); | ||||||
| #else | #else | ||||||
|     bool indexExists = LittleFS.exists("/index.htm"); |     bool indexExists = LittleFS.exists("/index.htm"); | ||||||
| #endif | #endif | ||||||
| @@ -1150,7 +1156,7 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha | |||||||
|             ws->setAuthentication(ESPUI.basicAuthUsername, ESPUI.basicAuthPassword); |             ws->setAuthentication(ESPUI.basicAuthUsername, ESPUI.basicAuthPassword); | ||||||
|         } |         } | ||||||
| #if defined(ESP32) | #if defined(ESP32) | ||||||
|         server->serveStatic("/", SPIFFS, "/").setDefaultFile("index.htm").setAuthentication(username, password); |         server->serveStatic("/", LITTLEFS, "/").setDefaultFile("index.htm").setAuthentication(username, password); | ||||||
| #else | #else | ||||||
|         server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(username, password); |         server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(username, password); | ||||||
| #endif | #endif | ||||||
| @@ -1158,7 +1164,7 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha | |||||||
|     else |     else | ||||||
|     { |     { | ||||||
| #if defined(ESP32) | #if defined(ESP32) | ||||||
|         server->serveStatic("/", SPIFFS, "/").setDefaultFile("index.htm"); |         server->serveStatic("/", LITTLEFS, "/").setDefaultFile("index.htm"); | ||||||
| #else | #else | ||||||
|         server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm"); |         server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm"); | ||||||
| #endif | #endif | ||||||
| @@ -1171,7 +1177,7 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha | |||||||
|             return request->requestAuthentication(); |             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); }); |     server->onNotFound([](AsyncWebServerRequest* request) { request->send(404); }); | ||||||
|   | |||||||
							
								
								
									
										13
									
								
								src/ESPUI.h
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/ESPUI.h
									
									
									
									
									
								
							| @@ -11,8 +11,8 @@ | |||||||
| #if defined(ESP32) | #if defined(ESP32) | ||||||
| #include <AsyncTCP.h> | #include <AsyncTCP.h> | ||||||
| #include <ESPAsyncWebServer.h> | #include <ESPAsyncWebServer.h> | ||||||
|  | #include <LITTLEFS.h> | ||||||
|  |  | ||||||
| #include "SPIFFS.h" |  | ||||||
| #include "WiFi.h" | #include "WiFi.h" | ||||||
|  |  | ||||||
| #else | #else | ||||||
| @@ -24,7 +24,6 @@ | |||||||
| #include <ESPAsyncWebServer.h> | #include <ESPAsyncWebServer.h> | ||||||
| #include <Hash.h> | #include <Hash.h> | ||||||
| #include <LittleFS.h> | #include <LittleFS.h> | ||||||
| #include <SPIFFSEditor.h> |  | ||||||
|  |  | ||||||
| #define FILE_WRITE "w" | #define FILE_WRITE "w" | ||||||
|  |  | ||||||
| @@ -222,11 +221,13 @@ public: | |||||||
|     void begin(const char* _title, const char* username = nullptr, const char* password = nullptr, |     void begin(const char* _title, const char* username = nullptr, const char* password = nullptr, | ||||||
|         uint16_t port = 80); // Setup server and page in Memorymode |         uint16_t port = 80); // Setup server and page in Memorymode | ||||||
|     void beginSPIFFS(const char* _title, const char* username = nullptr, const char* password = nullptr, |     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 |     void prepareFileSystem(); // Initially preps the filesystem and loads a lot of | ||||||
|                               // stuff into SPIFFS |                               // stuff into LITTLEFS | ||||||
|     void list(); // Lists SPIFFS directory |     void list(); // Lists LITTLEFS directory | ||||||
|  |  | ||||||
|     uint16_t addControl(ControlType type, const char* label, const String& value = String(""), |     uint16_t addControl(ControlType type, const char* label, const String& value = String(""), | ||||||
|         ControlColor color = ControlColor::Turquoise, uint16_t parentControl = Control::noParent, |         ControlColor color = ControlColor::Turquoise, uint16_t parentControl = Control::noParent, | ||||||
| @@ -302,7 +303,7 @@ private: | |||||||
|     const char* basicAuthPassword = nullptr; |     const char* basicAuthPassword = nullptr; | ||||||
|     bool basicAuth = true; |     bool basicAuth = true; | ||||||
|  |  | ||||||
|     Control *prepareJSONChunk(AsyncWebSocketClient* client, Control *control, JsonArray *items); |     Control* prepareJSONChunk(AsyncWebSocketClient* client, Control* control, JsonArray* items); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| extern ESPUIClass ESPUI; | extern ESPUIClass ESPUI; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user