@@ -453,6 +453,7 @@ STATIC void network_bluetooth_gatt_id_print(const mp_print_t *print, const esp_g
453
453
typedef enum {
454
454
NETWORK_BLUETOOTH_FIND_SERVICE ,
455
455
NETWORK_BLUETOOTH_FIND_CONNECTION ,
456
+ NETWORK_BLUETOOTH_DEL_CONNECTION ,
456
457
NETWORK_BLUETOOTH_FIND_CHAR_DESCR_IN ,
457
458
NETWORK_BLUETOOTH_FIND_CHAR_DESCR ,
458
459
NETWORK_BLUETOOTH_DEL_SERVICE ,
@@ -532,12 +533,19 @@ STATIC mp_obj_t network_bluetooth_item_op(mp_obj_t list, esp_bt_uuid_t* uuid, ui
532
533
break ;
533
534
534
535
case NETWORK_BLUETOOTH_FIND_CONNECTION :
536
+ case NETWORK_BLUETOOTH_DEL_CONNECTION :
535
537
{
536
538
network_bluetooth_connection_obj_t * conn = (network_bluetooth_connection_obj_t * ) items [i ];
537
539
if ((bda != NULL && memcmp (conn -> bda , bda , ESP_BD_ADDR_LEN ) == 0 ) || (bda == NULL && conn -> conn_id == handle_or_conn_id )) {
538
540
ret = conn ;
539
- goto NETWORK_BLUETOOTH_ITEM_END ;
540
541
}
542
+
543
+ if (kind == NETWORK_BLUETOOTH_DEL_CONNECTION ) {
544
+ // a bit ineffecient, but
545
+ // list_pop() is static
546
+ mp_obj_list_remove (list , conn );
547
+ }
548
+ goto NETWORK_BLUETOOTH_ITEM_END ;
541
549
}
542
550
break ;
543
551
}
@@ -609,6 +617,11 @@ STATIC mp_obj_t network_bluetooth_del_service_by_uuid(esp_bt_uuid_t* uuid) {
609
617
return network_bluetooth_item_op (bluetooth -> services , uuid , 0 , NULL , NETWORK_BLUETOOTH_DEL_SERVICE );
610
618
}
611
619
620
+ STATIC mp_obj_t network_bluetooth_del_connection_by_bda (esp_bd_addr_t bda ) {
621
+ network_bluetooth_obj_t * bluetooth = network_bluetooth_get_singleton ();
622
+ return network_bluetooth_item_op (bluetooth -> connections , NULL , 0 , bda , NETWORK_BLUETOOTH_DEL_CONNECTION );
623
+ }
624
+
612
625
STATIC void network_bluetooth_print_bda (const mp_print_t * print , esp_bd_addr_t bda ) {
613
626
if (print != NULL ) {
614
627
mp_printf (print , "%02X:%02X:%02X:%02X:%02X:%02X" , bda [0 ], bda [1 ], bda [2 ], bda [3 ], bda [4 ], bda [5 ]);
@@ -2881,7 +2894,9 @@ STATIC mp_obj_t network_bluetooth_connection_disconnect(mp_obj_t self_in) {
2881
2894
network_bluetooth_connection_obj_t * connection = (network_bluetooth_connection_obj_t * ) self_in ;
2882
2895
if (connection -> conn_id != -1 ) {
2883
2896
esp_ble_gattc_close (bluetooth -> gattc_interface , connection -> conn_id );
2897
+ network_bluetooth_del_connection_by_bda (connection -> bda );
2884
2898
connection -> conn_id = -1 ;
2899
+ connection -> services = mp_obj_new_list (0 , NULL );
2885
2900
}
2886
2901
return mp_const_none ;
2887
2902
}
@@ -3396,6 +3411,14 @@ STATIC mp_obj_t network_bluetooth_services(mp_obj_t self_in) {
3396
3411
}
3397
3412
STATIC MP_DEFINE_CONST_FUN_OBJ_1 (network_bluetooth_services_obj , network_bluetooth_services );
3398
3413
3414
+ // bluetooth.conns()
3415
+
3416
+ STATIC mp_obj_t network_bluetooth_conns (mp_obj_t self_in ) {
3417
+ network_bluetooth_obj_t * bluetooth = network_bluetooth_get_singleton ();
3418
+ return bluetooth -> connections ;
3419
+ }
3420
+ STATIC MP_DEFINE_CONST_FUN_OBJ_1 (network_bluetooth_conns_obj , network_bluetooth_conns );
3421
+
3399
3422
// bluetooth.is_scanning()
3400
3423
3401
3424
STATIC mp_obj_t network_bluetooth_is_scanning (mp_obj_t self_in ) {
@@ -3466,6 +3489,7 @@ STATIC const mp_rom_map_elem_t network_bluetooth_locals_dict_table[] = {
3466
3489
{ MP_ROM_QSTR (MP_QSTR_connect ), MP_ROM_PTR (& network_bluetooth_connect_obj ) },
3467
3490
{ MP_ROM_QSTR (MP_QSTR_Service ), MP_ROM_PTR (& network_bluetooth_gatts_service_type ) },
3468
3491
{ MP_ROM_QSTR (MP_QSTR_services ), MP_ROM_PTR (& network_bluetooth_services_obj ) },
3492
+ { MP_ROM_QSTR (MP_QSTR_conns ), MP_ROM_PTR (& network_bluetooth_conns_obj ) },
3469
3493
{ MP_ROM_QSTR (MP_QSTR_callback ), MP_ROM_PTR (& network_bluetooth_callback_obj ) },
3470
3494
{ MP_ROM_QSTR (MP_QSTR_scan_start ), MP_ROM_PTR (& network_bluetooth_scan_start_obj ) },
3471
3495
{ MP_ROM_QSTR (MP_QSTR_scan_stop ), MP_ROM_PTR (& network_bluetooth_scan_stop_obj ) },
0 commit comments