@@ -259,6 +259,8 @@ typedef struct {
259
259
mp_obj_t callback ; // common
260
260
mp_obj_t callback_userdata ; // common
261
261
262
+ mp_obj_t next ; // next charactersitic to add when service is started
263
+
262
264
} network_bluetooth_char_descr_obj_t ;
263
265
264
266
// "Bluetooth" Declaration
@@ -1576,12 +1578,28 @@ STATIC mp_obj_t network_bluetooth_callback_queue_handler(mp_obj_t arg) {
1576
1578
ITEM_BEGIN ();
1577
1579
size_t len ;
1578
1580
mp_obj_t * items ;
1581
+ network_bluetooth_char_descr_obj_t * prev = MP_OBJ_NULL ;
1579
1582
1580
1583
mp_obj_get_array (service -> chars , & len , & items );
1581
1584
1585
+ // Only start first
1586
+ // characteristic, and link chars together
1587
+ // for easier chaining of starts.
1588
+ //
1589
+ // This is because the IDF only allows adding
1590
+ // descriptors to the last-added charactersitic,
1591
+ // so we have to add new chars after adding chars
1592
+ //
1582
1593
for (int i = 0 ; i < len ; i ++ ) {
1583
1594
network_bluetooth_char_descr_obj_t * chr = (network_bluetooth_char_descr_obj_t * ) items [i ];
1584
- esp_ble_gatts_add_char (service -> handle , & chr -> id .uuid , chr -> perm , chr -> prop , NULL , NULL );
1595
+ if (i == 0 ) {
1596
+ esp_ble_gatts_add_char (service -> handle , & chr -> id .uuid , chr -> perm , chr -> prop , NULL , NULL );
1597
+ }
1598
+ chr -> next = MP_OBJ_NULL ;
1599
+ if (prev != MP_OBJ_NULL ) {
1600
+ prev -> next = chr ;
1601
+ }
1602
+ prev = chr ;
1585
1603
}
1586
1604
ITEM_END ();
1587
1605
}
@@ -1614,6 +1632,10 @@ STATIC mp_obj_t network_bluetooth_callback_queue_handler(mp_obj_t arg) {
1614
1632
network_bluetooth_char_descr_obj_t * descr = (network_bluetooth_char_descr_obj_t * ) items [j ];
1615
1633
esp_ble_gatts_add_char_descr (service -> handle , & descr -> id .uuid , descr -> perm , NULL , NULL );
1616
1634
}
1635
+ chr = chr -> next ; // Now add the next characteristic
1636
+ if (chr != MP_OBJ_NULL ) {
1637
+ esp_ble_gatts_add_char (service -> handle , & chr -> id .uuid , chr -> perm , chr -> prop , NULL , NULL );
1638
+ }
1617
1639
ITEM_END ();
1618
1640
}
1619
1641
}
0 commit comments