Skip to content

Commit ed865f5

Browse files
committed
LittleFS can be used (a choice for ESP8266 for now)
- To make and upload FS https://github.com/earlephilhower/arduino-esp8266littlefs-plugin - Simply redefine SPIFFS to LittleFS Changes are in src/SPIFFSEditor.cpp including the src/edit.htm See ESP_AsyncFSBrowser and SmartSwitch examples
1 parent 223096e commit ed865f5

26 files changed

+424
-391
lines changed

README.md

+110-105
Large diffs are not rendered by default.

examples/ESP_AsyncFSBrowser/ESP_AsyncFSBrowser.ino

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_LittleFS // possible only for ESP8266 for now
2+
13
#include <ArduinoOTA.h>
24
#ifdef ESP32
35
#include <FS.h>
@@ -6,6 +8,11 @@
68
#include <WiFi.h>
79
#include <AsyncTCP.h>
810
#elif defined(ESP8266)
11+
#ifdef USE_LittleFS
12+
#include <FS.h>
13+
#define SPIFFS LittleFS
14+
#include <LittleFS.h>
15+
#endif
916
#include <ESP8266WiFi.h>
1017
#include <ESPAsyncTCP.h>
1118
#include <ESP8266mDNS.h>
-96.6 KB
Binary file not shown.
117 KB
Binary file not shown.
Binary file not shown.
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Test
-5.96 KB
Binary file not shown.
-16.6 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

examples/SmartSwitch/README.md

+16-32
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,19 @@
11
<img title="" src="1.PNG" alt="" width="137"> <img title="" src="2.PNG" alt="" width="138"> <img title="" src="3.PNG" alt="" width="150"> <img title="" src="4.PNG" alt="" width="150">
22

