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

[S132] CCCD value not being initialized

Hi, I wrote a custom service with a characteristics with notifications support. After a client connects I start the sensors and I start updating the values. On the service I'm using the sd_ble_gatts_hvx function to update the value and send a notification in case it is enabled.

In theory the function should return NRF_ERROR_STATE_INVALID when the notifications are not enabled, but instead I'm getting a BLE_ERROR_GATTS_SYS_ATTR_MISSING. But if I write a 0 to the CCCD it starts reporting NRF_ERROR_STATE_INVALID which is the expected error.

I assume this is issue is due to the SD not initializing the CCCD to 0. I am right?

Thanks

Parents
  • You were right about not initializing CCCD, but it is not a bug. CCCDs are not initialized in memory because their values are persistent. The application can tell the softdevice what values it should store in CCCD using sd_ble_gatts_sys_attr_set. If the app doesn't have stored values for CCCDs (system attributes) for a particular peer, then it can send sd_ble_gatts_sys_attr_set(conn_handle, NULL, 0) and softdevice should reset the CCCD values to 0.

Reply
  • You were right about not initializing CCCD, but it is not a bug. CCCDs are not initialized in memory because their values are persistent. The application can tell the softdevice what values it should store in CCCD using sd_ble_gatts_sys_attr_set. If the app doesn't have stored values for CCCDs (system attributes) for a particular peer, then it can send sd_ble_gatts_sys_attr_set(conn_handle, NULL, 0) and softdevice should reset the CCCD values to 0.

Children
Related