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

BLE Disconnection does not work when "bt_conn_disconnect" is used

Build Environment - NCS 1.4.0

Board - nrf52840dk_nrf52840

Samples used - "central_hr" & "peripheral_hr"

Code changes - in "peripheral_hr" - src/main.c - replace the while(1) loop with the following code (disconnection attempt is made every 10 seconds)

while (1) {
    static int count;

    if ( !((++count%10)) ) { 
        if (default_conn) {
            int err = bt_conn_disconnect(default_conn, BT_HCI_ERR_SUCCESS);
            printk("Err RC = %d\n", err);
        }
    }
    k_sleep(K_SECONDS(1));

    /* Heartrate measurements simulation */
    hrs_notify();

    /* Battery level simulation */
    bas_notify();
}

Expected behaviour -

  1. HR notifications are sent for 9 seconds.
  2. Disconnection is triggered on 10th second.
  3. Advertising resumes.
  4. Central scans and reconnects.
  5. Cycle repeats

Issues observed -

  1. Return code "err" is 0, but advertising does not start.
  2. Scanning does not resume on the central.

Note - When the same code is built with Zephyr 2.4.0 using the board "nrf52840dk_nrf52840", the code behaves as expected.

Related