fine tune web update
This commit is contained in:
parent
e7bb42f72b
commit
22fdfc57c2
3 changed files with 27 additions and 5 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,4 +3,4 @@ KiCad/CanGrow/CanGrow.kicad_sch-bak
|
|||
KiCad/CanGrow/fp-info-cache
|
||||
KiCad/CanGrow/gerber/*.zip
|
||||
Arduino/CanGrow/CanGrow.geany
|
||||
build/
|
||||
Arduino/CanGrow/build/
|
||||
|
|
|
@ -91,9 +91,10 @@ void WebPage_system_restart(AsyncWebServerRequest *request) {
|
|||
* 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){
|
||||
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);
|
||||
if(!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000)){
|
||||
Update.printError(Serial);
|
||||
|
@ -106,17 +107,29 @@ void WebPage_system_update_ApplyUpdate(AsyncWebServerRequest *request, String fi
|
|||
}
|
||||
if(final){
|
||||
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 {
|
||||
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) {
|
||||
if(request->method() == HTTP_POST) {
|
||||
needRestart = !Update.hasError();
|
||||
AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", needRestart?"OK":"FAIL");
|
||||
doRestart = !Update.hasError();
|
||||
AsyncWebServerResponse *response = request->beginResponse(200, "text/html", doRestart?Page_system_update_HTML_POST:"UPDATE FAILED", Proc_WebPage_system_update_POST);
|
||||
response->addHeader("Connection", "close");
|
||||
request->send(response);
|
||||
} else {
|
||||
|
|
|
@ -92,6 +92,15 @@ Build : %CGBUILD% <br>
|
|||
|
||||
%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
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue