[Answered] BLE: Associating a descriptor with a characteristic

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

[Answered] BLE: Associating a descriptor with a characteristic

Postby kolban » Sun Jun 25, 2017 10:49 pm

In my study, I seem to find that an arbitrary BLE peripheral (a device) can host 1 or more services. Each service can be composed of 1 or more characteristics and each characteristic can have 0 or more descriptors. We thus have a tree like structure rooted at the device which has immediate children off services. A service has immediate children of characteristics and a characteristic has immediate children off descriptors.

To create a service, we call "esp_ble_gatts_create_service".

To create a characteristic, we call "esp_ble_gatts_add_char". This takes as input the handle of the service that was returned to us. Thus the characteristic is associated with the service.

To create a descriptor, we call "esp_ble_gatts_add_char_desc". And it is here my puzzle begins. Looking at the documentation of "esp_ble_gatts_add_char_desc", we say that it takes as input the handle of the **service**. Think about this for a moment. We supply a service handle ... **not** a characteristic handle. And this causes me pause. If we call "esp_ble_gatts_add_char_desc" and don't supply some relationship to a characteristic, how then can the descriptor be created in the correct place in the tree? How can the descriptor be created with a relationship to a corresponding characteristic?

Later ....

Oh yuk!!! ... I found the following:

https://github.com/espressif/esp-idf/issues/284

It appears that this is currently as designed. The descriptor is added/associated to the LAST characteristic added.
Last edited by kolban on Thu Jun 29, 2017 1:14 pm, edited 1 time in total.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

ESP_Tianhao
Posts: 28
Joined: Thu Jan 05, 2017 10:46 am

Re: BLE: Associating a descriptor with a characteristic

Postby ESP_Tianhao » Thu Jun 29, 2017 7:20 am

Now, there's two ways to add characteristics and descriptors.
1. use legacy way:
Just use `esp_ble_gatts_add_char` and `esp_ble_gatts_add_char_descr`.
Descriptor should add follow Characteristic. If there's multi descriptors, for example, there're 3 descriptors (A, B, C). A should add following their characteristic(X), when receive ADD_CHARACTERISTIC(X), add descriptor A, wait for ADD_DESCRIPTOR(A) event, then add descriptor B,wait for ADD_DESCRIPTOR(B) event, then add descriptor C. So the 3 descriptors(A, B, C) will associate with their character(X).

2. use gatt service table:
Just fill the service, characteristic and descriptors relationship in a gatt service table, then call `esp_ble_gatts_create_attr_tab`.

BTW, the relationship between characteristic and descriptor is just "following".

Who is online

Users browsing this forum: bryanergy and 45 guests