mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-26 23:45:10 +00:00
Manually restart BLE advertising after disconnect to prevent stack freeze
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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user