[Answered] BLE: Associating a descriptor with a characteristic
Posted: 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.
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.