diff --git a/Arduino/CanGrow/include/CanGrow.h b/Arduino/CanGrow/include/CanGrow.h index 4d35988..93186e7 100644 --- a/Arduino/CanGrow/include/CanGrow.h +++ b/Arduino/CanGrow/include/CanGrow.h @@ -44,8 +44,9 @@ #define CANGROW_SSID "CanGrow-unconfigured" // do we need a restart? (e.g. after wifi settings change) -bool needRestart; -bool doRestart; +bool needRestart = false; +// this triggers Restart() from the main loop +bool doRestart = false; // previous value of millis within the scheduler loop unsigned long schedulerPrevMillis = 0; diff --git a/Arduino/CanGrow/include/CanGrow_Webserver.h b/Arduino/CanGrow/include/CanGrow_Webserver.h index b93aed3..7462a4d 100644 --- a/Arduino/CanGrow/include/CanGrow_Webserver.h +++ b/Arduino/CanGrow/include/CanGrow_Webserver.h @@ -89,6 +89,10 @@ void Webserver_Init() { webserver.on("/wifi/", HTTP_POST, WebPage_wifi); webserver.on("/system/", HTTP_GET, WebPage_system); webserver.on("/system/", HTTP_POST, WebPage_system); + + webserver.on("/system/update", HTTP_GET, WebPage_system_update); + webserver.on("/system/update", HTTP_POST, WebPage_system_update, WebPage_system_update_ApplyUpdate); + webserver.on("/system/restart", HTTP_GET, WebPage_system_restart); webserver.on("/system/restart", HTTP_POST, WebPage_system_restart); diff --git a/Arduino/CanGrow/include/Webserver/Page_system.h b/Arduino/CanGrow/include/Webserver/Page_system.h index a4dee70..7b248c8 100644 --- a/Arduino/CanGrow/include/Webserver/Page_system.h +++ b/Arduino/CanGrow/include/Webserver/Page_system.h @@ -49,7 +49,7 @@ void WebPage_system(AsyncWebServerRequest *request) { /* - * Page subpage restart + * Subpage restart */ String Proc_WebPage_system_restart(const String& var) { if(TestHeaderFooter(var)) { @@ -84,3 +84,44 @@ void WebPage_system_restart(AsyncWebServerRequest *request) { } } + + + +/* + * Subpage update + */ + +void WebPage_system_update_ApplyUpdate(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){ + if(!index){ + Serial.printf("Update Start: %s\n", filename.c_str()); + Update.runAsync(true); + if(!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000)){ + Update.printError(Serial); + } + } + if(!Update.hasError()){ + if(Update.write(data, len) != len){ + Update.printError(Serial); + } + } + if(final){ + if(Update.end(true)){ + Serial.printf("Update Success: %uB\n", index+len); + } else { + Update.printError(Serial); + } + } + } + +void WebPage_system_update(AsyncWebServerRequest *request) { + if(request->method() == HTTP_POST) { + needRestart = !Update.hasError(); + AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", needRestart?"OK":"FAIL"); + response->addHeader("Connection", "close"); + request->send(response); + } else { + request->send_P(200, "text/html", Page_system_update_HTML, AddHeaderFooter); + } +} + + diff --git a/Arduino/CanGrow/include/Webserver/Page_system_HTML.h b/Arduino/CanGrow/include/Webserver/Page_system_HTML.h index 8e6b35e..93b7054 100644 --- a/Arduino/CanGrow/include/Webserver/Page_system_HTML.h +++ b/Arduino/CanGrow/include/Webserver/Page_system_HTML.h @@ -74,6 +74,27 @@ ESP32-Cam IP (optional): 🔄 Firmware update +Version: %CGVER%
+Build : %CGBUILD%
+ +

You find the latest CanGrow firmware version on the release page of the git repository.

+
+ Select .bin file:
+ + +
+