Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit 88645eb

Browse files
committed
esp32/network_bluetooth.c: Fixed duplicate conn obj on device disconnect
1 parent f782f8a commit 88645eb

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

esp32/network_bluetooth.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,16 @@ STATIC void gap_event_dump(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t
16481648
}
16491649
#endif // EVENT_DEBUG
16501650

1651+
STATIC void network_bluetooth_disconnect_helper(network_bluetooth_connection_obj_t* connection) {
1652+
network_bluetooth_obj_t* bluetooth = network_bluetooth_get_singleton();
1653+
if (connection != MP_OBJ_NULL && connection->conn_id != -1) {
1654+
esp_ble_gattc_close(bluetooth->gattc_interface, connection->conn_id);
1655+
network_bluetooth_del_connection_by_bda(connection->bda);
1656+
connection->conn_id = -1;
1657+
connection->services = mp_obj_new_list(0, NULL);
1658+
}
1659+
}
1660+
16511661
STATIC mp_obj_t network_bluetooth_callback_queue_handler(mp_obj_t arg) {
16521662
network_bluetooth_obj_t* bluetooth = network_bluetooth_get_singleton();
16531663

@@ -1908,10 +1918,7 @@ STATIC mp_obj_t network_bluetooth_callback_queue_handler(mp_obj_t arg) {
19081918

19091919
case NETWORK_BLUETOOTH_GATTC_CLOSE:
19101920
{
1911-
network_bluetooth_connection_obj_t* conn = network_bluetooth_find_connection_by_conn_id(cbdata.gattc_open_close.conn_id);
1912-
if (conn != MP_OBJ_NULL) {
1913-
conn->conn_id = -1;
1914-
}
1921+
network_bluetooth_disconnect_helper(network_bluetooth_find_connection_by_conn_id(cbdata.gattc_open_close.conn_id));
19151922
}
19161923
break;
19171924

@@ -2297,9 +2304,9 @@ STATIC void network_bluetooth_adv_updated() {
22972304
esp_ble_gap_config_adv_data(&self->adv_data);
22982305

22992306
// Restart will be handled in network_bluetooth_gap_event_handler
2300-
23012307
}
23022308

2309+
23032310
/******************************************************************************/
23042311
// MicroPython bindings for network_bluetooth
23052312
//
@@ -2890,14 +2897,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_bluetooth_connection_is_connected_obj,
28902897
// conn.disconnect()
28912898

28922899
STATIC mp_obj_t network_bluetooth_connection_disconnect(mp_obj_t self_in) {
2893-
network_bluetooth_obj_t * bluetooth = network_bluetooth_get_singleton();
2894-
network_bluetooth_connection_obj_t* connection = (network_bluetooth_connection_obj_t*) self_in;
2895-
if (connection->conn_id != -1) {
2896-
esp_ble_gattc_close(bluetooth->gattc_interface, connection->conn_id);
2897-
network_bluetooth_del_connection_by_bda(connection->bda);
2898-
connection->conn_id = -1;
2899-
connection->services = mp_obj_new_list(0, NULL);
2900-
}
2900+
network_bluetooth_disconnect_helper(self_in);
29012901
return mp_const_none;
29022902
}
29032903
STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_bluetooth_connection_disconnect_obj, network_bluetooth_connection_disconnect);

0 commit comments

Comments
 (0)