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

How do I use "sd_ble_gatts_value_get" to read the value of CCCD handle?

Hello, first, a little background info:

devzone.nordicsemi.com/.../

I want to know if I have successfully set the CCCD handle or not with my Android program.

And endnode recommended that I use this function "sd_ble_gatts_value_get".

I tried with the following code:

#ifdef DEBUG
	
	ble_gatts_value_t ble_gatts_value_cccd_acquire;  
	result = sd_ble_gatts_value_get (m_active_conn_handle,m_mesh_service.service_handle, &ble_gatts_value_cccd_acquire);
#endif

where: m_active_conn_handle is the current active gatt connection handle;

m_mesh_service.service_handle is the target gatt service I want to read one of its characteristic (and things get fuzzy from here), and its documentation is here:

ble_gatts_value_cccd_acquire is an empty struct that I plan to store my result in.

The final product: image description

isn't something very helpful...the length is 2, the offset is zero, and the p_value points to a part of the memory which aren't 0x0000 (notification disabled) or 0x0001 (notification enabled):

image description

So... how do I use this function? It has only 3 parameters, and 2 of which are used to id the target value...shouldn't I use 3, one for id-ing the gatt connection, one for id-ing the service, one for id-ing the characteristic? Golly why must everything be so confusing!

So... how?

  • ...(2/2)

    • So this gives you things like value handle and CCCD handle. Can you use code snippet above and supply one of these handles to sd_ble_gatts_value_get function call? Is at least reading value handle working? What about CCCD?

    I haven't touched nRF52 code for couple of months now and it looks like you are forcing me to do it. It's kind of battle of laziness, mine vs. yours;)

  • Hi,

    As both @RK and @endnode try to explain you have to ask for the value from the correct handle. A service might contain several characteristics, each one with or without a CCCD. Hence you need to get the value from the handle of a specific CCCD.

    Try something like this:

    uint32_t cccd_value;
    // Pupulate ble_gatts_value_t structure to hold received data and metadata.
    ble_gatts_value_t cccd_data;
    cccd_data.len = sizeof(uint32_t);
    cccd_data.offset = 0;
    cccd_data.p_value = (uint8_t*)&cccd_value;
    sd_ble_gatts_value_get(m_active_conn_handle, your_service.your_char_handle.cccd_handle, &cccd_data);
    
  • Both Jan and I have pointed out that the CCCD characteristic handle (as well as the value and other handles) are returned by the sd_ble_gatts_characteristic_add() call. That's in my comment of 3 days ago. There is no 'huge problem', the handle is not added by the softdevice in secret, it's not hard or impossible to get. Somewhere in the code you have that call is being executed and you need to go and find it and find where it puts the returned structure with all the handles on it and then go get the CCCD handle out of it.

  • That works to get the CCCD value except the cccd_value has 16 bits (uint16_t), not 32.  The define BLE_CCCD_VALUE_LEN is 2.

Related