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

  • Hello Jan:

    Thank you yet again for your patient reply :)

    Are you sure that handle you supply to sd_ble_gatts_value_get is CCCD handle?

    No, as a matter of fact, after some study, I am now sure it is not.

    What type is m_mesh_service handle and how you set the value?

    I... I don't really know, I got the value from the same function that added the metadata characteristic function (which is errorneous, I won't be able to get it anyway, it's a purely SD thing now it seems, I should have gone for value characteristic.)

    Now this is what I beleive, after some googling:

    What I want to read is the CCCD descriptor, it can be accessed using a handle. If the result I read is 0x0001, then it means the notification is enabled. of it's 0x0002, meaning indication is enabled. if it's 0x0000, it means nothing was enabled. (Continued below)

Reply
  • Hello Jan:

    Thank you yet again for your patient reply :)

    Are you sure that handle you supply to sd_ble_gatts_value_get is CCCD handle?

    No, as a matter of fact, after some study, I am now sure it is not.

    What type is m_mesh_service handle and how you set the value?

    I... I don't really know, I got the value from the same function that added the metadata characteristic function (which is errorneous, I won't be able to get it anyway, it's a purely SD thing now it seems, I should have gone for value characteristic.)

    Now this is what I beleive, after some googling:

    What I want to read is the CCCD descriptor, it can be accessed using a handle. If the result I read is 0x0001, then it means the notification is enabled. of it's 0x0002, meaning indication is enabled. if it's 0x0000, it means nothing was enabled. (Continued below)

Children
No Data
Related