Skip to content

Commit 1d2a575

Browse files
committed
esp32/network_bluetooth.c: Fix, GATTS Descr w/ multiple chars
The IDF API for adding descriptors only allows for specifying a _service_ handle. Because of this, you must do this: 1) Add service 2) Add charactteristic 3) Add char descriptor(s) 4) Add _next_ characteristic 5) goto 3
1 parent 12c22d1 commit 1d2a575

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

esp32/network_bluetooth.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ typedef struct {
259259
mp_obj_t callback; // common
260260
mp_obj_t callback_userdata; // common
261261

262+
mp_obj_t next; // next charactersitic to add when service is started
263+
262264
} network_bluetooth_char_descr_obj_t;
263265

264266
// "Bluetooth" Declaration
@@ -1576,12 +1578,28 @@ STATIC mp_obj_t network_bluetooth_callback_queue_handler(mp_obj_t arg) {
15761578
ITEM_BEGIN();
15771579
size_t len;
15781580
mp_obj_t *items;
1581+
network_bluetooth_char_descr_obj_t* prev = MP_OBJ_NULL;
15791582

15801583
mp_obj_get_array(service->chars, &len, &items);
15811584

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+
//
15821593
for (int i = 0; i < len; i++) {
15831594
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;
15851603
}
15861604
ITEM_END();
15871605
}
@@ -1614,6 +1632,10 @@ STATIC mp_obj_t network_bluetooth_callback_queue_handler(mp_obj_t arg) {
16141632
network_bluetooth_char_descr_obj_t* descr = (network_bluetooth_char_descr_obj_t*) items[j];
16151633
esp_ble_gatts_add_char_descr(service->handle, &descr->id.uuid, descr->perm, NULL, NULL);
16161634
}
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+
}
16171639
ITEM_END();
16181640
}
16191641
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy