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?
OK, I found the cause, I think I misused the APIs: Previously I call connectGatt with the 2nd param = true connectGatt(context, true, gattCallback); But now I change it to connectGatt(context, false, gattCallback); And the connecting time improved greatly –  user2810131 Mar 6 at 9:43
 
I've experimented slow connection but only when attempting to reconnecting the remote device, connecting device at first time gets no problem but reconnecting remains the connection in the onClientRegistered() method
 

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

http://stackoverflow.com/questions/22214254/android-ble-connect-slowly

最新文章

  1. ASP.NET MVC系列:Area
  2. Ie8+,强制默认使用ie8模式
  3. MySQL MVCC(多版本并发控制)
  4. HDU1054 Strategic Game——匈牙利算法
  5. 安装好grunt,cmd 提示"grunt不是内部或外部命令" 怎么办?
  6. IOS打开其他应用、以及被其他应用打开
  7. SQL Server 基础:拾遗
  8. [Hive - LanguageManual] Hive Concurrency Model (待)
  9. AXI_DMA IP学习
  10. CentOS7 VMware-Tools安装与共享文件夹设置
  11. [服务器]Gartner:2018年第四季度全球服务器收入增长17.8% 出货量增长8.5%
  12. 【转】Win10下python3和python2多版本同时安装并解决pip共存问题
  13. create-react-app项目添加less配置
  14. Hadoop生态集群MapReduce详解
  15. Go语言学习之10 Web开发与Mysql数据库
  16. router使用以及vue的动画效果
  17. [luogu P1438] 无聊的数列
  18. LAXCUS大数据操作系统节点挂掉后的处理
  19. POJ1789:Truck History(Prim算法)
  20. Java JDBC数据库链接

热门文章

  1. missing required architecture x86_64 in file 不支持64位
  2. 百度地图LBS开放平台AK一直没有用
  3. 前端插件Emmet
  4. Process Stats:了解你的APP如何使用内存(转)
  5. 在Windows Server 2012 中安装 .NET 3.5 Framework,PowerShell 安装.NET FRAMEWORK
  6. IOS中调整UI控件位置和尺寸
  7. MVC EF ObjectStateManager 中已存在具有同一键的对象。ObjectStateManager 无法跟踪具有相同键的多个对象。
  8. GIT Learning
  9. 对App数据库元素进行简单的设计
  10. 华丽的HTML5/jQuery动画和应用 前端必备