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?

  • Hi Rasmus,

    Could you explain what you observed when you said "the call will block" ? How do you know it ? If you set a break point at if (error_code != NRF_SUCCESS) would the debugger stops there ?

    The call to sd_ble_gatts_value_get() should be returned, unless you get a hardfault. Usually if the connection is disconnect, you will have BLE_ERROR_INVALID_CONN_HANDLE returned.

  • I've used a very low tech debugging technique for this problem. I set a break-point before and after the call to sd_ble_gatts_value_get() and set pass-count to 1000. Using this technique I see the two brek-points listed every time the call succed, and when the call blocks I only see the break-point before the call is made and not the one after. I have also tried to add a condition to the break-point before the call, so that it will break if conn_handle is not what it is supposed to be. This test did not indicate any misbehaviour at all.

  • What do you mean by "pass-count" ? How do you know if breakpoint is passed or not. Note that if you set the breakpoint when debugging, the softdevice won't work normally after that because the timing is messed up and you will most likely have a hardfault.

    Have you tried to use uart logging ?

  • For clearity I am working on a PC, writing an application to run on the PC using the pca10031 USB dongle. I am using Embarcadero XE7 IDE where I can set break-points and make it break after a number of passes. I am using this count feature exactly because the SoftDevice will not work after a break.

  • @Ramus: Sorry I am not very familiar with Embarcadero . But there could be other reason that it's blocked by something else, not because of the call. I would suggest you to add break point in the application assert handler. Also check if hardfault is triggered. If you can upload a simple example that can reproduce the issue, so that we can test here. It would be great.

Related