fix(esp32): defer station maintenance while an AP owns WiFi

Starting or restarting MQTT during browser OTA could remove the active AP by forcing STA mode. Defer shared MQTT startup and recovery, and Companion WiFi startup, pending credential reloads and saved-SSID retries, until the live SDK AP releases the driver. Preserve the setup owner's deliberate credential handoff and cooperative stop acknowledgement.

Validated 91 source host tests, including 20 new AP ownership cases and nine reverted controls under ASan/UBSan. Hardware and firmware build qualification remain separate; the Arduino mode snapshot is not atomic.
This commit is contained in:
mikecarper committed 2026-10-07 02:44:18 -07:00
1 parent 8c7d7d8839
commit df4cbb75eb
13 files changed
+596 -9

No files matched your search

+18
View File
@@ -2245,6 +2245,8 @@ void halt() {
#ifdef WITH_WEBCONFIG
if (the_mesh.isWebConfigActiveOrStopping()) return;
#endif
// Retain the pending reload until the operator's OTA/setup AP closes.
if (!mesh::wifi::stationMutationAllowed()) return;
companion_wifi_credential_reload_pending = false;
companion_wifi_credential_reload_at = 0;
@@ -2268,6 +2270,7 @@ void halt() {
static void startCompanionWiFi() {
if (mesh::wireless::control().blocked(mesh::wireless::WiFi)) return;
if (companion_wifi_active) return;
if (!mesh::wifi::stationMutationAllowed()) return;
board.setInhibitSleep(true);
mesh::wifi::setStationAutoReconnect(true);
@@ -3803,6 +3806,20 @@ void loop() {
ota_console_loop(); // service the local text console (port 5002)
#endif
const unsigned long wifi_now = millis();
// The owner of a recovery setup AP may deliberately retry its saved SSID
// in AP+STA mode. Other APs, including browser OTA, must remain untouched by
// this background station maintenance and its five-minute reconnect timer.
const bool setup_station_handoff =
#ifdef COMPANION_RADIO_FULL
!board.isOTAUpdateRunning() &&
#endif
#ifdef WITH_WEBCONFIG
the_mesh.isWebConfigSetupActive()
&& (wifi_setup_recovery_mode || the_mesh.isWebConfigWiFiRecoveryActive());
#else
wifiSetupPortal().isActive();
#endif
if (mesh::wifi::stationMutationAllowed(setup_station_handoff)) {
const bool station_channel_ok = mesh::wifi::enforceStationChannel();
if (station_channel_ok && WiFi.status() == WL_CONNECTED) {
wifi_reconnect_tracker.noteConnected();
@@ -3896,6 +3913,7 @@ void loop() {
mesh::wifi::beginStation(
configured_wifi_ssid, configured_wifi_password);
}
}
#ifdef WITH_MQTT_BRIDGE
the_mesh.serviceMQTT(configured_wifi_ssid, configured_wifi_password);
serviceCompanionWiFiNtp();