Skip to content

Commit 25ea953

Browse files
committed
don't mark as connected until connection secured
1 parent d929d32 commit 25ea953

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/helpers/nrf52/SerialBLEInterface.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ static SerialBLEInterface* instance;
44

55
void 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

1310
void 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+
2126
void 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();

src/helpers/nrf52/SerialBLEInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class SerialBLEInterface : public BaseSerialInterface {
2525
void clearBuffers() { send_queue_len = 0; }
2626
static void onConnect(uint16_t connection_handle);
2727
static void onDisconnect(uint16_t connection_handle, uint8_t reason);
28+
static void onSecured(uint16_t connection_handle);
2829

2930
public:
3031
SerialBLEInterface() {

0 commit comments

Comments
 (0)