Android的蓝牙低功耗(BLE)writeCharacteristic延迟回调 [英] Android bluetooth low energy (ble) writeCharacteristic delay callback

查看:6306
本文介绍了Android的蓝牙低功耗(BLE)writeCharacteristic延迟回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在执行上采用Android BLE API(SDK 18)一个应用程序,我有一个问题是,数据传输过程中的延迟非常缓慢。这是我的日志。

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:05.121: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...

03-12 16:20:06.272:D / BluetoothGatt(13578):onCharacteristicWrite() - 设备= ... UUID = ...状态= 0

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:06.972: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...

03-12 16:20:08.254:D / BluetoothGatt(13578):onCharacteristicWrite() - 设备= ... UUID = ...状态= 0

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:10.055: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...

03-12 16:20:11.257:D / BluetoothGatt(13578):onCharacteristicWrite() - 设备= ... UUID = ...状态= 0

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:12.478: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...

03-12 16:20:14.250:D / BluetoothGatt(13578):onCharacteristicWrite() - 设备= ... UUID = ...状态= 0

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:14.960: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...

03-12 16:20:16.242:D / BluetoothGatt(13578):onCharacteristicWrite() - 设备= ... UUID = ...状态= 0

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:16.402: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...

03-12 16:20:20.225:D / BluetoothGatt(13578):onCharacteristicWrite() - 设备= ... UUID = ...状态= 0

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:20.526: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...

03-12 16:20:24.219:D / BluetoothGatt(13578):onCharacteristicWrite() - 设备= ... UUID = ...状态= 0

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:25.360: D/BluetoothGatt(13578): writeCharacteristic() - uuid: ...

03-12 16:20:27.222:D / BluetoothGatt(13578):onCharacteristicWrite() - 设备= ... UUID = ...状态= 0

03-12 16:20:27.222: D/BluetoothGatt(13578): onCharacteristicWrite() - Device=... UUID=... Status=0

有关详细信息,我发现,只有当它有onCharacteristicWrite回调完成,每一个传输进度,这意味着所有发送命令之前收到onCharacteristicWrite回调将被忽略。

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.

这是Android的流动,我们必须下或者有什么办法来设置它跳过回调一步加快进度。

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.

我的code是:

private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
......
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
    mSending = false;
}
};

private void writeCharacteristic() {
    .....

    mGattCharacSetIntensity.setValue(data);
    mGattCharacSetIntensity.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
    mBluetoothGatt.writeCharacteristic(mGattCharacSetIntensity);
    return;
}

编辑:我有iPhone(从AppStore的一个BLE传输数据的应用程序)进行比较时,BLE传输数据非常快(小于0.5秒),因此Im pressive。我们怎样才能解决,加快了Android BLE转让的进展?

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?.

编辑:如果我设置BluetoothGattCharacteristic的WriteType到WRITE_TYPE_NO_RESPONSE,当我发指令顺序多,他们在Android商店上的队列,并发送至远程设备逐一接收后writeCharacteristic回调,这将导致一个问题,当你停止你发送lood,Android的发送进度仍然继续延迟(有时超过3秒)。

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).

推荐答案

一个BLE连接的性能在很大程度上取决于所使用的连接时间,如果你的连接时间间隔为高,你看到的性能可能不是不合理的。由核心规格,连接间隔可以是7.5毫秒和4秒之间,所以有相当一定的灵活性。

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.

如果有可能为你,我建议你尝试改变周围你说要使用更短的连接时间,这将有助于改善性能。您可能需要使用采取一看的此页面,解释rel="nofollow">此页BLE吞吐量和,说明连接参数。

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.

这篇关于Android的蓝牙低功耗(BLE)writeCharacteristic延迟回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