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 Mitch,

    Are you sure that handle you supply to sd_ble_gatts_value_get is CCCD handle? What type is m_mesh_service handle and how you set the value? Note that Service itself doesn't provide any Value handle (indeed!) but only Characteristic has one and Descriptors one... Note that Service has handle which holds UUID and similar for Characteristic, but I'm not sure you can read them by this SD function (you can definitely read them over BLE GATT methods).

    Also the structure ble_gatts_value_t ble_gatts_value_cccd_acquire should be allocated by you, don't expect to get pointers to SD memory area! See example from Nordic SDK (full text search for function which you want to use is great help, try it;)

    ret_code_t err_code;
    
    // Go straight to the characteristic
    uint8_t           value_buffer[ESCS_ADV_SLOT_CHAR_LENGTH_MAX] = {0};
    ble_gatts_value_t value = {.len = sizeof(value_buffer),
                               .offset = 0,
                               .p_value = &(value_buffer[0])};
    
    err_code = sd_ble_gatts_value_get(p_escs->conn_handle, val_handle, &value);
    RETURN_IF_ERROR(err_code);
    

    And last but not least I haven't tried sd_ble_gatts_value_get function on handle which isn't GATT Characteristic Value but something else (e.g. UUID or Descriptor). It's possible that it won't work and you will need to use something else (e.g. sd_ble_gatts_sys_attr_get).

    Cheers Jan

  • Hi Mitch, seems still crawling through the BLE architecture:) Summary:

    • Yes, CCCD is created automatically by SD for certain GATT Characteristic (remember it's SD which builds actual GATT table to be available as Server to connected Clients) BUT that depends on flags you set for that Characteristic! If you say during the creation that it supports Indication or Notify methods then SD will create CCCD.
    • All this Characteristic "creation" (or "provisioning" if you want) is done by calling sd_ble_gatts_characteristic_add function (I'm sure you are calling it in your code as well!). This function fills p_handles (pointer to structure supplied by your app) all created handles including CCCD. (1/x)
Reply
  • Hi Mitch, seems still crawling through the BLE architecture:) Summary:

    • Yes, CCCD is created automatically by SD for certain GATT Characteristic (remember it's SD which builds actual GATT table to be available as Server to connected Clients) BUT that depends on flags you set for that Characteristic! If you say during the creation that it supports Indication or Notify methods then SD will create CCCD.
    • All this Characteristic "creation" (or "provisioning" if you want) is done by calling sd_ble_gatts_characteristic_add function (I'm sure you are calling it in your code as well!). This function fills p_handles (pointer to structure supplied by your app) all created handles including CCCD. (1/x)
Children
No Data
Related