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

Properly disconnection in central device

Hi. I'm working on central device which is connecting to peripheral device. I used blinky example, modified characteristics to my needs and it works fine.

Now I try to do scenario: after switch button, I'm starting to scan, connect, exchange information and disconnect. The problem is properly disconnection.

I'm not sure can I do disconnecting after my timeout is up and how to properly call right "conn handle" parameter (based on ble_app_blinky_c)?

err_code = sd_ble_gap_disconnect(?conn_handle?, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);

I'm using: nRF52832, SDK15.3, SD132 v6.1.1

Best regards,

PW

Parents
  • Hello,

    You get the conn_handle in the connected event, so you can save it. E.g. the ble_app_uart example the conn handle is saved in the BLE_GAP_EVT_CONNECTED event in main.c:

    m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;

    Remember to reset the conn_handle in the BLE_GAP_EVT_DISCONNECTED event:

    m_conn_handle = BLE_CONN_HANDLE_INVALID;

    Best regards,

    Edvin

Reply
  • Hello,

    You get the conn_handle in the connected event, so you can save it. E.g. the ble_app_uart example the conn handle is saved in the BLE_GAP_EVT_CONNECTED event in main.c:

    m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;

    Remember to reset the conn_handle in the BLE_GAP_EVT_DISCONNECTED event:

    m_conn_handle = BLE_CONN_HANDLE_INVALID;

    Best regards,

    Edvin

Children
Related