Skip to content

Commit

Permalink
LittleFS can be used (a choice for ESP8266 for now)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
lorol authored and Jurij Retzlaff committed Sep 11, 2022
1 parent ef69271 commit b722f09
Show file tree
Hide file tree
Showing 26 changed files with 424 additions and 391 deletions.
215 changes: 110 additions & 105 deletions README.md

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions examples/ESP_AsyncFSBrowser/ESP_AsyncFSBrowser.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define USE_LittleFS // possible only for ESP8266 for now

#include <ArduinoOTA.h>
#ifdef ESP32
#include <FS.h>
Expand All @@ -6,6 +8,11 @@
#include <WiFi.h>
#include <AsyncTCP.h>
#elif defined(ESP8266)
#ifdef USE_LittleFS
#include <FS.h>
#define SPIFFS LittleFS
#include <LittleFS.h>
#endif
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESP8266mDNS.h>
Expand Down
Binary file removed examples/ESP_AsyncFSBrowser/data/ace.js.gz
Binary file not shown.
Binary file added examples/ESP_AsyncFSBrowser/data/acefull.js.gz
Binary file not shown.
Binary file removed examples/ESP_AsyncFSBrowser/data/ext-searchbox.js.gz
Binary file not shown.
Binary file added examples/ESP_AsyncFSBrowser/data/folder/image.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/ESP_AsyncFSBrowser/data/folder/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test
Binary file removed examples/ESP_AsyncFSBrowser/data/mode-css.js.gz
Binary file not shown.
Binary file removed examples/ESP_AsyncFSBrowser/data/mode-html.js.gz
Binary file not shown.
Binary file not shown.
Binary file added examples/ESP_AsyncFSBrowser/data/worker-css.js.gz
Binary file not shown.
Binary file modified examples/ESP_AsyncFSBrowser/data/worker-html.js.gz
Binary file not shown.
Binary file not shown.
48 changes: 16 additions & 32 deletions examples/SmartSwitch/README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
<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">

## SmartSwitch

* Remote Temperature Control application with schedule

(example: car block heater or car battery charger for winter)

