Android bluetooth low energy (ble) writeCharacteristic delay callback

前端 未结 4 2013
失恋的感觉
失恋的感觉 2021-02-06 16:10

I am implementing a application on Android using BLE Api (SDK 18), and I have a issue that the transfer data process is delay very slow. This is my log.

03-1

4条回答
  •  清酒与你
    2021-02-06 16:15

    We had the same problem. It occurs after several writes and goes away when you reconnect the Gatt. What we do is measure the delay between writeCharacteristic() and onCharacteristicWrite(). If it is above a certain threshold (1500ms), we disconnect() and close() the gatt server and reconnect. After that it is usually fine for a while.

    When doing this it might become necessary to disable the whole bluetooth adapter and reenable it. Otherwise the first reconnect to the gatt server fails and it takes about 15 seconds until it is reconnected. Sometimes it never reconnects.

    When disabling the adapter you might run into the problem that service discovery does not return in onServicesDiscovered(). We have currently no solution for that.

提交回复
热议问题