Skip to content

Commit 0427421

Browse files
committed
prepare to migrate to LittleFS
1 parent 2543e12 commit 0427421

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,10 @@ Web App
5252

5353
Patterns are requested by the app from the ESP8266, so as new patterns are added, they're automatically listed in the app.
5454

55-
The web app is stored in SPIFFS (on-board flash memory).
55+
The web app is stored in a file system in on-board flash memory. The file system used is LittleFS *(Note: prior versions used SPIFFS)*.
5656

5757
The web app is a single page app that uses [jQuery](https://jquery.com) and [Bootstrap](http://getbootstrap.com). It has buttons for On/Off, a slider for brightness, a pattern selector, and a color picker (using [jQuery MiniColors](http://labs.abeautifulsite.net/jquery-minicolors)). Event handlers for the controls are wired up, so you don't have to click a 'Send' button after making changes. The brightness slider and the color picker use a delayed event handler, to prevent from flooding the ESP8266 web server with too many requests too quickly.
5858

59-
The only drawback to SPIFFS that I've found so far is uploading the files can be extremely slow, requiring several minutes, sometimes regardless of how large the files are. It can be so slow that I've been just developing the web app and debugging locally on my desktop (with a hard-coded IP for the ESP8266), before uploading to SPIFFS and testing on the ESP8266.
60-
6159
Installing
6260
-----------
6361
The app is installed via the Arduino IDE which can be [downloaded here](https://www.arduino.cc/en/main/software). The ESP8266 boards will need to be added to the Arduino IDE which is achieved as follows. Click File > Preferences and copy and paste the URL "http://arduino.esp8266.com/stable/package_esp8266com_index.json" into the Additional Boards Manager URLs field. Click OK. Click Tools > Boards: ... > Boards Manager. Find and click on ESP8266 (using the Search function may expedite this). Click on Install. After installation, click on Close and then select your ESP8266 board from the Tools > Board: ... menu.
@@ -74,14 +72,14 @@ Here are the board settings I use:
7472

7573
![image](https://user-images.githubusercontent.com/3598755/135755572-52d4d0db-1dba-4388-a86c-a293e4f13878.png)
7674

77-
The web app needs to be uploaded to the ESP8266's SPIFFS. You can do this within the Arduino IDE after installing the [Arduino ESP8266FS tool](http://esp8266.github.io/Arduino/versions/2.3.0/doc/filesystem.html#uploading-files-to-file-system).
75+
The web app needs to be uploaded to the ESP8266's file system. You can do this within the Arduino IDE after installing the [Arduino ESP8266FS tool](http://esp8266.github.io/Arduino/versions/2.3.0/doc/filesystem.html#uploading-files-to-file-system).
7876

7977
With ESP8266FS installed upload the web app using `ESP8266 Sketch Data Upload` command in the Arduino Tools menu.
8078

8179
Compression
8280
-----------
8381

84-
The web app files can be gzip compressed before uploading to SPIFFS by running the following command:
82+
The web app files can be gzip compressed before uploading to the ESP8266's file system by running the following command:
8583

8684
`gzip -r data/`
8785

data/js/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var address = location.hostname;
33
var urlBase = "";
44

5-
// used when hosting the site somewhere other than the ESP8266 (handy for testing without waiting forever to upload to SPIFFS)
5+
// used when hosting the site somewhere other than the ESP8266 (handy for testing without waiting forever to upload to SPIFFS/LittleFS)
66
// var address = "192.168.86.36";
77
// var urlBase = "http://" + address + "/";
88

data/js/simple.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var address = location.hostname;
33
var urlBase = "";
44

5-
// used when hosting the site somewhere other than the ESP8266 (handy for testing without waiting forever to upload to SPIFFS)
5+
// used when hosting the site somewhere other than the ESP8266 (handy for testing without waiting forever to upload to SPIFFS/LittleFS)
66
// var address = "192.168.1.13";
77
// var urlBase = "http://" + address + "/";
88

esp8266-fastled-webserver/FSBrowser.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
//holds the current upload
23
File fsUploadFile;
34

@@ -36,10 +37,10 @@ bool handleFileRead(String path){
3637
if(path.endsWith("/")) path += "index.htm";
3738
String contentType = getContentType(path);
3839
String pathWithGz = path + ".gz";
39-
if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)){
40-
if(SPIFFS.exists(pathWithGz))
40+
if(MYFS.exists(pathWithGz) || MYFS.exists(path)){
41+
if(MYFS.exists(pathWithGz))
4142
path += ".gz";
42-
File file = SPIFFS.open(path, "r");
43+
File file = MYFS.open(path, "r");
4344
(void)webServer.streamFile(file, contentType);
4445
file.close();
4546

@@ -55,7 +56,7 @@ void handleFileUpload(){
5556
String filename = upload.filename;
5657
if(!filename.startsWith("/")) filename = "/"+filename;
5758
Serial.print("handleFileUpload Name: "); Serial.println(filename);
58-
fsUploadFile = SPIFFS.open(filename, "w");
59+
fsUploadFile = MYFS.open(filename, "w");
5960
filename = String();
6061
} else if(upload.status == UPLOAD_FILE_WRITE){
6162
//Serial.print("handleFileUpload Data: "); Serial.println(upload.currentSize);
@@ -74,9 +75,9 @@ void handleFileDelete(){
7475
Serial.println("handleFileDelete: " + path);
7576
if(path == "/")
7677
return webServer.send(500, "text/plain", "BAD PATH");
77-
if(!SPIFFS.exists(path))
78+
if(!MYFS.exists(path))
7879
return webServer.send(404, "text/plain", "FileNotFound");
79-
SPIFFS.remove(path);
80+
MYFS.remove(path);
8081
webServer.send(200, "text/plain", "");
8182
path = String();
8283
}
@@ -88,9 +89,9 @@ void handleFileCreate(){
8889
Serial.println("handleFileCreate: " + path);
8990
if(path == "/")
9091
return webServer.send(500, "text/plain", "BAD PATH");
91-
if(SPIFFS.exists(path))
92+
if(MYFS.exists(path))
9293
return webServer.send(500, "text/plain", "FILE EXISTS");
93-
File file = SPIFFS.open(path, "w");
94+
File file = MYFS.open(path, "w");
9495
if(file)
9596
file.close();
9697
else
@@ -104,7 +105,7 @@ void handleFileList() {
104105

105106
String path = webServer.arg("dir");
106107
Serial.println("handleFileList: " + path);
107-
Dir dir = SPIFFS.openDir(path);
108+
Dir dir = MYFS.openDir(path);
108109
path = String();
109110

110111
String output = "[";

esp8266-fastled-webserver/esp8266-fastled-webserver.ino

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@ extern "C" {
2727
#include "user_interface.h"
2828
}
2929

30+
#include <FS.h>
31+
//#include <LittleFS.h>
32+
#define MYFS SPIFFS
33+
34+
3035
#include <ESP8266WiFi.h>
3136
#include <ESP8266mDNS.h>
3237
#include <ESP8266WebServer.h>
3338
#include <ESP8266HTTPUpdateServer.h>
3439
#include <ESP8266HTTPClient.h>
3540
//#include <WebSocketsServer.h>
36-
#include <FS.h>
41+
3742
#include <EEPROM.h>
3843
//#include <IRremoteESP8266.h>
3944
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager/tree/development
@@ -249,11 +254,12 @@ void setup() {
249254
Serial.print( F("MAC Address: ") ); Serial.println(WiFi.macAddress());
250255
Serial.println();
251256

252-
SPIFFS.begin();
253-
{
254-
Serial.println("SPIFFS contents:");
257+
if (!MYFS.begin()) {
258+
Serial.println(F("An error occurred when attempting to mount the flash file system"));
259+
} else {
260+
Serial.println("FS contents:");
255261

256-
Dir dir = SPIFFS.openDir("/");
262+
Dir dir = MYFS.openDir("/");
257263
while (dir.next()) {
258264
String fileName = dir.fileName();
259265
size_t fileSize = dir.fileSize();
@@ -477,7 +483,7 @@ void setup() {
477483
webServer.send(200, "text/plain", "");
478484
}, handleFileUpload);
479485

480-
webServer.serveStatic("/", SPIFFS, "/", "max-age=86400");
486+
webServer.serveStatic("/", MYFS, "/", "max-age=86400");
481487

482488
MDNS.begin(nameChar);
483489
MDNS.setHostname(nameChar);

0 commit comments

Comments
 (0)