fine tune web update

This commit is contained in:
Marcus 2024-10-22 00:40:07 +02:00
parent e7bb42f72b
commit 22fdfc57c2
3 changed files with 27 additions and 5 deletions

2
.gitignore vendored
View file

@ -3,4 +3,4 @@ KiCad/CanGrow/CanGrow.kicad_sch-bak
KiCad/CanGrow/fp-info-cache KiCad/CanGrow/fp-info-cache
KiCad/CanGrow/gerber/*.zip KiCad/CanGrow/gerber/*.zip
Arduino/CanGrow/CanGrow.geany Arduino/CanGrow/CanGrow.geany
build/ Arduino/CanGrow/build/

View file

@ -91,9 +91,10 @@ void WebPage_system_restart(AsyncWebServerRequest *request) {
* Subpage update * Subpage update
*/ */
// https://github.com/mathieucarbou/ESPAsyncWebServer/blob/main/docs/index.md#setting-up-the-server
void WebPage_system_update_ApplyUpdate(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){ void WebPage_system_update_ApplyUpdate(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){
if(!index){ if(!index){
Serial.printf("Update Start: %s\n", filename.c_str()); Serial.printf(":: [Webserver:system:update:ApplyUpdate] Update Start: %s\n", filename.c_str());
Update.runAsync(true); Update.runAsync(true);
if(!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000)){ if(!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000)){
Update.printError(Serial); Update.printError(Serial);
@ -106,17 +107,29 @@ void WebPage_system_update_ApplyUpdate(AsyncWebServerRequest *request, String fi
} }
if(final){ if(final){
if(Update.end(true)){ if(Update.end(true)){
Serial.printf("Update Success: %uB\n", index+len); Serial.printf(":: [Webserver:system:update:ApplyUpdate] Update Success: %uB\n", index+len);
} else { } else {
Update.printError(Serial); Update.printError(Serial);
} }
} }
} }
String Proc_WebPage_system_update_POST(const String& var) {
if(var == "CONFIGWIFI_IP") {
if(configWifi.dhcp == true) {
return WiFi.localIP().toString();
} else {
return String(IP2Char(configWifi.ip));
}
} else {
return String();
}
}
void WebPage_system_update(AsyncWebServerRequest *request) { void WebPage_system_update(AsyncWebServerRequest *request) {
if(request->method() == HTTP_POST) { if(request->method() == HTTP_POST) {
needRestart = !Update.hasError(); doRestart = !Update.hasError();
AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", needRestart?"OK":"FAIL"); AsyncWebServerResponse *response = request->beginResponse(200, "text/html", doRestart?Page_system_update_HTML_POST:"UPDATE FAILED", Proc_WebPage_system_update_POST);
response->addHeader("Connection", "close"); response->addHeader("Connection", "close");
request->send(response); request->send(response);
} else { } else {

View file

@ -92,6 +92,15 @@ Build : %CGBUILD% <br>
%FOOTER%)"; %FOOTER%)";
const char* Page_system_update_HTML_POST PROGMEM = R"(<html>
<head>
<meta http-equiv='refresh' content='3;url=http://%CONFIGWIFI_IP%/' />
</head>
<body>
<h1>successfully updated! redirecting tp http://%CONFIGWIFI_IP% in 3 seconds</h1>
</body>
</html>)";
/* /*
* Subpage restart * Subpage restart
*/ */