From ac33787de5a5f397d32aa405b5cc02f6e6e54852 Mon Sep 17 00:00:00 2001 From: "Valentin V. Bartenev" Date: Mon, 11 May 2026 09:18:12 +0300 Subject: [PATCH] Web: replace ElegantOTA UI with native HTTPS firmware upload OTA firmware updates previously required starting a separate plain-HTTP AsyncWebServer on port 80 via ElegantOTA. This meant stopping the redirect server, spinning up a new server instance, and transmitting the firmware binary unencrypted without authentication enforced. Add a POST /api/ota endpoint directly to WebPanelServer. The handler authenticates via the existing X-Auth-Token session token, resets the idle timeout via noteActivity(), and streams the request body in 4096-byte chunks into Update.write() (matching the ESP32 flash sector size). Update.begin() is called with the exact Content-Length so the library can verify partition space upfront. Update.abort() is called on any read or write error to leave the device on the current firmware. On success the handler sends a 200 response and reboots after 1s. The endpoint runs over the existing HTTPS server on port 443. Replace the "Start OTA" button in the actions bar with an inline "Firmware Update" card on the app page. The card contains a .bin file picker and an upload button. Upload progress is tracked via XMLHttpRequest's upload.onprogress event and shown with a progress bar. A 401 response redirects to the login page; other failures re-enable the file picker so the user can retry without reloading the page. The old ElegantOTA infrastructure (ESP32Board::startOTAUpdate, WebService::prepareForOTAStart, the /update redirect handler) is not yet removed and remains accessible via the `start ota` CLI command. --- src/helpers/web/WebPanelServer.cpp | 136 ++++++++++++++++++++++++++--- src/helpers/web/WebPanelServer.h | 1 + 2 files changed, 126 insertions(+), 11 deletions(-) diff --git a/src/helpers/web/WebPanelServer.cpp b/src/helpers/web/WebPanelServer.cpp index 2647c3af..b118a2a8 100644 --- a/src/helpers/web/WebPanelServer.cpp +++ b/src/helpers/web/WebPanelServer.cpp @@ -7,6 +7,7 @@ #include #include #include +#include "Update.h" #include "../mqtt/generated/WebPanelCert.h" @@ -558,7 +559,7 @@ const char kWebPanelAppHtml[] PROGMEM = R"HTML( .actions-bar { display:grid; grid-template-columns:1fr; gap:10px; } .actions-group { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); } .actions-group.left, .actions-group.center, .actions-group.right { justify-self:stretch; } - .actions-group.center { grid-template-columns:repeat(3,minmax(0,1fr)); justify-items:stretch; } + .actions-group.center { grid-template-columns:repeat(2,minmax(0,1fr)); justify-items:stretch; } .actions-group.right { grid-template-columns:repeat(3,minmax(0,1fr)); justify-items:stretch; } #actionsPanel .actions-group button { width:100%; } #actionsPanel .actions-group.center button { width:100%; min-width:0; } @@ -591,7 +592,6 @@ const char kWebPanelAppHtml[] PROGMEM = R"HTML(
-
@@ -665,6 +665,25 @@ const char kWebPanelAppHtml[] PROGMEM = R"HTML(
+ +