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

softreset after call sd_ble_gap_disconnect()

Hi support team,

In my case, i want to auto disconnect to ble central after some minutes with no message transfered, so i create an timmer and set event compare and clear timmer insite event nus_data_handler(). It's working, but my device was reset after execute function sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION). I use NRF connect tool to check connection handle and i got reason BLE_HCI_CONNECTION_TIMEOUT (maybe my device was disconnected but it not send any message to ble central so that after 4s event timeout triggered). Could you show me how to safety disconnect to ble central.
Thanks.

  • Hi,

    It's working, but my device was reset after execute function sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION)

    You should never see a reset out of the blue. If you see a reset in this case, I suspect an error handler has been hit. Could you have used an invalid connection handle in the call to sd_ble_gap_disconnect()? If the nRF is reset before a disconnect occurs, this will be seen as a timeout on the peer side. Can you debug to check what actually happens when you attempt to disconnect? What is the return value of sd_ble_gap_disconnect()? If that is NRF_SUCCESS, then I suggest you keep debugging to see what else is causing the reset.

    Could you show me how to safety disconnect to ble central.

    the safe and correct way to disconnect is to call sd_ble_gap_disconnect() with the correct connection handle. Please remember that from this point the connection will no longer be valid, so if you continue to use the connection handle that will cause problems (typically an invalid sate error from the API where it is used).

  • For more detail, i have funcion app_error_fault_handler(), i set breakpoint there and call APP_ERROR_CHECK(err_code) to know NRF_ERROR. Because i have only one m_conn_handle and it handle in orther function so i'm sure it's a valid. In addition i set m_conn_handle = BLE_CONN_HANDLE_INVALID before call sd_ble_gap_disconnect() but it not working. when debuger run into event timmer_compare (as I described above) my device was reset exactly when call sd_ble_gap_disconnect() with no err_code response (it's not run out of function disconnect) 

  • Hi,

    I see. It could be that the SoftDevice asserted for some reason, though that may be a long shot, and in that case, you should hit the breakpoint you set in the app_error_fault_handler(). I have no other suggestions then to dig deeper into this with a debugger. If you get stuck, I can also try this on my side it if you can upload a piece of code that reproduces the issue on a DK?

  • I attack code zip file below. it's base on example ble_app_uart and I add a timmer with compare event to disconnect ble after 10s

    4061.ble_app_uart.zip

Related