Skip to content

Commit f26c4f9

Browse files
committed
A better fix for the "advertising stops once service connects" bug
We just restart advertising after we get the connect notification. This handles cases where the phone walks out of range without disconnecting.
1 parent a3b88c1 commit f26c4f9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

libraries/BLE/src/BLEServer.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,12 @@ void BLEServer::handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t
171171
m_pServerCallbacks->onConnect(this);
172172
m_pServerCallbacks->onConnect(this, param);
173173
}
174-
m_connectedCount++; // Increment the number of connected devices count.
174+
m_connectedCount++; // Increment the number of connected devices count.
175+
176+
// The BLE system software implicitly stops advertising once someone connects - we don't want that
177+
// because if a client walks away (without even gracefully disconnecting), we will never again restart
178+
// advertising
179+
startAdvertising();
175180
break;
176181
} // ESP_GATTS_CONNECT_EVT
177182

@@ -215,7 +220,6 @@ void BLEServer::handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t
215220
m_connectedCount--; // Decrement the number of connected devices count.
216221
}
217222

218-
startAdvertising();
219223
break;
220224
} // ESP_GATTS_DISCONNECT_EVT
221225

0 commit comments

Comments
 (0)