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

sd_ble_gatts_value_set for setting directly CCCD value.

Hi Nordic Semiconductor's community,

I have a question about the function sd_ble_gatts_value_set(), more precisely about if it is possible to set the CCCD value of a characteristic directly in firmware (not by the client (i.e. Android application) ).

i use the sd_ble_gatts_value_set() like this :

    uint32_t err_code;
    uint8_t cccd_value = 0x0001;
	ble_gatts_value_t gatts_value;
	memset(&gatts_value, 0, sizeof(gatts_value));

     gatts_value.len = sizeof(uint8_t);
     gatts_value.offset  = 0;
     gatts_value.p_value = &cccd_value;  // 0x0001 (Notification).
	
	err_code = sd_ble_gatts_value_set(BLE_CONN_HANDLE_INVALID, m_lbs.battery_char_handles.cccd_handle, &gatts_value);
	APP_ERROR_CHECK(err_code);

Here, i set the value of the CCCD characteristic, but the nrf51 DK reset at APP_ERROR_CHECK(err_code).

I have the error code equal to 0x0000000F. So it is not possible (for me) to set programmatically (directly in the code) the CCCD value.

Thanks.

  • Hi,

    This is intended. It is up to the peer to decide if it wants notifications and/or indications from you. Forcing a notification upon a device would be violating the spec. The reason for this is that some devices might not support them at all, and notifications are not requests, so the device cannot respond and say "Unsupported Opcode".

    You are however required to store these values between connections, but only for bonded devices. This can be accomplished with the sd_ble_gatts_sys_attr_get and sd_ble_gatts_sys_attr_set calls, which will retrieve and set the CCCD/SCCD values for a specific connection handle. If you are using the SDK, the Peer Manager module automatically handles this.

  • Thanks Ulrich.

    It's clear, so it is from for example, my android app (Master) to set the CCCD in the the characteristic in the slave.

Related