@@ -182,19 +182,22 @@ void BLEClient::gattClientEventHandler(
182
182
// - uint16_t conn_id
183
183
// - esp_bd_addr_t remote_bda
184
184
case ESP_GATTC_DISCONNECT_EVT: {
185
- // If we receive a disconnect event, set the class flag that indicates that we are
186
- // no longer connected.
187
- m_isConnected = false ;
188
- if (m_pClientCallbacks != nullptr ) {
189
- m_pClientCallbacks->onDisconnect (this );
190
- }
191
- BLEDevice::removePeerDevice (m_appId, true );
192
- esp_ble_gattc_app_unregister (m_gattc_if);
193
- m_semaphoreRssiCmplEvt.give ();
194
- m_semaphoreSearchCmplEvt.give (1 );
185
+ ESP_LOGE (__func__, " disconnect event, conn_id: %d" , evtParam->disconnect .conn_id );
186
+ if (getConnId () != evtParam->disconnect .conn_id )
195
187
break ;
188
+ m_semaphoreOpenEvt.give (evtParam->disconnect .reason );
189
+ if (!m_isConnected)
190
+ break ;
191
+ // If we receive a disconnect event, set the class flag that indicates that we are
192
+ // no longer connected.
193
+ esp_ble_gattc_close (m_gattc_if, m_conn_id);
194
+ m_isConnected = false ;
195
+ if (m_pClientCallbacks != nullptr ) {
196
+ m_pClientCallbacks->onDisconnect (this );
197
+ }
198
+ break ;
196
199
} // ESP_GATTC_DISCONNECT_EVT
197
-
200
+
198
201
//
199
202
// ESP_GATTC_OPEN_EVT
200
203
//
@@ -224,8 +227,12 @@ void BLEClient::gattClientEventHandler(
224
227
// uint16_t app_id
225
228
//
226
229
case ESP_GATTC_REG_EVT: {
227
- m_gattc_if = gattc_if;
228
- m_semaphoreRegEvt.give ();
230
+ if (m_appId == evtParam->reg .app_id ){
231
+ ESP_LOGI (__func__, " register app id: %d, %d, gattc_if: %d" , m_appId, evtParam->reg .app_id , gattc_if);
232
+ m_gattc_if = gattc_if;
233
+ m_appId = evtParam->reg .app_id ;
234
+ m_semaphoreRegEvt.give ();
235
+ }
229
236
break ;
230
237
} // ESP_GATTC_REG_EVT
231
238
0 commit comments