@@ -4,10 +4,7 @@ static SerialBLEInterface* instance;
44
55void SerialBLEInterface::onConnect (uint16_t connection_handle) {
66 BLE_DEBUG_PRINTLN (" SerialBLEInterface: connected" );
7- if (instance){
8- instance->_isDeviceConnected = true ;
9- // no need to stop advertising on connect, as the ble stack does this automatically
10- }
7+ // we now set _isDeviceConnected=true in onSecured callback instead
118}
129
1310void SerialBLEInterface::onDisconnect (uint16_t connection_handle, uint8_t reason) {
@@ -18,6 +15,14 @@ void SerialBLEInterface::onDisconnect(uint16_t connection_handle, uint8_t reason
1815 }
1916}
2017
18+ void SerialBLEInterface::onSecured (uint16_t connection_handle) {
19+ BLE_DEBUG_PRINTLN (" SerialBLEInterface: onSecured" );
20+ if (instance){
21+ instance->_isDeviceConnected = true ;
22+ // no need to stop advertising on connect, as the ble stack does this automatically
23+ }
24+ }
25+
2126void SerialBLEInterface::begin (const char * device_name, uint32_t pin_code) {
2227
2328 instance = this ;
@@ -36,6 +41,7 @@ void SerialBLEInterface::begin(const char* device_name, uint32_t pin_code) {
3641
3742 Bluefruit.Periph .setConnectCallback (onConnect);
3843 Bluefruit.Periph .setDisconnectCallback (onDisconnect);
44+ Bluefruit.Security .setSecuredCallback (onSecured);
3945
4046 // To be consistent OTA DFU should be added first if it exists
4147 // bledfu.begin();
@@ -80,7 +86,7 @@ void SerialBLEInterface::startAdv() {
8086 * https://developer.apple.com/library/content/qa/qa1931/_index.html
8187 */
8288 Bluefruit.Advertising .restartOnDisconnect (false ); // don't restart automatically as we handle it in onDisconnect
83- Bluefruit.Advertising .setInterval (32 , 1600 );
89+ Bluefruit.Advertising .setInterval (32 , 244 );
8490 Bluefruit.Advertising .setFastTimeout (30 ); // number of seconds in fast mode
8591 Bluefruit.Advertising .start (0 ); // 0 = Don't stop advertising after n seconds
8692
0 commit comments