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

Using Android BLE library, getting into a connecting -> disconnecting (timeout) situation. nRF app seems to help.

Hi,

We're using the Android BLE library from Nordic. It really helped us handle a lot of the things we didn't want to think about handling on the bluetooth stack. (Thank you)

We've been experiencing some weird issues where the sensors will get into a connecting -> disconnecting issues, effectively timing out on connect.

The flow is : 

  • we scan for devices using the compact scanner (nordic)
  • we try to connect to one or more devices
  • the connection attempt would time out

The interesting thing we've found is that if we use nRF connect application (Android) on the same device (phone), and try to connect to the device it works. And surprisingly, right after connecting and disconnecting using nRF connect app, the devices will connect to the Android app (also using BLE library from Nordic) successfully as well. Are we missing to do anything properly. What are the steps on nRF connect app on connect and disconnect? We are thinking it might be that we got the driver or the sensor into a weird state and nRF connect app connection fixes it somehow?

Running out of ideas because we're tried many different things such as putting delays in possible places. Thanks!

  • Hi,

    Logs would be great for establishing what happens.

    nRF Connect does not use the Android BLE Library. The main difference is probably that in nRF Connect for Android, the cache is cleared on disconnection. You can get that same behavior in the BLE Library by changing shouldClearCacheWhenDisconnected() to return true instead of false. The issue may have to do with caching, and if so then that might be a solution.

    How do you recover from the error state? Do you use bonding? Pairing?

    Regards,
    Terje

  • Thank you. I will test `shouldClearCacheWhenDisconnected()` and report back my findings.

    We are not using bonding or pairing. (We cannot recover from error state: see logs below)

    The one way we've found works by launching nRF connect app; from my observation we don't even need to hit "connect" on the nRF app. If our app is trying to connect to the device stuck in the follow log and we launch the nRF connect app to scan for devices - it will successfully connect to it. Could it be something with the way we're scanning? (We switched to compact scanner library from Nordic recently from our own scanner)

    Thanks for the help, looking forward to hearing your thoughts on what might be happening.

    For the logs : here's what I have

    2019-06-20 10:07:01.729 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Connecting...
    2019-06-20 10:07:01.731 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, LE 1M)
    2019-06-20 10:07:11.766 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Cancelling connection...
    2019-06-20 10:07:11.769 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt.disconnect()
    2019-06-20 10:07:11.773 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Disconnected
    2019-06-20 10:07:11.782 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt.close()
    2019-06-20 10:07:11.784 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : wait(200)
    2019-06-20 10:07:11.987 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Connecting...
    2019-06-20 10:07:11.995 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, LE 1M)
    2019-06-20 10:07:21.782 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Cancelling connection...
    2019-06-20 10:07:21.789 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt.disconnect()
    2019-06-20 10:07:21.796 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Disconnected
    2019-06-20 10:07:21.810 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt.close()
    2019-06-20 10:07:21.813 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : wait(200)
    2019-06-20 10:07:22.016 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Connecting...
    2019-06-20 10:07:22.023 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, LE 1M)
    2019-06-20 10:07:31.806 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Cancelling connection...
    2019-06-20 10:07:31.813 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt.disconnect()
    2019-06-20 10:07:31.821 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Disconnected
    2019-06-20 10:07:31.836 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt.close()
    2019-06-20 10:07:31.840 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : wait(200)
    2019-06-20 10:07:32.041 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Connecting...
    2019-06-20 10:07:32.045 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, LE 1M)
    2019-06-20 10:07:41.834 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Cancelling connection...
    2019-06-20 10:07:41.837 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt.disconnect()
    2019-06-20 10:07:41.844 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Disconnected
    2019-06-20 10:07:41.859 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt.close()
    2019-06-20 10:07:41.861 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : wait(200)
    2019-06-20 10:07:42.062 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Connecting...
    2019-06-20 10:07:42.066 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, LE 1M)
    2019-06-20 10:07:51.856 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Cancelling connection...
    2019-06-20 10:07:51.862 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt.disconnect()
    2019-06-20 10:07:51.872 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Disconnected
    2019-06-20 10:07:51.883 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt.close()
    2019-06-20 10:07:51.886 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : wait(200)
    2019-06-20 10:07:52.087 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Connecting...
    2019-06-20 10:07:52.092 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, LE 1M)
    2019-06-20 10:08:01.882 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Cancelling connection...
    2019-06-20 10:08:01.888 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt.disconnect()
    2019-06-20 10:08:01.894 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Disconnected
    2019-06-20 10:08:01.906 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt.close()
    2019-06-20 10:08:01.910 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : wait(200)
    2019-06-20 10:08:02.112 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : Connecting...
    2019-06-20 10:08:02.118 31999-31999/ai.cloud I/Stream: StreamBleManager : Message : gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, LE 1M)

  • This issue still happens even when I override `shouldClearCacheWhenDisconnected()` to return true. 

    As I've mentioned before, it seems like I we just launch nRF connect (Android) app in the same android device - this timeout issue will go away. The important distinction is that we are not doing anything on the nRF app, we just launch it (no connect/disconnects).

    Any thoughts as to why? If nRF connect code was open source, I would look at what it does and test those out but seems like it's not. Slight smile

    Thanks!

Related