Skip to content

Commit 44e1157

Browse files
authored
Merge pull request #209 from henrygab/bugfixes2
Use LittleFS +
2 parents cab0f6a + 8cb78f7 commit 44e1157

34 files changed

+51
-24
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

README.md

Lines changed: 5 additions & 6 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,15 @@ 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.
76+
You can do this within the Arduino IDE after installing the [Arduino ESP8266 LittleFS](https://github.com/earlephilhower/arduino-esp8266littlefs-plugin).
7877

79-
With ESP8266FS installed upload the web app using `ESP8266 Sketch Data Upload` command in the Arduino Tools menu.
78+
With the upload tool installed, upload the web app using `ESP8266 LittleFS Data Upload` command in the Arduino Tools menu.
8079

8180
Compression
8281
-----------
8382

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

8685
`gzip -r data/`
8786

esp8266-fastled-webserver/FSBrowser.h

Lines changed: 13 additions & 10 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,18 +105,20 @@ 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 = "[";
111112
while(dir.next()){
112113
File entry = dir.openFile("r");
113114
if (output != "[") output += ',';
114115
bool isDir = false;
116+
//bool isDir = entry.isDirectory();
117+
115118
output += "{\"type\":\"";
116119
output += (isDir)?"dir":"file";
117120
output += "\",\"name\":\"";
118-
output += String(entry.name()).substring(1);
121+
output += String(entry.name());
119122
output += "\"}";
120123
entry.close();
121124
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

data/js/app.js renamed to esp8266-fastled-webserver/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 renamed to esp8266-fastled-webserver/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

File renamed without changes.
File renamed without changes.

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 LittleFS
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);

deployapp.sh renamed to scripts/deployapp.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ declare -a filenames=(
2020
# "images/atom196.png"
2121
# "favicon.ico"
2222

23+
# TODO -- update to be based on script's own directory
24+
# TODO -- update to switch to build directory
25+
pushd ../esp8266-fastled-webserver > /dev/null
26+
2327
for filename in "${filenames[@]}"
2428
do
2529
# add --trace-ascii curl.log for logging
@@ -31,3 +35,5 @@ do
3135

3236
rm -f data/$filename.gz
3337
done
38+
39+
popd > /dev/null

deployfirmware.sh renamed to scripts/deployfirmware.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@ binFilename=tree-v2.ino.bin
33
ip=${1:-"192.168.86.36"}
44
url="http://$ip/update"
55

6+
# TODO -- update to be based on script's own directory
7+
# TODO -- update to switch to build directory
8+
pushd ../esp8266-fastled-webserver > /dev/null
9+
610
curl -v --form "file=@$outputDir/$binFilename;filename=$binFilename" $url
11+
12+
popd > /dev/null

uploadfile.sh renamed to scripts/uploadfile.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ filename=$2
1010

1111
# add --trace-ascii curl.log for logging
1212

13+
# TODO -- update to be based on script's own directory
14+
# TODO -- update to switch to build directory
15+
pushd ../esp8266-fastled-webserver > /dev/null
16+
1317
gzip -kf data/$filename
1418

1519
echo $filename
1620
curl --form "file=@data/$filename.gz;filename=$filename.gz" $url
1721

1822
rm -f data/$filename.gz
23+
24+
popd > /dev/null
25+

0 commit comments

Comments
 (0)