implement webui littlefs wipe
This commit is contained in:
parent
22fdfc57c2
commit
5af5bcd94d
6 changed files with 73 additions and 5 deletions
|
@ -127,7 +127,7 @@ void setup() {
|
||||||
// read status from PinWIPE to WIPE
|
// read status from PinWIPE to WIPE
|
||||||
// when PinWIPE is set to LOW, format LittleFS
|
// when PinWIPE is set to LOW, format LittleFS
|
||||||
if(digitalRead(PinWIPE) != PinWIPE_default) {
|
if(digitalRead(PinWIPE) != PinWIPE_default) {
|
||||||
LFS_format();
|
LFS_Format();
|
||||||
Restart();
|
Restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,8 +123,11 @@ case $1 in
|
||||||
|
|
||||||
;;
|
;;
|
||||||
w|webupload)
|
w|webupload)
|
||||||
echo ":: Uploading to $IP"
|
test -z "$2" && UPLOAD_FILE="$(pwd)/build/CanGrow.ino.bin"
|
||||||
curl -v http://$IP/system/applyUpdate -X POST -H 'Content-Type: multipart/form-data' -F "firmware=@$(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
|
echo
|
||||||
;;
|
;;
|
||||||
m|mon|monitor)
|
m|mon|monitor)
|
||||||
|
|
|
@ -47,7 +47,7 @@ void LFS_Init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LFS_format() {
|
void LFS_Format() {
|
||||||
Serial.println(":: [LittleFS] formatting...");
|
Serial.println(":: [LittleFS] formatting...");
|
||||||
// ESP32 LittleFS needs begin() first, otherwise it would crash
|
// ESP32 LittleFS needs begin() first, otherwise it would crash
|
||||||
// ESP8266 does not need it, so we leave it
|
// ESP8266 does not need it, so we leave it
|
||||||
|
|
|
@ -96,6 +96,9 @@ void Webserver_Init() {
|
||||||
webserver.on("/system/restart", HTTP_GET, WebPage_system_restart);
|
webserver.on("/system/restart", HTTP_GET, WebPage_system_restart);
|
||||||
webserver.on("/system/restart", HTTP_POST, 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);
|
requestLogger.setOutput(Serial);
|
||||||
// this activates the middleware
|
// this activates the middleware
|
||||||
if(configSystem.httpLogSerial == true) {
|
if(configSystem.httpLogSerial == true) {
|
||||||
|
|
|
@ -75,7 +75,7 @@ void WebPage_system_restart(AsyncWebServerRequest *request) {
|
||||||
|
|
||||||
if(request->hasParam("confirmed", true)) {
|
if(request->hasParam("confirmed", true)) {
|
||||||
Serial.println(":: [Webserver:system:restart] POST[confirmed]: is set, triggering restart");
|
Serial.println(":: [Webserver:system:restart] POST[confirmed]: is set, triggering restart");
|
||||||
// force a small delay to ensure client has received http payload
|
|
||||||
doRestart = true;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,3 +117,27 @@ const char* Page_system_restart_HTML_RESTART_MSG PROGMEM = R"(Do you want to res
|
||||||
</form>)";
|
</form>)";
|
||||||
|
|
||||||
const char* Page_system_restart_HTML_RESTART_MSG_POST PROGMEM = R"(Restarting...)";
|
const char* Page_system_restart_HTML_RESTART_MSG_POST PROGMEM = R"(Restarting...)";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Subpage wipe
|
||||||
|
*/
|
||||||
|
const char* Page_system_wipe_HTML PROGMEM = R"(%HEADER%
|
||||||
|
<h1>💣 Factory reset</h1>
|
||||||
|
<div class='warnmsg'>
|
||||||
|
%WIPE_MSG%
|
||||||
|
</div>
|
||||||
|
|
||||||
|
%FOOTER%)";
|
||||||
|
|
||||||
|
const char* Page_system_wipe_HTML_WIPE_MSG PROGMEM = R"(All settings will be removed!!<br><br>
|
||||||
|
Please confirm wiping LittleFS
|
||||||
|
<form action='/system/wipe' method='post'><br>
|
||||||
|
Please confirm: <input type='checkbox' id='confirmed' name='confirmed' required /><br>
|
||||||
|
<input type='submit' value='Confirm wiping' />
|
||||||
|
</form>)";
|
||||||
|
|
||||||
|
|
||||||
|
const char* Page_system_wipe_HTML_WIPE_MSG_POST PROGMEM = R"(Restarting...)";
|
||||||
|
|
Loading…
Reference in a new issue