This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to retrieve the handle for a characteristic value by UUID?

Hello everybody,

I want to do something very simple: Read some data from my Bluetooth peripheral. I know the UUID of the data I want to read, but I do not know the handle.

I do NOT want do do a complete discovery, transferring every characteristic information over Bluetooth and matchin the UUID on Central side.

The SoftDevice GATTS API provides the following function:

uint32_t sd_ble_gattc_characteristics_discover(uint16_t conn_handle, ble_gattc_handle_range_t const* p_handle_range)

This function call doesn't take any UUID information. It appears to me that (worst case) all characteristics have to be read over Bluetooth to find the desired handle. Also, there is no other function that accepts UUIDs as a parameter. Further, I could not find any information in the Bluetooth Core Specification that suggests that such a function is part of the Bluetooth standard.

Can anyone confirm that, by Bluetooth design, it is not possible/intended to request the handle to a certain UUID in one simple step?


There is one function that might be useful, though:

uint32_t sd_ble_gattc_char_value_by_uuid_read(uint16_t conn_handle, ble_uuid_t const* p_uuid, ble_gattc_handle_range_t const* p_handle_range)

Is it possible to use the handle value received from this request with the following function:

uint32_t sd_ble_gattc_read( uint16_t conn_handle, uint16_t handle, uint16_t offset)

I want to read and write large GATT values that have to be transmitted in multiple parts. Would the following strategy be the way to go?

  1. Use sd_ble_gattc_char_value_by_uuid_read() to get the handle and read Bytes 1-19
  2. Use sd_ble_gattc_read() with the handle received from (1) to read bytes 20-41
  3. Use sd_ble_gattc_read() with the handle received from (1) to read bytes 42-63 etc...
  4. Use sd_ble_gattc_write() with the handle received from (1) to write data to my characteristic

Update: I have tried reading with this strategy and it seems to work for large attribute sizes (60-70 Bytes). But it does not work for a size of 20 Bytes! When I get 19 Bytes with the first function call (read by UUID) and try to read the remaining byte with the second function call (read by handle), I get an error message from the peripheral: Attribute is not long. It appears I cannot read with offset when an attribute is smaller than 22 Bytes. Can anyone confirm this? Is this a bug?

Related