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?

Parents
  • 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);
    
Reply
  • 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);
    
Children
Related