Search code examples
androidbluetooth-lowenergy

Android BLE connection speed issue


My android application uses the

BluetoothAdapter.startLeScan()

to scan for result before manually asking for it to stop by pressing a button.

Will this type of attitude affect the time of ble connection time?

I think the scanning is blocked when the bluetooth service is binded, and unblocked after connection establishment without any code to write. Is this right?

The connection time varies from time to time. It takes about 1~2 sec average, but sometimes, it takes about 5 to 6 seconds or even more. Why should this happen?


Solution

  • Will this type of attitude affect the time of ble connection time?

    Sometimes Maybe. Connection procedure is initiated by sending connect-request, after that device enters connecting state. If you manually stop scanning before device enters connecting state it may interrupt the connection following up.

    I think the scanning is blocked when the bluetooth service is binded, and unblocked after connection establishment without any code to write. Is this right?

    Yes, it is.

    The connection time varies from time to time. It takes about 1~2 sec average, but sometimes, it takes about 5 to 6 seconds or even more. Why should this happen?

    There are many reasons and you can consider one major reason first. That is BLE device's special operating mode. They are not active all the time but periodically. For example, it actives for 100ms per 10s and sleeps in other 9.9s. If you start scanning when the BLE device just enters sleep, so you need more than 9.9s.

    Secondly, problem may due to your Android device. Check that when it sends the connect-request and there is any other tasks or events may interrupt the connection procedure.

    Thirdly, there is interference or not? Maybe WIFI or USB 3.0.