From ec98d5f8a51dc497259610a4038ac25a35dbe112 Mon Sep 17 00:00:00 2001 From: Lloyd Date: Wed, 2 Jul 2025 23:41:31 +0100 Subject: [PATCH 1/2] BLE: Remove ScanResponse.addName() to fix re-advertising after disconnect Removed the call to Bluefruit.ScanResponse.addName() in startAdv(), as it was preventing BLE from reliably restarting advertising after a disconnect. Hypothesis: adding the device name to the scan response exceeds internal buffer limits or causes a conflict with advertising timing, leading to the BLE stack silently failing to re-advertise. Tested successfully (on T-1000) without this line, advertising now resumes correctly after disconnection (on Iphone) --- src/helpers/nrf52/SerialBLEInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/nrf52/SerialBLEInterface.cpp b/src/helpers/nrf52/SerialBLEInterface.cpp index f43a3767..c6c99d5b 100644 --- a/src/helpers/nrf52/SerialBLEInterface.cpp +++ b/src/helpers/nrf52/SerialBLEInterface.cpp @@ -27,7 +27,7 @@ void SerialBLEInterface::startAdv() { // Secondary Scan Response packet (optional) // Since there is no room for 'Name' in Advertising packet - Bluefruit.ScanResponse.addName(); + // Bluefruit.ScanResponse.addName(); /* Start Advertising * - Enable auto advertising if disconnected From d32fa5c00476013f3a12183277a15aaa5d6795e9 Mon Sep 17 00:00:00 2001 From: Lloyd Date: Fri, 4 Jul 2025 21:07:55 +0100 Subject: [PATCH 2/2] Manually restart BLE advertising after disconnect to prevent stack freeze MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced use of `restartOnDisconnect(true)` with explicit (existing) manual re-advertising logic. This avoids Bluetooth stack instability caused by overlapping advertising state, Changes: - Added explicit `Bluefruit.Advertising.stop()` and data clears in `startAdv()` - Disabled automatic restart with `restartOnDisconnect(false)` - Re-advertising now fully handled in `checkRecvFrame()` loop Tested on: iPhone, Android, Windows, and Chrome – confirmed stable reconnects and name visibility. --- src/helpers/nrf52/SerialBLEInterface.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/helpers/nrf52/SerialBLEInterface.cpp b/src/helpers/nrf52/SerialBLEInterface.cpp index c6c99d5b..af5b425e 100644 --- a/src/helpers/nrf52/SerialBLEInterface.cpp +++ b/src/helpers/nrf52/SerialBLEInterface.cpp @@ -18,6 +18,10 @@ void SerialBLEInterface::begin(const char* device_name, uint32_t pin_code) { } void SerialBLEInterface::startAdv() { + Bluefruit.Advertising.stop(); // always clean restart + Bluefruit.Advertising.clearData(); // clear advertising data + Bluefruit.ScanResponse.clearData(); // clear scan response data + // Advertising packet Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); Bluefruit.Advertising.addTxPower(); @@ -27,7 +31,7 @@ void SerialBLEInterface::startAdv() { // Secondary Scan Response packet (optional) // Since there is no room for 'Name' in Advertising packet - // Bluefruit.ScanResponse.addName(); + Bluefruit.ScanResponse.addName(); /* Start Advertising * - Enable auto advertising if disconnected @@ -38,7 +42,7 @@ void SerialBLEInterface::startAdv() { * For recommended advertising interval * https://developer.apple.com/library/content/qa/qa1931/_index.html */ - Bluefruit.Advertising.restartOnDisconnect(true); + Bluefruit.Advertising.restartOnDisconnect(false); // don't restart automatically as already beeing done in checkRecvFrame() Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds