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

nRF Connect for android disconnects with Error 22: 'gatt conn terminate local host'

Hi,

I'm testing stability of my firmware. As a part of tests I'm trying to maintain long term (multiple days) connection between nRF52 and nRF Connect for Android app running on Xiaomi Mi 2 (BLE5.0 capable hardware with Android 8.0). Every 24h or so I'm getting Error 22 code and nRF Connect disconnects. From nRF52 side everything looks ok, no asserts or error codes. Softdevice events look as Android phone has gracefully shut down the connection. What might be an issue? How could I approach debugging this further?

  • For anyone who ends up in this thread because of the nRF Connect "ERROR 22" issue, I just spent 2 h trying to figure out the reson in my case.

    So, just to recap the details of the issue:

    • my device (NRF52832QFAAE0) is a BLE peripheral serving as GATT Server, using SoftDevice s132 v7.0.1, SDK16.0.0.
    • NRF_SDH_BLE_CENTRAL_LINK_COUNT       = 0
    • NRF_SDH_BLE_PERIPHERAL_LINK_COUNT = 1
    • my device was not showing any known or unknown or assertion fail
    • my device was correctly advertising and accepting connection (without bonding)
    • after 30 seconds from each connection, my smartphone (OnePlus 5T, android 9) is dropping the connection with error 22 (0x16)
    • I was using nRF Connect version 4.24.1

    The 30 second timeout of my phone lead me to think that my device was probably not replying to a GATT query from my phone.
    After dumping all the BLE events, I noticed that I was receiving a HVX event of type INDICATION.

    At first I solved it with a simple call to:

    sd_ble_gattc_hv_confirm(p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->evt.gattc_evt.params.hvx.handle);

    A second inspection brought me to find out that my NRF app was configured with an example of GATT service and apparently was sending indication to my device. Disabling it solved my issue.

    Please, nRF Team, look into this, and maybe put a warning in the app if the server example is enabled by default.
    Still, I'm nos sure how is it possible to receive Indications if i'm not enabling any client feature in my device.


  • Hi  ,

       I have disabled the indication for example GATT service, even though I am facing the same issue.

  • Hi, i have the same problem. And i'm really curious to know the answer to the previous question: "I'm not sure how is it possible to receive Indications if i'm not enabling any client feature in my device" ?

    Thx

  • Hi,

    To sum up, the issue is that the smartphone app has a GATT server, and it sends indications to the nRF device, even if the nRF device has changed application to something not expecting indications?

    Note that the nRF device, by default, will always use the same BLE address. So it might be the smartphone remembering from a previous session that the device of that address had enabled indications. However, from what I understand that should not happen unless the device is bonded... So if that is indeed what is happening then there is something wrong either in the app or in the BLE stack of the smartphone. It would still be worth trying the workaround from a previous answer in this thread:

    ivnn said:
    to solve this issue go to Android Settings->Bluetooth->Paired devices-> and unpair your dev

    Regards,
    Terje

Related