This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to use sd_ble_gatts_descriptor_add()

I am trying to code a cycle power service and I need to add a server characteristic configuration descriptor. This service is probably the only BT SIG service that uses that descriptor. I have a method that uses sd_* calls to add a characteristic to a service. But I did not add the option to include an sccd. So I thought I would call this method, and having the populated

ble_gatts_char_handles_t

structure, I would use the

sd_ble_gatts_descriptor_add(uint16_t char_handle, ble_gatts_attr_t const *p_attr, uint16_t *p_handle)

method to add the sccd. But I cannot figure out how to use this method and what it is expecting. Is the ble_gatts_attr_t  structure the descriptor? So do I create this structure, populate it to the extent I can, and then use the fields in the ble_gatts_char_handles_t structure to populate the char_handle and *p_handle fields?

From the documentation I believe I have to make this call to add the descriptor right after I add the power characteristic to the service.

Or is the ble_gatts_attr_t  structure the cycle power measurement characteristic itself? If so, I would need other ,methods to get the structure. My guess is that the ble_gatts_attr_t  struct is supposed to be the descriptor itself, but that is certainly not clear from the documentation.

  • Hi Brian, 

    I haven't looked in to the cycle power service. But I assume the main purpose of the sccd is to broadcast the value of the characteristic when advertising  ? 
    If it's the case, you can just enable char_props.broadcast = 1 when you call sd_ble_gatts_characteristic_add() , similar to the .notify = 1 when you want to enable CCCD for the characteristic. 

    After that you should be able to see the SCCD in the ATT table. You will receive the handle of sccd (sccd_handle) from the softdevice , the same way as cccd_handle. 

Related