From 01fd229b21f3ebb42f732d14a7fa5ce9fbc0c406 Mon Sep 17 00:00:00 2001 From: Jared Dohrman Date: Sun, 24 May 2026 17:49:01 +1000 Subject: [PATCH] fix: use existing Wi-Fi for ESP32 OTA start --- src/helpers/ESP32Board.cpp | 21 ++++++++++++++------- src/helpers/web/WebPanelServer.cpp | 6 +++++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/helpers/ESP32Board.cpp b/src/helpers/ESP32Board.cpp index a34cf5e2..fc34fc14 100644 --- a/src/helpers/ESP32Board.cpp +++ b/src/helpers/ESP32Board.cpp @@ -12,19 +12,26 @@ bool ESP32Board::startOTAUpdate(const char* id, char reply[]) { inhibit_sleep = true; // prevent sleep during OTA - WiFi.mode(WIFI_AP_STA); - if (!WiFi.softAP("MeshCore-OTA", NULL)) { - strcpy(reply, "Error - OTA AP start failed"); - return false; + + IPAddress ota_ip; + if (WiFi.status() == WL_CONNECTED) { + ota_ip = WiFi.localIP(); + } else { + WiFi.mode(WIFI_AP_STA); + if (!WiFi.softAP("MeshCore-OTA", NULL)) { + strcpy(reply, "Error - OTA AP start failed"); + return false; + } + ota_ip = WiFi.softAPIP(); } - sprintf(reply, "Started: http://%s/update", WiFi.softAPIP().toString().c_str()); + sprintf(reply, "Started: http://%s/update", ota_ip.toString().c_str()); MESH_DEBUG_PRINTLN("startOTAUpdate: %s", reply); static char id_buf[60]; - sprintf(id_buf, "%s (%s)", id, getManufacturerName()); + snprintf(id_buf, sizeof(id_buf), "%s (%s)", id, getManufacturerName()); static char home_buf[90]; - sprintf(home_buf, "

Hi! I am a MeshCore Repeater. ID: %s

", id); + snprintf(home_buf, sizeof(home_buf), "

Hi! I am a MeshCore Repeater. ID: %s

", id); static AsyncWebServer* server = nullptr; if (server != nullptr) { diff --git a/src/helpers/web/WebPanelServer.cpp b/src/helpers/web/WebPanelServer.cpp index 21881eec..ad7748d4 100644 --- a/src/helpers/web/WebPanelServer.cpp +++ b/src/helpers/web/WebPanelServer.cpp @@ -2678,7 +2678,11 @@ const char kWebPanelAppHtml[] PROGMEM = R"HTML( }; document.getElementById("otaBtn").onclick = async () => { if (confirm("Start OTA mode now?")) { - await runCommand("start ota"); + const result = await runCommand("start ota"); + const match = result.text && result.text.match(/https?:\/\/\S+/); + if (result.ok && match) { + window.location.href = match[0]; + } } }; document.getElementById("refreshPageBtn").onclick = async () => {