Android bluetooth low energy (ble) writeCharacteristic delay callback
2014-06-11 14:16
316 查看
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-12 16:20:05.121: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...
03-12 16:20:06.272: D/BluetoothGatt(13578): onCharacteristicWrite() - Device=... UUID=... Status=0
03-12 16:20:06.972: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...
03-12 16:20:08.254: D/BluetoothGatt(13578): onCharacteristicWrite() - Device=... UUID=... Status=0
03-12 16:20:10.055: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...
03-12 16:20:11.257: D/BluetoothGatt(13578): onCharacteristicWrite() - Device=... UUID=... Status=0
03-12 16:20:12.478: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...
03-12 16:20:14.250: D/BluetoothGatt(13578): onCharacteristicWrite() - Device=... UUID=... Status=0
03-12 16:20:14.960: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...
03-12 16:20:16.242: D/BluetoothGatt(13578): onCharacteristicWrite() - Device=... UUID=... Status=0
03-12 16:20:16.402: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...
03-12 16:20:20.225: D/BluetoothGatt(13578): onCharacteristicWrite() - Device=... UUID=... Status=0
03-12 16:20:20.526: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...
03-12 16:20:24.219: D/BluetoothGatt(13578): onCharacteristicWrite() - Device=... UUID=... Status=0
03-12 16:20:25.360: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...
03-12 16:20:27.222: D/BluetoothGatt(13578): onCharacteristicWrite() - Device=... UUID=... Status=0
For more information, I found that every Transfer Progress only completes when it has the onCharacteristicWrite callback, this means that all sending command before receive onCharacteristicWrite callback will be ignored.
Is this the flow of Android we have to following or there is any way to setup it skip the callback step to speed up the progress.
My code is:
EDIT: I have a comparison with iPhone (a BLE transfer data app from AppStore), the BLE transfer data is very quick (less than 0.5 sec), so impressive. How can we work around to SPEED UP the Android BLE Transfer progress?.
EDIT: If I set WriteType of BluetoothGattCharacteristic to WRITE_TYPE_NO_RESPONSE, and when I send many command sequentially, the Android stores them on a queue and send to remote device one by one after receive writeCharacteristic CallBack, this leads to a issue, when you stop your sending lood, the Android Sending Progress still continue with the delay (Sometime more than 3 sec).
##############
Performance of a BLE link is highly dependent on the connection interval used, and if your connection interval is high, the performance you see may not be that unreasonable. By the Core Specification, the connection interval can be between 7.5 ms and 4 s, so there's quite some flexibility.
If it's possible for you, I'd recommend you to try changing the Peripheral you're talking to to use a shorter connection interval, which should improve performance. You may have use in taking a look at this page, explaining BLE throughput, and this page, explaining connection parameters.
http://stackoverflow.com/questions/22348470/android-bluetooth-low-energy-ble-writecharacteristic-delay-callback
03-12 16:20:05.121: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...
03-12 16:20:06.272: D/BluetoothGatt(13578): onCharacteristicWrite() - Device=... UUID=... Status=0
03-12 16:20:06.972: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...
03-12 16:20:08.254: D/BluetoothGatt(13578): onCharacteristicWrite() - Device=... UUID=... Status=0
03-12 16:20:10.055: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...
03-12 16:20:11.257: D/BluetoothGatt(13578): onCharacteristicWrite() - Device=... UUID=... Status=0
03-12 16:20:12.478: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...
03-12 16:20:14.250: D/BluetoothGatt(13578): onCharacteristicWrite() - Device=... UUID=... Status=0
03-12 16:20:14.960: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...
03-12 16:20:16.242: D/BluetoothGatt(13578): onCharacteristicWrite() - Device=... UUID=... Status=0
03-12 16:20:16.402: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...
03-12 16:20:20.225: D/BluetoothGatt(13578): onCharacteristicWrite() - Device=... UUID=... Status=0
03-12 16:20:20.526: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...
03-12 16:20:24.219: D/BluetoothGatt(13578): onCharacteristicWrite() - Device=... UUID=... Status=0
03-12 16:20:25.360: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...
03-12 16:20:27.222: D/BluetoothGatt(13578): onCharacteristicWrite() - Device=... UUID=... Status=0
For more information, I found that every Transfer Progress only completes when it has the onCharacteristicWrite callback, this means that all sending command before receive onCharacteristicWrite callback will be ignored.
Is this the flow of Android we have to following or there is any way to setup it skip the callback step to speed up the progress.
My code is:
privatefinalBluetoothGattCallback mGattCallback =newBluetoothGattCallback(){......@Overridepublicvoid onCharacteristicWrite(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic,int status){ mSending =false;}};privatevoid writeCharacteristic(){..... mGattCharacSetIntensity.setValue(data); mGattCharacSetIntensity.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT); mBluetoothGatt.writeCharacteristic(mGattCharacSetIntensity);return;}
EDIT: I have a comparison with iPhone (a BLE transfer data app from AppStore), the BLE transfer data is very quick (less than 0.5 sec), so impressive. How can we work around to SPEED UP the Android BLE Transfer progress?.
EDIT: If I set WriteType of BluetoothGattCharacteristic to WRITE_TYPE_NO_RESPONSE, and when I send many command sequentially, the Android stores them on a queue and send to remote device one by one after receive writeCharacteristic CallBack, this leads to a issue, when you stop your sending lood, the Android Sending Progress still continue with the delay (Sometime more than 3 sec).
##############
Performance of a BLE link is highly dependent on the connection interval used, and if your connection interval is high, the performance you see may not be that unreasonable. By the Core Specification, the connection interval can be between 7.5 ms and 4 s, so there's quite some flexibility.
If it's possible for you, I'd recommend you to try changing the Peripheral you're talking to to use a shorter connection interval, which should improve performance. You may have use in taking a look at this page, explaining BLE throughput, and this page, explaining connection parameters.
http://stackoverflow.com/questions/22348470/android-bluetooth-low-energy-ble-writecharacteristic-delay-callback
相关文章推荐
- Android-Bluetooth Low Energy(BLE)
- Android:BLE(Bluetooth Low Energy)开发
- Android Bluetooth4.0(BLE是Bluetooth Low Energy的简称) 官方API
- Android ble onCharacteristicChanged()无法触发BluetoothGattCallback
- Android使用BLE(低功耗蓝牙,Bluetooth Low Energy)
- Android-低功耗蓝牙BLE(Bluetooth Low Energy)开发
- Android Bluetooth Low Energy(Android低功耗蓝牙)
- Android Bluetooth Low Energy(Android低功耗蓝牙)
- Android使用Bluetooth和Bluetooth Low Energy实现蓝牙以及蓝牙4.0,一行代码实现
- How to Implement Bluetooth Low Energy (BLE) in Ice Cream Sandwich
- Android Bluetooth Low Energy官方文档翻译
- Android Bluetooth Low Energy(Android低功耗蓝牙)
- Android Bluetooth Low Energy
- BLE(Bluetooth Low Energy)---first part
- Bluetooth Low Energy for Android --- Google官方说明文档(英文)
- 【转】android 4.3 BLE onCharacteristicWrite没有回调
- 蓝牙 BlueTooth Low Energy (BLE)
- 基于蓝牙4.0的蓝牙打印机 低耗电蓝牙 BLE (Bluetooth Low Energy)
- 低功耗蓝牙Bluetooth Low Energy(BLE)
- Android5.0(Lollipop) 蓝牙BLE(Bluetooth Low Energy)