Android的BLE连接缓慢 [英] android ble connect slowly

查看:5106
本文介绍了Android的BLE连接缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在写一个Android应用程序连接到BLE外围设备。安卓4.4.2,Galaxy Nexus的。

我有一个设备上的LED指示连接状态。

这个问题是从持续时间 connectGatt()拨打接收onConnectionStateChange STATE_CONNECTED 的点是如此的不一致。一些时间,它是非常快,但大多数时候花费5秒以上。打开蓝牙关闭/打开没有任何效果。

我试过的 TI BTool 的PC机上用的 TI BLE 的适配器,它总是建立连接速度非常快。

我也试过与iPhone 5S,这是快了。

  1. 在任何一个经历了这个问题呢?
  2. 是否有任何机会,我们可以改善呢?
解决方案

传递真实的connectGatt()自动连接参数请求后台连接,同时通过虚假请求的直接连接。 BluetoothGatt#连接()总是请求后台连接。

背景连接(根据来自4.4.2 AOSP Bluedroid源)具有1280ms的扫描间隔和11.25ms的一个窗口。这对应于大约0.9%的占空比这解释了为什么连接,当不进行扫描时,可能需要很长的时间才能完成。

直接连接具有60ms的时间间隔为30ms这样的连接完成,窗口要快得多。此外,还有只能有一个直接连接请求等待的时间和它超时后30秒。 onConnectionStateChange()被调用状态= 2,状态= 133,表示此超时。

我已经验证的Nexus5这种行为,但显然情况因人而异。

我要指出,有在BluetoothGatt.java竞争状态,可能会导致一个直接的连接请求,即使自动连接=真正传递到BluetoothDevice类#connectGatt()。

Hi I'm writing an Android app to connect to a BLE peripheral device. Android 4.4.2, Galaxy Nexus.

I have an LED on the device to indicate connection state.

The issue is the duration from connectGatt() call to the point of receiving onConnectionStateChange STATE_CONNECTED are so inconsistent. Some time it is very quick but most of the time it takes 5s or more. Turning Bluetooth off/on does not have any effect.

I tried TI BTool on PC with the TI BLE Dongle and it always establishes connection very fast.

I also tried with an iPhone 5S and it is fast too.

  1. Any one has experienced this issue too?
  2. Is there any chance we can improve this?

解决方案

Passing true to connectGatt() autoconnect argument requests a background connection, while passing false requests a direct connection. BluetoothGatt#connect() always requests a background connection.

Background connection (according to Bluedroid sources from 4.4.2 AOSP) has scan interval of 1280ms and a window of 11.25ms. This corresponds to about 0.9% duty cycle which explains why connections, when not scanning, can take a long time to complete.

Direct connection has interval of 60ms and window of 30ms so connections complete much faster. Additionally there can only be one direct connection request pending at a time and it times out after 30 seconds. onConnectionStateChange() gets called with state=2, status=133 to indicate this timeout.

I have verified this behavior on Nexus5 but obviously YMMV.

I should mention that there is a race condition in BluetoothGatt.java that can cause a direct connection request even if autoconnect=true is passed into BluetoothDevice#connectGatt().

这篇关于Android的BLE连接缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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