Skip to content

FAQ: Cannot connect

Dariusz Seweryn edited this page Jun 10, 2020 · 7 revisions

Known Android BLE Stack peculiarities

This library aims for removing as much of Android related issues as possible so the user will not have to think about them. Unfortunately this is not always possible without a handicap on usefulness or aggressive actions to ensure proper behaviour.
The usual symptom of Android BLE Stack issues is the dreaded status=133 (or 0x85 in hexadecimal). It usually means that the OS was not been able to connect to a given peripheral. It may be because the peripheral is no longer advertising and it is a valid reason. For other mitigable scenarios read below.

Connect without a scan

Direct connect to a peripheral (RxBleDevice.establishConnection(autoConnect = false)) may not succeed until it will be scanned. The problem is that the Android OS exposes a 48 bit MAC address identifier which does not contain information about the address type (public/random/etc.). This information is contained by the internal Android BLE stack which is cleared once the BluetoothAdapter is turned off. After this clear if you try to connect to your peripheral the Android makes a guess under the hood to figure out the type address. If the guess will not be correct then a connection will not succeed until the device will get re-scanned. (source)

  • To mitigate the problem you should track the changes in the BluetoothAdapter's state and always scan your peripheral before connecting (whether you know that adapter was turned off or do not know it was turned off).

Connect while scanning

Some Android devices (i.e. Huawei, Asus) are reportedly not handling well connecting to a peripheral if there is an ongoing BLE scan. Sometimes it is a system service initiated scan.

  • To have a solution that works on most of the devices out there you must first stop the scan before you start to connect to a peripheral.

Connect right after scanning

Some devices are not connecting properly right after the BLE scan has finished.

  • This issue can be worked around by adding a delay of 500 ms between the end of the BLE scan and the beginning of a connection. (500 ms between disposing RxBleClient.scanBleDevices() and subscribing to RxBleDevice.establishConnection()

Other notable issues

Environment rich in Bluetooth devices

There was an issue (reportedly fixed ~Android 7.0) that crashed Android Bluetooth stack when around 1990 Bluetooth devices were scanned.

Calling BluetoothGatt.close() with wrong timing

There is an issue which can make keep an open connection to a BLE device despite calling BluetoothGatt.close() (this part is mitigated by the library as far as we are aware). There was a similar issue with connection being established at around the same time the app canceled connection resulting in the Android not being aware of it (nor app) but connection being kept established anyway (see issue #483).