From 4ededd97f730029cf4ef6ea0933f38a1ae81aa9a Mon Sep 17 00:00:00 2001 From: Pixel Perfect Date: Sat, 1 Aug 2026 22:03:33 -0700 Subject: [PATCH] fix(tpager): keep Wi-Fi-only applies live Signed-off-by: Pixel Perfect --- .../esp32/MultiTransportCompanionInterface.cpp | 7 +++---- .../esp32/MultiTransportCompanionInterface.h | 10 ++++------ src/main.cpp | 15 +++++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/helpers/esp32/MultiTransportCompanionInterface.cpp b/src/helpers/esp32/MultiTransportCompanionInterface.cpp index e976877..55b9b78 100644 --- a/src/helpers/esp32/MultiTransportCompanionInterface.cpp +++ b/src/helpers/esp32/MultiTransportCompanionInterface.cpp @@ -184,15 +184,14 @@ void MultiTransportCompanionInterface::prepareBle(const char* prefix, char* name _ble_pin_code = pin_code; } -void MultiTransportCompanionInterface::beginBle(const char* prefix, char* name, uint32_t pin_code, - bool create_enabled) { +void MultiTransportCompanionInterface::beginBle(const char* prefix, char* name, uint32_t pin_code) { prepareBle(prefix, name, pin_code); _ble.begin(prefix, name, pin_code); _ble_begun = true; - _ble_enabled = create_enabled; + _ble_enabled = true; _ota_ble_released = false; _ota_ble_was_enabled = false; - if (create_enabled) _ble.enable(); + _ble.enable(); } void MultiTransportCompanionInterface::enableBle() { diff --git a/src/helpers/esp32/MultiTransportCompanionInterface.h b/src/helpers/esp32/MultiTransportCompanionInterface.h index 287cdf5..cafd9cc 100644 --- a/src/helpers/esp32/MultiTransportCompanionInterface.h +++ b/src/helpers/esp32/MultiTransportCompanionInterface.h @@ -30,12 +30,10 @@ public: void stopTcpServer(); // stop TCP server and disconnect clients; prevents startTcpServer until enableTcp() #ifdef BLE_PIN_CODE - // Call after begin() and the_mesh is ready (e.g. after startInterface). Enables BLE by default. - // create_enabled=false pre-creates the NimBLE host/GATT table but leaves - // advertising off and the user-visible/persisted state disabled. T-Pager - // uses this after Wi-Fi claims its heap so a later live toggle allocates - // nothing after the UI working set has filled internal DRAM. - void beginBle(const char* prefix, char* name, uint32_t pin_code, bool create_enabled = true); + // Call after begin() and the_mesh is ready (e.g. after startInterface). + // Creates and enables BLE; BLE-off Pager boots deliberately avoid a dormant + // NimBLE allocation so Wi-Fi retains its normal reconnect path. + void beginBle(const char* prefix, char* name, uint32_t pin_code); // Store the BLE name/pin WITHOUT bringing the stack up. Used at boot when the // heap guard defers co-initialising BLE alongside Wi-Fi: the params are kept so // a later enableBle() can lazily bring BLE up live (no reboot). diff --git a/src/main.cpp b/src/main.cpp index 42fe194..104f928 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -769,7 +769,7 @@ void setup() { if (!want_wifi || pager_wifi_ready_for_ble) { if (want_ble) { serial_interface.beginBle(BLE_NAME_PREFIX, the_mesh.getNodePrefs()->node_name, - the_mesh.getBLEPin(), want_ble); + the_mesh.getBLEPin()); if (want_wifi) WiFi.setAutoReconnect(false); Serial.printf("[boot] BLE stack ready (enabled=%d wifi=%d)\n", (int)want_ble, (int)want_wifi); @@ -938,15 +938,18 @@ void loop() { * from the UI (the transition above already covered the on case). */ if (wifiConfigConsumeApplyRequest()) { #if defined(TLORA_PAGER) && defined(BLE_PIN_CODE) - // Every explicit credential/reconnect request must return through setup. - // This covers the setup wizard, saved-network/slot activation, scan - // reconnect, transport settings, and companion/CLI-backed preference - // updates instead of relying on each caller to remember the Pager's order. - if (wifi_radio_en && wifiConfigHasRuntime()) { + // With NimBLE resident, every explicit credential/reconnect request must + // return through setup. Wi-Fi-only applies stay live: opening the Wi-Fi + // page itself performs a scan/rejoin and must not reboot the device. + if (wifi_radio_en && wifiConfigHasRuntime() && + serial_interface.isBleStackBegun()) { Serial.println("[wifi] restarting for ordered T-Pager association"); ui_task.rebootDevice(); return; } + if (wifi_radio_en && !serial_interface.isBleStackBegun()) { + WiFi.setAutoReconnect(true); + } #endif /* Only touch WiFi state if it was actually started this session. When * BLE is the active transport (no creds saved), WiFi was never inited