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

S130 sd_ble_gatts_value_get block

Hello Everyone

I have an issue when reading the value of an attribute using sd_ble_gatts_value_get, where if the connection has been lost, the call will block for ever. I use the following cleaned snippet.

uint16_t conn_handle;
uint16_t att_handle;
ble_gatts_value_t gatt_value;

get_att_handle(&att_handle);
get_conn_handle(&conn_handle);

gatt_value.len = 2;
gatt_value.offset = 0;
gatt_value.p_value = (uint8_t *)value;

error_code = sd_ble_gatts_value_get(conn_handle, att_handle, &gatt_value);
if (error_code != NRF_SUCCESS)
{
  //handle error
}

The characteristic I am reading has a vendor specefic UUID and data is fixed width 2 bytes. I am calling the snippet above in a loop to wait for a specific value. Everything works fine untill the device is disconnected. I have verified that the same thing happen no matter if I use the correct conn_handle or BLE_CONN_HANDLE_INVALID; everything Works fine untill connection is lost, after this the call will block.

Has anyone experienced this before, or perhaps know of a solution?

  • It seems like if the connection is in a "waiting for timeout" state, the call will block. Sometimes the connection is really disconnect before the call to sd_ble_gatts_value_get() and the call will not block.

  • I tried to reproduce the issue here, but couldn't see anything wrong. What I did was to add this code

    if (err_code == NRF_SUCCESS)
    					{
    						 err_code = sd_ble_gap_disconnect(p_bas->conn_handle,0x13);
    
    						err_code = sd_ble_gatts_value_get(p_bas->conn_handle,  p_bas->battery_level_handles.value_handle, &gatts_value);
    
    					}
    

    in ble_bas_battery_level_update() in ble_bas.c in the ble_app_hrs example (after the line err_code = sd_ble_gatts_hvx...) . So that sd_ble_gatts_value_get() will be called right after the disconnect request. But it worked fine, I haven't seen any issue.

    How often do you see the issue ? Could you provide an simple example that we can test here ?

Related