diff --git a/Page1.png b/Page1.png index 5c6f46b6..c495615c 100644 Binary files a/Page1.png and b/Page1.png differ diff --git a/Page2.png b/Page2.png index bd222235..a45ec602 100644 Binary files a/Page2.png and b/Page2.png differ diff --git a/Page3.png b/Page3.png index b7f91a8d..e13829d2 100644 Binary files a/Page3.png and b/Page3.png differ diff --git a/Page4.png b/Page4.png index dbc20c64..0dd26a6c 100644 Binary files a/Page4.png and b/Page4.png differ diff --git a/Page6.png b/Page6.png index 622bd2d2..5e9e3d23 100644 Binary files a/Page6.png and b/Page6.png differ diff --git a/README.md b/README.md index 4158bcd0..a306acda 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ the template files are stored on SPIFFS: and uploaded using [IDE](http://arduino.esp8266.com/versions/1.6.5-1160-gef26c5f/doc/reference.html#file-system) The list of keywords can be find here : https://github.com/luc-github/ESP8266/blob/master/keywords.txt Any files on SPIFFS can be called on web interface without having the path hard coded - this give more flexibility, favicon.ico is a good example of it. -So UI is kind of separated from FW which allow easier modifications. +So UI is kind of separated from FW which allow easier modifications. For this a light file manager is available in extra settings page, it allows to upload/download/delete files. as SPIFFS is flat filesystem no directory management is necessary so it is very simple. Additionally 404.tpl (the page not found) and restart.tpl(restart page when applying changes) are not mandatory, a fail safe version is embeded if they are not present. diff --git a/esp8266/data - for more than 64K SPIFFS/header.inc b/esp8266/data - for more than 64K SPIFFS/header.inc index e426852b..1fbdee0c 100644 --- a/esp8266/data - for more than 64K SPIFFS/header.inc +++ b/esp8266/data - for more than 64K SPIFFS/header.inc @@ -15,7 +15,7 @@ $INCLUDE[css.inc]$ AP Configuration Station Configuration Printer Status - Printer Settings + Extra Settings   FW: V$FW_VER$ Github diff --git a/esp8266/data - for more than 64K SPIFFS/settings.tpl b/esp8266/data - for more than 64K SPIFFS/settings.tpl index 76c69278..438be91f 100644 --- a/esp8266/data - for more than 64K SPIFFS/settings.tpl +++ b/esp8266/data - for more than 64K SPIFFS/settings.tpl @@ -1,6 +1,6 @@ $INCLUDE[header.inc]$
-
Printer Settings
+
Extra Settings

@@ -22,6 +22,65 @@ $SUCCESS_MSG$
+
+
Filesystem
+
+ +

+
Namesize
+ +
+
+ $INCLUDE[footer.inc]$ diff --git a/esp8266/data/header.inc b/esp8266/data/header.inc index e426852b..1fbdee0c 100644 --- a/esp8266/data/header.inc +++ b/esp8266/data/header.inc @@ -15,7 +15,7 @@ $INCLUDE[css.inc]$ AP Configuration Station Configuration Printer Status - Printer Settings + Extra Settings   FW: V$FW_VER$ Github diff --git a/esp8266/data/settings.tpl b/esp8266/data/settings.tpl index 76c69278..438be91f 100644 --- a/esp8266/data/settings.tpl +++ b/esp8266/data/settings.tpl @@ -1,6 +1,6 @@ $INCLUDE[header.inc]$
-
Printer Settings
+
Extra Settings

@@ -22,6 +22,65 @@ $SUCCESS_MSG$
+
+
Filesystem
+
+ +

+
Namesize
+ +
+
+ $INCLUDE[footer.inc]$ diff --git a/esp8266/webinterface.cpp b/esp8266/webinterface.cpp index b6dda1dd..ecc0a795 100644 --- a/esp8266/webinterface.cpp +++ b/esp8266/webinterface.cpp @@ -180,7 +180,7 @@ const char KEY_E_FEEDRATE [] PROGMEM = "$E_FEEDRATE$"; const char KEY_XY_FEEDRATE_STATUS [] PROGMEM = "$XY_FEEDRATE_STATUS$"; const char KEY_Z_FEEDRATE_STATUS [] PROGMEM = "$Z_FEEDRATE_STATUS$"; const char KEY_E_FEEDRATE_STATUS [] PROGMEM = "$E_FEEDRATE_STATUS$"; -const char VALUE_SETTINGS [] PROGMEM = "Printer Settings"; +const char VALUE_SETTINGS [] PROGMEM = "Extra Settings"; const char KEY_REFRESH_PAGE_STATUS [] PROGMEM = "$REFRESH_PAGE_STATUS$"; bool WEBINTERFACE_CLASS::isHostnameValid(const char * hostname) @@ -2306,13 +2306,24 @@ void handle_web_interface_status() buffer2send+="\"}"; } buffer2send+="]"; -// buffer2send+="\"end\":\"end\""; buffer2send+="}"; - web_interface->WebServer.send(200, "text/plain",buffer2send); + web_interface->WebServer.send(200, "application/json",buffer2send); Serial.println(system_get_free_heap_size()); } +String formatBytes(size_t bytes){ + if (bytes < 1024){ + return String(bytes)+"oct"; + } else if(bytes < (1024 * 1024)){ + return String(bytes/1024.0)+"Ko"; + } else if(bytes < (1024 * 1024 * 1024)){ + return String(bytes/1024.0/1024.0)+"Mo"; + } else { + return String(bytes/1024.0/1024.0/1024.0)+"Go"; + } +} + String getContentType(String filename){ if(filename.endsWith(".htm")) return "text/html"; else if(filename.endsWith(".html")) return "text/html"; @@ -2331,6 +2342,65 @@ String getContentType(String filename){ else if(filename.endsWith(".txt")) return "text/plain"; return "application/octet-stream"; } +void handleFileUpload(){ + if(web_interface->WebServer.uri() != "/FILES") return; + HTTPUpload& upload = (web_interface->WebServer).upload(); + if(upload.status == UPLOAD_FILE_START){ + String filename = upload.filename; + web_interface->fsUploadFile = SPIFFS.open(filename, "w"); + filename = String(); + } else if(upload.status == UPLOAD_FILE_WRITE){ + if(web_interface->fsUploadFile) + { + web_interface->fsUploadFile.write(upload.buf, upload.currentSize); + } + } else if(upload.status == UPLOAD_FILE_END){ + if(web_interface->fsUploadFile) + web_interface->fsUploadFile.close(); + } + else Serial.println("Cannot open file"); +} + +void handleFileList() { + String path = "/"; + String status="Ok"; + if(web_interface->WebServer.hasArg("action")) { + if(web_interface->WebServer.arg("action")=="delete" && web_interface->WebServer.hasArg("filename")) + { + String filename; + web_interface->urldecode(filename,web_interface->WebServer.arg("filename").c_str()); + if(!SPIFFS.exists(filename)){ + status="Cannot delete, file not found!"; + } + else + { + SPIFFS.remove(filename); + } + } + } + String jsonfile = "{\"path\":\"" + path + "\","; + Dir dir = SPIFFS.openDir(path); + jsonfile+="\"files\":["; + bool firstentry=true; + while (dir.next()) { + if (!firstentry) jsonfile+=","; + else firstentry=false; + jsonfile+="{"; + jsonfile+="\"name\":\""; + jsonfile+=dir.fileName(); + jsonfile+="\",\"size\":\""; + File f = dir.openFile("r"); + jsonfile+=formatBytes(f.size()); + jsonfile+="\""; + jsonfile+="}"; + f.close(); + } + jsonfile+="],"; + jsonfile+="\"status\":\"" + status + "\""; + jsonfile+="}"; + path = ""; + web_interface->WebServer.send(200, "application/json", jsonfile); +} //do a redirect to avoid to many query //and handle not registred path @@ -2558,6 +2628,8 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port) WebServer.on("/PRINTER",HTTP_ANY, handle_web_interface_printer); WebServer.on("/CMD",HTTP_ANY, handle_web_command); WebServer.on("/RESTART",HTTP_GET, handle_restart); + WebServer.on("/FILES", HTTP_ANY, handleFileList); + WebServer.onFileUpload(handleFileUpload); //Captive portal Feature #ifdef CAPTIVE_PORTAL_FEATURE WebServer.on("/generate_204",HTTP_ANY, handle_web_interface_root); @@ -2580,6 +2652,7 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port) info_msg.setlenght(50); status_msg.setsize(4); status_msg.setlenght(50); + fsUploadFile=(fs::File)0; } //Destructor WEBINTERFACE_CLASS::~WEBINTERFACE_CLASS() diff --git a/esp8266/webinterface.h b/esp8266/webinterface.h index 31aa3744..adf37632 100644 --- a/esp8266/webinterface.h +++ b/esp8266/webinterface.h @@ -24,6 +24,7 @@ #include #include #include +#include #include "storestrings.h" #define MAX_EXTRUDERS 4 @@ -34,6 +35,7 @@ class WEBINTERFACE_CLASS WEBINTERFACE_CLASS (int port = 80); ~WEBINTERFACE_CLASS(); ESP8266WebServer WebServer; + File fsUploadFile; void urldecode( String & dst, const char *src); bool isSSIDValid(const char * ssid); bool isPasswordValid(const char * password); diff --git a/page5.png b/page5.png index 562ef829..9814821f 100644 Binary files a/page5.png and b/page5.png differ