From a294f01a5d934b7f88f05ad91f628c79cdc879f3 Mon Sep 17 00:00:00 2001 From: mikecarper Date: Mon, 5 Oct 2026 10:47:37 -0700 Subject: [PATCH] Restore configured ESP-NOW bridge after browser OTA stops --- src/helpers/CommonCLI.cpp | 6 +++++- test/test_wifi_ota_start.py | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index 8d3b938ad..2965b9e63 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -2780,7 +2780,11 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re if (!reply[0]) strcpy(reply, "Error"); } #if defined(WITH_MQTT_BRIDGE) && defined(LIGHTWEIGHT_WIFI_OTA) - else if (_prefs->bridge_enabled) { + else if (_prefs->bridge_enabled +#ifdef WITH_ESPNOW_BRIDGE + || _prefs->espnow_bridge_enabled +#endif + ) { _callbacks->setBridgeState(true); } #endif diff --git a/test/test_wifi_ota_start.py b/test/test_wifi_ota_start.py index 82d4c1194..0bdc902a1 100644 --- a/test/test_wifi_ota_start.py +++ b/test/test_wifi_ota_start.py @@ -97,14 +97,14 @@ int main() { #include struct Callbacks { bool active = true, allow_stop = true; - int stops = 0, bridge_stops = 0; + int stops = 0, bridge_stops = 0, bridge_starts = 0; bool isWebConfigActive() const { return active; } bool stopWebConfigForOTA(char* reply) { ++stops; if (!allow_stop) { strcpy(reply, "ERR: handoff failed"); return false; } active = false; strcpy(reply, "WebConfig stopped"); return true; } - void setBridgeState(bool enabled) { if (!enabled) ++bridge_stops; } + void setBridgeState(bool enabled) { if (enabled) ++bridge_starts; else ++bridge_stops; } } callbacks; struct Board { bool allow_start = true; @@ -117,7 +117,10 @@ struct Board { } bool stopOTAUpdate(char*) { return true; } } board; -struct Prefs { const char* node_name = "test"; bool bridge_enabled = false; } prefs; +struct Prefs { + const char* node_name = "test"; + bool bridge_enabled = false, espnow_bridge_enabled = false; +} prefs; struct CLI { Board* _board = &board; Prefs* _prefs = &prefs; @@ -147,12 +150,18 @@ int main() { cli.run("start ota", reply.text); assert(strcmp(reply.text, "ERR: OTA WiFi failed; WebConfig stopped") == 0); assert(callbacks.stops == 3 && board.starts == 3 && callbacks.bridge_stops == 2); + cli.run("stop ota", reply.text); + assert(callbacks.bridge_starts == 0); // Do not enable disabled bridges. + prefs.espnow_bridge_enabled = true; + cli.run("stop ota", reply.text); + assert(callbacks.bridge_starts == 1); // Restore ESP-NOW even with MQTT off. assert(reply.guard == 123); } ''' self.compile_and_run(fixture.replace("@CLI@", cli[start:end]), "-DESP_PLATFORM=1", "-DADMIN_PASSWORD=1", - "-DWITH_MQTT_BRIDGE=1", "-DLIGHTWEIGHT_WIFI_OTA=1") + "-DWITH_MQTT_BRIDGE=1", "-DLIGHTWEIGHT_WIFI_OTA=1", + "-DWITH_ESPNOW_BRIDGE=1") def test_webconfig_teardown_cannot_turn_ota_wifi_off(self): source = (ROOT / "src/helpers/esp32/WebConfigServer.cpp").read_text()