sd_ble_gatts_value_get and sd_ble_gatts_value_set when not in connection requires different handles

Hi,

when I am not in a connection, I want to call sd_ble_gatts_value_get() and sd_ble_gatts_value_set(). Both require a connection handle.

For the  sd_ble_gatts_value_get() I must use "0" as connection handle - else it crashes

For the sd_ble_gatts_value_set() I must use "BLE_CONN_HANDLE_INVALID" (0xFFFF) - else it crashes

Why does this functions need different handles when I am not in a connection? This is very ugly, if I can not use a common connection handle for my whole program.

Is this a bug? Is there any solution to this, except the workaround of using different connection handles for the functions (have to check before every call, if the system is in a valid connection by checking a custom variable - thats bad)

Thank you,
Regards

I use SDK 15.2.

  • With sd_ble_gatts_value_get() I want to check if notifications are enabled like this:

    sd_ble_gatts_value_get(connection_handle,
                                        *p_cccd_handle,
                                        &cccd_data);

    ret_value = ble_srv_is_notification_enabled(cccd_data.p_value);

  • Crashes means "Invalid connection handle error" - system stops because I am using APP_ERROR_CHECK()

  • Hi Andre, 

    My understanding is that you want to read if the CCCD is enabled or not. 

    But the problem is that CCCD value is connection dependent. In a connection with a central it may be set and in another connection it may be not.It's a system attribute. You would need to be in a connection to read the system attribute. 

    The application has the responsibility to keep track of the system attribute and restore it when the same central is connected, using sd_ble_gatts_sys_attr_set(). 

    When not in a connection, there is no point reading out the system attribute. You still can use 0 as connect handle but it is not guarantee the value is the correct one. 

    For sd_ble_gatts_value_set() it's correct that you need to use BLE_CONN_HANDLE_INVALID.