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

Android scanner app connects to device but my program doesn't

Actually refers to the mobile version of nRF Connect but it's not on the menu.

I have inherited a legacy Android app that connects to various BLE devices and reads data. Works OK except for one device (a weight scale). It simply won't connect whether or not autoConnect is set. Any attempts to connect return immediately with a generic GATT_ERROR (code 0x85).

Your mobile scanner app can connect and seems to function normally. So can another test program I wrote using the RxAndroidBle library. Interestingly, with this library, it only works if autoConnect is true: if it's false I get an "already connected" error. I get this same error even if autoConnect is true, but after a few seconds it resolves itself and connects.

Wondering if your software experts can suggest things to try. I'm at my wits' end.

(I've run nRF Connect on iOS, and Android 8.0 and 5.0; works on all.)

Parents
  • Hi,

    So what I would recommend is:

    1. First always connect with autoConnect = false, as it's much faster. Only when the device looses link and the app is in background you may use autoConnect = true so you don't bother with timeouts, etc. But when user awaits actively, use false.

    2. Try connecting on UI thread. Some phones, for example from Samsung, like when you do BLE operations on the main thread.

    3. If other devices are working, I'd say it's something with the weight scale. Did you try to sniff or get HCI snoop logs from the Android? Did you compare to other devices, is there any difference?

    4. Did you try another phone? It may be that your phone does not support some feature and after feature exchange it disconnects instead of ignoring it.

    The Android API on Android is so simple, that it's really hard to do it wrong. Unfortunately, there is a lot of 'workarounds' to make a connection more stable, like add delays, use UI thread, retry, clear device cache, etc, but none of then should be required.

    PS. I recommend using our BLE Library (https://github.com/NordicSemiconductor/Android-BLE-Library/) for keeping the connection, and in fact version 2 of it (develop branch). Version 2-alpha is highly not-stable but I'd like some feedback! However, RxAndroidBle should also  work properly.

Reply
  • Hi,

    So what I would recommend is:

    1. First always connect with autoConnect = false, as it's much faster. Only when the device looses link and the app is in background you may use autoConnect = true so you don't bother with timeouts, etc. But when user awaits actively, use false.

    2. Try connecting on UI thread. Some phones, for example from Samsung, like when you do BLE operations on the main thread.

    3. If other devices are working, I'd say it's something with the weight scale. Did you try to sniff or get HCI snoop logs from the Android? Did you compare to other devices, is there any difference?

    4. Did you try another phone? It may be that your phone does not support some feature and after feature exchange it disconnects instead of ignoring it.

    The Android API on Android is so simple, that it's really hard to do it wrong. Unfortunately, there is a lot of 'workarounds' to make a connection more stable, like add delays, use UI thread, retry, clear device cache, etc, but none of then should be required.

    PS. I recommend using our BLE Library (https://github.com/NordicSemiconductor/Android-BLE-Library/) for keeping the connection, and in fact version 2 of it (develop branch). Version 2-alpha is highly not-stable but I'd like some feedback! However, RxAndroidBle should also  work properly.

Children
No Data
Related