diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index a8e6b5f..b6e35f5 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -127,7 +127,7 @@ void setup() { // read status from PinWIPE to WIPE // when PinWIPE is set to LOW, format LittleFS if(digitalRead(PinWIPE) != PinWIPE_default) { - LFS_format(); + LFS_Format(); Restart(); } diff --git a/Arduino/CanGrow/cangrow.sh b/Arduino/CanGrow/cangrow.sh index 89f0ae9..e7a1749 100755 --- a/Arduino/CanGrow/cangrow.sh +++ b/Arduino/CanGrow/cangrow.sh @@ -123,8 +123,11 @@ case $1 in ;; w|webupload) - echo ":: Uploading to $IP" - curl -v http://$IP/system/applyUpdate -X POST -H 'Content-Type: multipart/form-data' -F "firmware=@$(pwd)/build/CanGrow.ino.bin" + test -z "$2" && UPLOAD_FILE="$(pwd)/build/CanGrow.ino.bin" + test -n "$2" && UPLOAD_FILE="$2" + + echo ":: Uploading $UPLOAD_FILE to $IP" + curl -v http://$IP/system/update -X POST -H 'Content-Type: multipart/form-data' -F "firmware=@${UPLOAD_FILE}" echo ;; m|mon|monitor) diff --git a/Arduino/CanGrow/include/CanGrow_LittleFS.h b/Arduino/CanGrow/include/CanGrow_LittleFS.h index 6902447..71e9058 100644 --- a/Arduino/CanGrow/include/CanGrow_LittleFS.h +++ b/Arduino/CanGrow/include/CanGrow_LittleFS.h @@ -47,7 +47,7 @@ void LFS_Init() { } } -void LFS_format() { +void LFS_Format() { Serial.println(":: [LittleFS] formatting..."); // ESP32 LittleFS needs begin() first, otherwise it would crash // ESP8266 does not need it, so we leave it diff --git a/Arduino/CanGrow/include/CanGrow_Webserver.h b/Arduino/CanGrow/include/CanGrow_Webserver.h index 7462a4d..771df33 100644 --- a/Arduino/CanGrow/include/CanGrow_Webserver.h +++ b/Arduino/CanGrow/include/CanGrow_Webserver.h @@ -96,6 +96,9 @@ void Webserver_Init() { webserver.on("/system/restart", HTTP_GET, WebPage_system_restart); webserver.on("/system/restart", HTTP_POST, WebPage_system_restart); + webserver.on("/system/wipe", HTTP_GET, WebPage_system_wipe); + webserver.on("/system/wipe", HTTP_POST, WebPage_system_wipe); + requestLogger.setOutput(Serial); // this activates the middleware if(configSystem.httpLogSerial == true) { diff --git a/Arduino/CanGrow/include/Webserver/Page_system.h b/Arduino/CanGrow/include/Webserver/Page_system.h index 2dd3f29..370b046 100644 --- a/Arduino/CanGrow/include/Webserver/Page_system.h +++ b/Arduino/CanGrow/include/Webserver/Page_system.h @@ -75,7 +75,7 @@ void WebPage_system_restart(AsyncWebServerRequest *request) { if(request->hasParam("confirmed", true)) { Serial.println(":: [Webserver:system:restart] POST[confirmed]: is set, triggering restart"); - // force a small delay to ensure client has received http payload + doRestart = true; } @@ -138,3 +138,41 @@ void WebPage_system_update(AsyncWebServerRequest *request) { } +/* + * Subpage restart + */ +String Proc_WebPage_system_wipe(const String& var) { + if(TestHeaderFooter(var)) { + return AddHeaderFooter(var); + } else if(var == "WIPE_MSG") { + return String(Page_system_wipe_HTML_WIPE_MSG); + } else { + return String(); + } +} + +String Proc_WebPage_system_wipe_POST(const String& var) { + if(var == "WIPE_MSG") { + return String(Page_system_wipe_HTML_WIPE_MSG_POST); + } else { + return Proc_WebPage_system_wipe(var); + } +} + +void WebPage_system_wipe(AsyncWebServerRequest *request) { + if(request->method() == HTTP_POST) { + request->send_P(200, "text/html", Page_system_wipe_HTML, Proc_WebPage_system_wipe_POST); + + if(request->hasParam("confirmed", true)) { + Serial.println(":: [Webserver:system:wipe] POST[confirmed]: is set, triggering wipe / factory reset"); + LFS_Format(); + Serial.println(":: [Webserver:system:wipe] triggering restart"); + doRestart = true; + } + + } else { + request->send_P(200, "text/html", Page_system_wipe_HTML, Proc_WebPage_system_wipe); + } + +} + diff --git a/Arduino/CanGrow/include/Webserver/Page_system_HTML.h b/Arduino/CanGrow/include/Webserver/Page_system_HTML.h index 612c4c2..c04a7a6 100644 --- a/Arduino/CanGrow/include/Webserver/Page_system_HTML.h +++ b/Arduino/CanGrow/include/Webserver/Page_system_HTML.h @@ -117,3 +117,27 @@ const char* Page_system_restart_HTML_RESTART_MSG PROGMEM = R"(Do you want to res )"; const char* Page_system_restart_HTML_RESTART_MSG_POST PROGMEM = R"(Restarting...)"; + + + + +/* + * Subpage wipe + */ +const char* Page_system_wipe_HTML PROGMEM = R"(%HEADER% +

💣 Factory reset

+
+%WIPE_MSG% +
+ +%FOOTER%)"; + +const char* Page_system_wipe_HTML_WIPE_MSG PROGMEM = R"(All settings will be removed!!

+Please confirm wiping LittleFS +

+Please confirm:
+ +
)"; + + +const char* Page_system_wipe_HTML_WIPE_MSG_POST PROGMEM = R"(Restarting...)";