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

No disconnect event after bond on Android

Hello,

To reproduce this problem I use these steps:

  1. Bond to NRF51822 using Android 6.0.1 and latest nRF Connect version;
  2. After successful bond, connect to NRF51822;
  3. Use "DISCONNECT" button in nRF Connect application;

After these steps my application does not get BLE_GAP_EVT_DISCONNECTED event. As a consequence it does not advertise.

I am using custom board with NRF51822, S130 v2.0.1, SDK v12.1.0. My application has a custom profile. Note: problem is also reproducible with ble_app_hrs_freertos example.

Some insights:

  1. If I repeat connect/disconnect action from nRF Connect for few times I eventually get BLE_GAP_EVT_DISCONNECTED with reason BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION. After that I get disconnect events in application on every disconnect from android.
  2. If I turn off bluetooth on mobile phone or reset NRF51822 after bond, I receive disconnect event later on;
  3. This behaviour does not reproduce with S110 and SDK v10;
  4. This behavior does not reproduce with android version 5.0;
  • FormerMember
    0 FormerMember

    Could you use the sniffer to capture what is being transmitted over the air? And then, specifically check if the disconnect packet from nRF Connect is transmitted? And also check if the slave responds to that packet?

    Do you see this problem if using the "normal" ble_app_hrs in SDK 12.1.0 (without free rtos)?

  • I also notice the behavior you described. This is an "issue" on the client (Android phone) and not on the server.

    When a BLE peripheral is bonded to an Android phone (from Android 6 an higher ?), the disconnect request is not sent most of the time. If you are connected, as soon as you "forget" the bonded device, you will receive the disconnect event. If you turn the Bluetooth off on your phone, you will also get the disconnect event after the timeout you defined in the connection parameters.

    The Android API has only one method to disconnect. I used an Ellisys sniffer and no disconnect request are sent at all if the device is paired. You can to the test yourself. You can forget the bonded device using the "bonded" tab in nRF Connect for Android.

    This behavior is also quite annoying for me. It appends on Android Nexus phones running Android 6 and 7. You can use any demo application on the server, you will get the same behavior, unfortunately.

    Turning off the Bluetooth on the phone or removing a paired device is not acceptable. As a workaround, you could send the disconnect request from the server (you could write to a characteristic value to the server or another similar mechanism).

    The disconnection in BLE is always a bit tricky. This behavior on Android is not very clear for me. On iOS, the disconnect request has the same behavior with paired devices or not.

    Any Android developer at Nordic could help us with this issue ?

  • Hi, as far as I know the first disconnection after Edit: OOB (Out Of Band) bonding will not work when Disconnect sent from the Android side. After reconnecting it should work properly every time.

    The fix for that is already on AOSP but will not be included in N release. I'll try to get a link to a commit. Edit: found it: android-review.googlesource.com/

    Disconnecting after pairing from Settings should work normally, but as you see above some phones may have problems (however, I have never had such issue).

    As a workaround you would have to disconnect from the peripheral side, perhaps just after bonding? After that phone could connect again.

  • Thanks for your message. Would be interested if you could find that commit. This fix will not be included in N 7.1.1 ?

  • Added a suggested workaround to disconnect from the peripheral side after bonding. Now get disconnect events from central and it works fine so far.

Related