33
## SmartSwitch
4-
5-
* Remote Temperature Control application with schedule
6-
7-
(example: car block heater or car battery charger for winter)
8-
9-
* Based on [ESP_AsyncFSBrowser](https://github.com/lorol/ESPAsyncWebServer/tree/master/examples/ESP_AsyncFSBrowser) example that uses embedded ACE editor
10-
11-
* Wide browser compatibility, no extra server-side needed
12-
13-
* HTTP server and WebSocket on same port
14-
15-
* Standalone, no JS dependencies for the browser from Internet
16-
17-
* [Ace Editor](https://github.com/ajaxorg/ace) embedded to source but also - editable, upgradeable see [extras folder](https://github.com/lorol/ESPAsyncWebServer/tree/master/extras)
18-
19-
* Added [ESPAsyncWiFiManager](https://github.com/alanswx/ESPAsyncWiFiManager) and fallback AP mode after timeout
20-
21-
* Real Time (NTP) w/ Time Zones. Sync from browser time if in AP mode
22-
23-
* Memorized settings to EEPROM
24-
25-
* Multiple clients can be connected at same time, they see each other' requests
26-
27-
* Authentication variants including [Cookie-based](https://github.com/me-no-dev/ESPAsyncWebServer/pull/684) idea
28-
29-
* Used [this Xtea implementation](https://github.com/franksmicro/Arduino/tree/master/libraries/Xtea) for getting a fancier Cookie token
30-
31-
* Default credentials **smart : switch** or only **switch** as password
32-
33-
* OTA included
34-
35-
* Use the latest ESP8266 ESP32 cores from GitHub
4+
- Remote Temperature Control application with schedule
5+
(example: car block heater or car battery charger for winter)
6+
- Based on [ESP_AsyncFSBrowser](https://github.com/lorol/ESPAsyncWebServer/tree/master/examples/ESP_AsyncFSBrowser) example that uses embedded ACE editor
7+
- Wide browser compatibility, no extra server-side needed
8+
- HTTP server and WebSocket on same port
9+
- Standalone, no JS dependencies for the browser from Internet
10+
- [Ace Editor](https://github.com/ajaxorg/ace) embedded to source but also - editable, upgradeable see [extras folder](https://github.com/lorol/ESPAsyncWebServer/tree/master/extras)
11+
- Added [ESPAsyncWiFiManager](https://github.com/alanswx/ESPAsyncWiFiManager) and fallback AP mode after timeout
12+
- Real Time (NTP) w/ Time Zones. Sync from browser time if in AP mode
13+
- Memorized settings to EEPROM
14+
- Multiple clients can be connected at same time, they see each other' requests
15+
- Authentication variants including [Cookie-based](https://github.com/me-no-dev/ESPAsyncWebServer/pull/684) idea
16+
- Used [this Xtea implementation](https://github.com/franksmicro/Arduino/tree/master/libraries/Xtea) for getting a fancier Cookie token
17+
- Default credentials **smart : switch** or only **switch** as password
18+
- OTA included
19+
- Use the latest ESP8266 ESP32 cores from GitHub

examples/SmartSwitch/SmartSwitch.ino

+18-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Multiple clients can be connected at same time, they see each other requests
1313
Use latest ESP core lib (from Github)
1414
*/
1515

16+
#define USE_LittleFS // possible only for ESP8266 for now
17+
1618
#define USE_WFM // to use ESPAsyncWiFiManager
1719
//#define DEL_WFM // delete Wifi credentials stored
1820
//(use once then comment and flash again), also HTTP /erase-wifi can do the same live
@@ -44,10 +46,16 @@ Use latest ESP core lib (from Github)
4446
#include <WiFi.h>
4547
#include <AsyncTCP.h>
4648
#elif defined(ESP8266)
49+
#ifdef USE_LittleFS
50+
#include <FS.h>
51+
#define SPIFFS LittleFS
52+
#include <LittleFS.h>
53+
#endif
4754
#include <ESP8266WiFi.h>
4855
#include <ESPAsyncTCP.h>
4956
#include <ESP8266mDNS.h>
5057
#endif
58+
5159
#include <ESPAsyncWebServer.h>
5260
#ifdef USE_WFM
5361
#include "ESPAsyncWiFiManager.h"
@@ -62,6 +70,7 @@ Use latest ESP core lib (from Github)
6270
#include "Xtea.h"
6371
#endif
6472

73+
6574
#define RTC_UTC_TEST 1577836800 // Some Date
6675
#define MYTZ PSTR("EST5EDT,M3.2.0,M11.1.0")
6776

@@ -517,8 +526,12 @@ void setup(){
517526
Serial.printf("Timer set %02d:%02d - %02d:%02d\n", ee.hstart, ee.mstart, ee.hstop, ee.mstop);
518527
Serial.printf("Temp set %+2.1f\n", ee.tempe);
519528

520-
//SPIFFS
521-
SPIFFS.begin();
529+
//FS
530+
if (SPIFFS.begin()) {
531+
Serial.print(F("FS mounted\n"));
532+
} else {
533+
Serial.print(F("FS mount failed\n"));
534+
}
522535

523536
#ifdef USE_AUTH_WS
524537
ws.setAuthentication(http_username,http_password);
@@ -676,7 +689,10 @@ void setup(){
676689
ArduinoOTA.setHostname(hostName);
677690
ArduinoOTA.onStart([]() {
678691
Serial.print(F("OTA Started ...\n"));
692+
SPIFFS.end(); // Clean FS
679693
ws.textAll("Now,OTA"); // for all clients
694+
ws.enable(false);
695+
ws.closeAll();
680696
});
681697
ArduinoOTA.begin();
682698
} // setup end
0 Bytes
Binary file not shown.

examples/SmartSwitch/data/index.htm

+4-3
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,12 @@
549549
}
550550

551551
function buttonOClick() {
552+
var murl = "";
552553
// If base auth
553-
var murl = document.location.href.replace("http://", "http://" + new Date().getTime() + "@");
554+
//murl = document.location.href.replace("http://", "http://" + new Date().getTime() + "@");
554555
// If cookie auth
555-
murl += 'login';
556-
if (document.location.host.length < 5) murl = 'http://' + MYCORS + '/login'; //CORS
556+
murl += 'login/';
557+
if (document.location.host.length < 5) murl = 'http://' + MYCORS + '/login/'; //CORS
557558
warningNotification({ message: 'Logout'});
558559
window.open(murl, '_self');
559560
}
-3.25 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.

extras/README.md

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
### Extras
2-
32
Additions to facilitate code modifications (for MS Win, similar can be done on Linux)
43

5-
**ehg.c (ehg.exe):** Tool to generate C-code array from file' bytes
4+
- **ehg.c (ehg.exe):** Tool to generate C-code array from file' bytes
65
Based on [bin2array](https://github.com/TheLivingOne/bin2array/) PROGMEM keyword can optionally be added.
76

8-
**rehg.c (rehg.exe):** Tool to reverse C-code array generated by **ehg.exe** back to a file
7+
- **rehg.c (rehg.exe):** Tool to reverse C-code array generated by **ehg.exe** back to a file
98
Based on [c2bin](https://github.com/birkett/cbintools/tree/master/c2bin)
109
First 4 lines of source are ignored, then parses the 0xHH - formated bytes
1110
until a } is found on separate new line.
1211

1312
### Tools
14-
15-
[TCC : Tiny C Compiler](https://bellard.org/tcc/) for **ehg** and **rehg** compiling on MS Win
16-
17-
[7-Zip](https://www.7-zip.org) Install 7z and use the included gzip as command line tool
18-
[Node.js](https://nodejs.org) Install Node with default settings, then run:
13+
- [TCC : Tiny C Compiler](https://bellard.org/tcc/) for **ehg** and **rehg** compiling on MS Win
14+
- [7-Zip](https://www.7-zip.org) Install 7z and use the included gzip as command line tool
15+
- [Node.js](https://nodejs.org) Install Node with default settings, then run:
1916

2017
``` npm install html-minifier-terser -g, npm install -g github-files-fetcher ```
2118

2219
### Batch files provided
23-
24-
**do.bat:** Generates **edit.htm.gz.h** file
25-
26-
**undo.bat:** Reverts **edit.htm** from C array header to file (still minified!)
27-
28-
**update_ace.bat:** Updates **acefull.js.gz** file from latest GitHub Ace sources
20+
- **do.bat:** Generates **edit.htm.gz.h** file
21+
- **undo.bat:** Reverts **edit.htm** from C array header to file (still minified!)
22+
- **update_ace.bat:** Updates **acefull.js.gz** file from latest GitHub Ace sources

extras/update_ace.bat

+11-3
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,24 @@ call fetcher --url="https://github.com/ajaxorg/ace-builds/blob/master/src-min-no
1616
cd tmp1
1717
type ace.js mode-html.js theme-monokai.js ext-searchbox.js > acefull.js
1818
"C:\Program Files\7-Zip\7z.exe" a -tgzip -mx9 acefull.js.gz acefull.js
19-
REM
2019
"C:\Program Files\7-Zip\7z.exe" a -tgzip -mx9 worker-html.js.gz worker-html.js
2120
"C:\Program Files\7-Zip\7z.exe" a -tgzip -mx9 worker-javascript.js.gz worker-javascript.js
2221
"C:\Program Files\7-Zip\7z.exe" a -tgzip -mx9 worker-css.js.gz worker-css.js
2322

24-
REM update:
23+
REM update SmartSwitch /data:
2524
pause
2625
copy acefull.js.gz ..\..\examples\SmartSwitch\data\acefull.js.gz
27-
REM
2826
copy worker-html.js.gz ..\..\examples\SmartSwitch\data\worker-html.js.gz
2927
copy worker-javascript.js.gz ..\..\examples\SmartSwitch\data\worker-javascript.js.gz
3028
copy worker-css.js.gz ..\..\examples\SmartSwitch\data\worker-css.js.gz
29+
30+
REM update ESP_AsyncFSBrowser /data:
31+
pause
32+
copy acefull.js.gz ..\..\examples\ESP_AsyncFSBrowser\data\acefull.js.gz
33+
copy worker-html.js.gz ..\..\examples\ESP_AsyncFSBrowser\data\worker-html.js.gz
34+
copy worker-javascript.js.gz ..\..\examples\ESP_AsyncFSBrowser\data\worker-javascript.js.gz
35+
copy worker-css.js.gz ..\..\examples\ESP_AsyncFSBrowser\data\worker-css.js.gz
36+
37+
REM delete temporary stuff
38+
pause
3139
del *.js *.gz

src/SPIFFSEditor.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
#include "edit.htm.gz.h"
55

6+
#ifdef ESP32
7+
#define fullName(x) name(x)
8+
#endif
9+
610
#define SPIFFS_MAXLENGTH_FILEPATH 32
711
const char *excludeListFile = "/.exclude.files";
812

@@ -190,7 +194,10 @@ void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request){
190194
while(dir.next()){
191195
fs::File entry = dir.openFile("r");
192196
#endif
193-
if (isExcluded(_fs, entry.name())) {
197+
String fname = entry.fullName();
198+
if (fname.charAt(0) != '/') fname = "/" + fname;
199+
200+
if (isExcluded(_fs, fname.c_str())) {
194201
#ifdef ESP32
195202
entry = dir.openNextFile();
196203
#endif
@@ -200,7 +207,7 @@ void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request){
200207
output += "{\"type\":\"";
201208
output += "file";
202209
output += "\",\"name\":\"";
203-
output += String(entry.name());
210+
output += String(fname);
204211
output += "\",\"size\":";
205212
output += String(entry.size());
206213
output += "}";
@@ -218,7 +225,7 @@ void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request){
218225
output = String();
219226
}
220227
else if(request->hasParam("edit") || request->hasParam("download")){
221-
request->send(request->_tempFile, request->_tempFile.name(), String(), request->hasParam("download"));
228+
request->send(request->_tempFile, request->_tempFile.fullName(), String(), request->hasParam("download"));
222229
}
223230
else {
224231
const char * buildTime = __DATE__ " " __TIME__ " GMT";

src/edit.htm

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
43
<head>
54
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
65
<title>ESP Editor</title>
@@ -196,7 +195,7 @@
196195
t.append("path", e), requests.add("PUT", "/edit", t, a)
197196
}
198197
var o = ce("button");
199-
o.innerHTML = "Refresh List", ge(e).appendChild(o);
198+
o.innerHTML = "Root Dir", ge(e).appendChild(o);
200199
var c = ce("input");
201200
c.type = "file", c.multiple = !1, c.name = "data", c.id = "upload-select", ge(e).appendChild(c);
202201
var d = ce("input");
@@ -255,6 +254,7 @@
255254
}
256255

257256
function createTree(e, t) {
257+
258258
function n(e) {
259259
ge("download-frame").src = "/edit?download=" + e
260260
}
@@ -274,10 +274,12 @@
274274
t.loadUrl(i), document.body.getElementsByClassName("cm").length > 0 && document.body.removeChild(e)
275275
});
276276
var d = ce("li");
277-
o.appendChild(d), d.innerHTML = "<span>Download</span>", d.onclick = function(t) {
277+
o.appendChild(d), s(i) || r(i) ? (d.innerHTML = "<span>Download</span>", d.onclick = function(t) {
278278
n(i), document.body.getElementsByClassName("cm").length > 0 && document.body.removeChild(e)
279-
};
280-
var l = ce("li");
279+
}) : z(i) ? (o.appendChild(d), d.innerHTML = "<span>ChDir</span>", d.onclick = function(t) {
280+
f.removeChild(f.childNodes[0]), m(f, i), document.body.getElementsByClassName("cm").length > 0 && document.body.removeChild(e)
281+
}) : ();
282+
var l = ce("li");
281283
o.appendChild(l), l.innerHTML = "<span>Delete</span>", l.onclick = function(t) {
282284
u(i), document.body.getElementsByClassName("cm").length > 0 && document.body.removeChild(e)
283285
}
@@ -302,7 +304,7 @@
302304
c.id = n;
303305
var d = ce("span");
304306
return d.innerHTML = n, c.appendChild(d), c.onclick = function(e) {
305-
s(c.id.toLowerCase()) ? t.loadUrl(c.id) : r(c.id.toLowerCase()) && a(c.id)
307+
s(c.id.toLowerCase()) ? t.loadUrl(c.id) : r(c.id.toLowerCase()) ? a(c.id) : z(c.id) ? f.removeChild(f.childNodes[0]) && m(f, c.id.toLowerCase()) : ()
306308
}, c.oncontextmenu = function(e) {
307309
e.preventDefault(), e.stopPropagation(), o(e, c.id, !0)
308310
}, c
@@ -314,6 +316,11 @@
314316
e.appendChild(a);
315317
for (var i = n.length, o = 0; i > o; o++) "file" === n[o].type && a.appendChild(c(t, n[o].name, n[o].size))
316318
}
319+
320+
function z(e) {
321+
if (e.indexOf('.') == -1) return !0
322+
else return !1
323+
}
317324

318325
function s(e) {
319326
var t = /(?:.([^.]+))?$/.exec(e)[1];

0 commit comments

Comments
 (0)