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

  • ...(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;)

Reply
  • ...(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;)

Children
No Data
Related