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

How does the slaver disconnect the connection?

Hi,

I do some function base on the ble_app_uart peoject and using the S130.Now I want the device disconnect the connection once it receives the disconnection command from UART. I do it like this: err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED); APP_ERROR_CHECK(err_code);

However,the chip will reset when runs the sd_ble_gap_disconnec API.Even I cann't see the value of the err_code variable.

What the value should be for the m_conn_handle?And how to get the current value of m_conn_handle?

Anyone could help me?Thank you very much.

  • Hey!

    First of all, the reset comes from APP_ERROR_CHECK. If you want to see the error code, you can print it before calling this function. Alternatively you can turn off the reset function by adding the "DEBUG" preprocessor symbol Target options.

    You find Target options by pressing the wand-like icon in the top left of this picture. image description

    The error handling happens in app_error.c You can set a breakpoint here on line 84, and use a debugger to view the error code and line number the error occurred.

    The connection handle must be the same as the one you get at the connection event. It is saved here in the on_ble_evt() function:

    case BLE_GAP_EVT_CONNECTED:
            err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
            APP_ERROR_CHECK(err_code);
            m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
            break;
    

    You should not use BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED as the disconnect reason though. Use BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION instead.

Related