* Based on [ESP_AsyncFSBrowser](https://github.com/lorol/ESPAsyncWebServer/tree/master/examples/ESP_AsyncFSBrowser) example that uses embedded ACE editor

* Wide browser compatibility, no extra server-side needed

* HTTP server and WebSocket on same port

* Standalone, no JS dependencies for the browser from Internet

* [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)

* Added [ESPAsyncWiFiManager](https://github.com/alanswx/ESPAsyncWiFiManager) and fallback AP mode after timeout

* Real Time (NTP) w/ Time Zones. Sync from browser time if in AP mode

* Memorized settings to EEPROM

* Multiple clients can be connected at same time, they see each other' requests

* Authentication variants including [Cookie-based](https://github.com/me-no-dev/ESPAsyncWebServer/pull/684) idea

* Used [this Xtea implementation](https://github.com/franksmicro/Arduino/tree/master/libraries/Xtea) for getting a fancier Cookie token

* Default credentials **smart : switch** or only **switch** as password

* OTA included

* Use the latest ESP8266 ESP32 cores from GitHub
- Remote Temperature Control application with schedule
(example: car block heater or car battery charger for winter)
- Based on [ESP_AsyncFSBrowser](https://github.com/lorol/ESPAsyncWebServer/tree/master/examples/ESP_AsyncFSBrowser) example that uses embedded ACE editor
- Wide browser compatibility, no extra server-side needed
- HTTP server and WebSocket on same port
- Standalone, no JS dependencies for the browser from Internet
- [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)
- Added [ESPAsyncWiFiManager](https://github.com/alanswx/ESPAsyncWiFiManager) and fallback AP mode after timeout
- Real Time (NTP) w/ Time Zones. Sync from browser time if in AP mode
- Memorized settings to EEPROM
- Multiple clients can be connected at same time, they see each other' requests
- Authentication variants including [Cookie-based](https://github.com/me-no-dev/ESPAsyncWebServer/pull/684) idea
- Used [this Xtea implementation](https://github.com/franksmicro/Arduino/tree/master/libraries/Xtea) for getting a fancier Cookie token
- Default credentials **smart : switch** or only **switch** as password
- OTA included
- Use the latest ESP8266 ESP32 cores from GitHub
20 changes: 18 additions & 2 deletions examples/SmartSwitch/SmartSwitch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Multiple clients can be connected at same time, they see each other requests
Use latest ESP core lib (from Github)
*/

#define USE_LittleFS // possible only for ESP8266 for now

#define USE_WFM // to use ESPAsyncWiFiManager
//#define DEL_WFM // delete Wifi credentials stored
//(use once then comment and flash again), also HTTP /erase-wifi can do the same live
Expand Down Expand Up @@ -44,10 +46,16 @@ Use latest ESP core lib (from Github)
#include <WiFi.h>
#include <AsyncTCP.h>
#elif defined(ESP8266)
#ifdef USE_LittleFS
#include <FS.h>
#define SPIFFS LittleFS
#include <LittleFS.h>
#endif
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESP8266mDNS.h>
#endif

#include <ESPAsyncWebServer.h>
#ifdef USE_WFM
#include "ESPAsyncWiFiManager.h"
Expand All @@ -62,6 +70,7 @@ Use latest ESP core lib (from Github)
#include "Xtea.h"
#endif


#define RTC_UTC_TEST 1577836800 // Some Date
#define MYTZ PSTR("EST5EDT,M3.2.0,M11.1.0")

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

//SPIFFS
SPIFFS.begin();
//FS
if (SPIFFS.begin()) {
Serial.print(F("FS mounted\n"));
} else {
Serial.print(F("FS mount failed\n"));
}

#ifdef USE_AUTH_WS
ws.setAuthentication(http_username,http_password);
Expand Down Expand Up @@ -676,7 +689,10 @@ void setup(){
ArduinoOTA.setHostname(hostName);
ArduinoOTA.onStart([]() {
Serial.print(F("OTA Started ...\n"));
SPIFFS.end(); // Clean FS
ws.textAll("Now,OTA"); // for all clients
ws.enable(false);
ws.closeAll();
});
ArduinoOTA.begin();
} // setup end
Expand Down
Binary file modified examples/SmartSwitch/data/acefull.js.gz
Binary file not shown.
7 changes: 4 additions & 3 deletions examples/SmartSwitch/data/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,12 @@
}

function buttonOClick() {
var murl = "";
// If base auth
var murl = document.location.href.replace("http://", "http://" + new Date().getTime() + "@");
//murl = document.location.href.replace("http://", "http://" + new Date().getTime() + "@");
// If cookie auth
murl += 'login';
if (document.location.host.length < 5) murl = 'http://' + MYCORS + '/login'; //CORS
murl += 'login/';
if (document.location.host.length < 5) murl = 'http://' + MYCORS + '/login/'; //CORS
warningNotification({ message: 'Logout'});
window.open(murl, '_self');
}
Expand Down
Binary file removed examples/SmartSwitch/data/index.min.htm.gz
Binary file not shown.
Binary file modified examples/SmartSwitch/data/worker-css.js.gz
Binary file not shown.
Binary file modified examples/SmartSwitch/data/worker-html.js.gz
Binary file not shown.
Binary file modified examples/SmartSwitch/data/worker-javascript.js.gz
Binary file not shown.
22 changes: 8 additions & 14 deletions extras/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
### Extras

Additions to facilitate code modifications (for MS Win, similar can be done on Linux)

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

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

### Tools

[TCC : Tiny C Compiler](https://bellard.org/tcc/) for **ehg** and **rehg** compiling on MS Win

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

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

### Batch files provided

**do.bat:** Generates **edit.htm.gz.h** file

**undo.bat:** Reverts **edit.htm** from C array header to file (still minified!)

**update_ace.bat:** Updates **acefull.js.gz** file from latest GitHub Ace sources
- **do.bat:** Generates **edit.htm.gz.h** file
- **undo.bat:** Reverts **edit.htm** from C array header to file (still minified!)
- **update_ace.bat:** Updates **acefull.js.gz** file from latest GitHub Ace sources
14 changes: 11 additions & 3 deletions extras/update_ace.bat
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@ call fetcher --url="https://github.com/ajaxorg/ace-builds/blob/master/src-min-no
cd tmp1
type ace.js mode-html.js theme-monokai.js ext-searchbox.js > acefull.js
"C:\Program Files\7-Zip\7z.exe" a -tgzip -mx9 acefull.js.gz acefull.js
REM
"C:\Program Files\7-Zip\7z.exe" a -tgzip -mx9 worker-html.js.gz worker-html.js
"C:\Program Files\7-Zip\7z.exe" a -tgzip -mx9 worker-javascript.js.gz worker-javascript.js
"C:\Program Files\7-Zip\7z.exe" a -tgzip -mx9 worker-css.js.gz worker-css.js

REM update:
REM update SmartSwitch /data:
pause
copy acefull.js.gz ..\..\examples\SmartSwitch\data\acefull.js.gz
REM
copy worker-html.js.gz ..\..\examples\SmartSwitch\data\worker-html.js.gz
copy worker-javascript.js.gz ..\..\examples\SmartSwitch\data\worker-javascript.js.gz
copy worker-css.js.gz ..\..\examples\SmartSwitch\data\worker-css.js.gz

REM update ESP_AsyncFSBrowser /data:
pause
copy acefull.js.gz ..\..\examples\ESP_AsyncFSBrowser\data\acefull.js.gz
copy worker-html.js.gz ..\..\examples\ESP_AsyncFSBrowser\data\worker-html.js.gz
copy worker-javascript.js.gz ..\..\examples\ESP_AsyncFSBrowser\data\worker-javascript.js.gz
copy worker-css.js.gz ..\..\examples\ESP_AsyncFSBrowser\data\worker-css.js.gz

REM delete temporary stuff
pause
del *.js *.gz
13 changes: 10 additions & 3 deletions src/SPIFFSEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#include "edit.htm.gz.h"

#ifdef ESP32
#define fullName(x) name(x)
#endif

#define SPIFFS_MAXLENGTH_FILEPATH 32
const char *excludeListFile = "/.exclude.files";

Expand Down Expand Up @@ -190,7 +194,10 @@ void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request){
while(dir.next()){
fs::File entry = dir.openFile("r");
#endif
if (isExcluded(_fs, entry.name())) {
String fname = entry.fullName();
if (fname.charAt(0) != '/') fname = "/" + fname;

if (isExcluded(_fs, fname.c_str())) {
#ifdef ESP32
entry = dir.openNextFile();
#endif
Expand All @@ -200,7 +207,7 @@ void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request){
output += "{\"type\":\"";
output += "file";
output += "\",\"name\":\"";
output += String(entry.name());
output += String(fname);
output += "\",\"size\":";
output += String(entry.size());
output += "}";
Expand All @@ -218,7 +225,7 @@ void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request){
output = String();
}
else if(request->hasParam("edit") || request->hasParam("download")){
request->send(request->_tempFile, request->_tempFile.name(), String(), request->hasParam("download"));
request->send(request->_tempFile, request->_tempFile.fullName(), String(), request->hasParam("download"));
}
else {
const char * buildTime = __DATE__ " " __TIME__ " GMT";
Expand Down
19 changes: 13 additions & 6 deletions src/edit.htm
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>ESP Editor</title>
Expand Down Expand Up @@ -196,7 +195,7 @@
t.append("path", e), requests.add("PUT", "/edit", t, a)
}
var o = ce("button");
o.innerHTML = "Refresh List", ge(e).appendChild(o);
o.innerHTML = "Root Dir", ge(e).appendChild(o);
var c = ce("input");
c.type = "file", c.multiple = !1, c.name = "data", c.id = "upload-select", ge(e).appendChild(c);
var d = ce("input");
Expand Down Expand Up @@ -255,6 +254,7 @@
}

function createTree(e, t) {

function n(e) {
ge("download-frame").src = "/edit?download=" + e
}
Expand All @@ -274,10 +274,12 @@
t.loadUrl(i), document.body.getElementsByClassName("cm").length > 0 && document.body.removeChild(e)
});
var d = ce("li");
o.appendChild(d), d.innerHTML = "<span>Download</span>", d.onclick = function(t) {
o.appendChild(d), s(i) || r(i) ? (d.innerHTML = "<span>Download</span>", d.onclick = function(t) {
n(i), document.body.getElementsByClassName("cm").length > 0 && document.body.removeChild(e)
};
var l = ce("li");
}) : z(i) ? (o.appendChild(d), d.innerHTML = "<span>ChDir</span>", d.onclick = function(t) {
f.removeChild(f.childNodes[0]), m(f, i), document.body.getElementsByClassName("cm").length > 0 && document.body.removeChild(e)
}) : ();
var l = ce("li");
o.appendChild(l), l.innerHTML = "<span>Delete</span>", l.onclick = function(t) {
u(i), document.body.getElementsByClassName("cm").length > 0 && document.body.removeChild(e)
}
Expand All @@ -302,7 +304,7 @@
c.id = n;
var d = ce("span");
return d.innerHTML = n, c.appendChild(d), c.onclick = function(e) {
s(c.id.toLowerCase()) ? t.loadUrl(c.id) : r(c.id.toLowerCase()) && a(c.id)
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()) : ()
}, c.oncontextmenu = function(e) {
e.preventDefault(), e.stopPropagation(), o(e, c.id, !0)
}, c
Expand All @@ -314,6 +316,11 @@
e.appendChild(a);
for (var i = n.length, o = 0; i > o; o++) "file" === n[o].type && a.appendChild(c(t, n[o].name, n[o].size))
}

function z(e) {
if (e.indexOf('.') == -1) return !0
else return !1
}

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

0 comments on commit b722f09

Please sign in to comment.