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

android ble connect slowly的更多相关文章

  1. Android ble 蓝牙4.0 总结

    本文介绍Android ble 蓝牙4.0,也就是说API level >= 18,且支持蓝牙4.0的手机才可以使用,如果手机系统版本API level < 18,也是用不了蓝牙4.0的哦 ...

  2. Android BLE与终端通信(四)——实现服务器与客户端即时通讯功能

    Android BLE与终端通信(四)--实现服务器与客户端即时通讯功能 前面几篇一直在讲一些基础,其实说实话,蓝牙主要为多的还是一些概念性的东西,当你把概念都熟悉了之后,你会很简单的就可以实现一些逻 ...

  3. Android BLE与终端通信(三)——客户端与服务端通信过程以及实现数据通信

    Android BLE与终端通信(三)--客户端与服务端通信过程以及实现数据通信 前面的终究只是小知识点,上不了台面,也只能算是起到一个科普的作用,而同步到实际的开发上去,今天就来延续前两篇实现蓝牙主 ...

  4. Android BLE与终端通信(一)——Android Bluetooth基础API以及简单使用获取本地蓝牙名称地址

    Android BLE与终端通信(一)--Android Bluetooth基础API以及简单使用获取本地蓝牙名称地址 Hello,工作需要,也必须开始向BLE方向学习了,公司的核心技术就是BLE终端 ...

  5. Android ble 蓝牙4.0 总结一

    本文介绍Android ble 蓝牙4.0,也就是说API level >= 18,且支持蓝牙4.0的手机才可以使用,如果手机系统版本API level < 18,也是用不了蓝牙4.0的哦 ...

  6. Android BLE蓝牙详细解读

    代码地址如下:http://www.demodashi.com/demo/15062.html 随着物联网时代的到来,越来越多的智能硬件设备开始流行起来,比如智能手环.心率检测仪.以及各式各样的智能家 ...

  7. 快速接入 Android BLE 开发的基础框架

    代码地址如下:http://www.demodashi.com/demo/12092.html ** Android BLE基础操作框架,基于回调,操作简单.包含扫描.多连接.广播包解析.服务读写及通 ...

  8. Android BLE与终端通信(三)——client与服务端通信过程以及实现数据通信

    Android BLE与终端通信(三)--client与服务端通信过程以及实现数据通信 前面的终究仅仅是小知识点.上不了台面,也仅仅能算是起到一个科普的作用.而同步到实际的开发上去,今天就来延续前两篇 ...

  9. Android BLE 蓝牙开发——扫码枪基于BLESSED

    一.蓝牙模式HID与BLE 当扫码枪与手机连接时,通常采用的是蓝牙HID(Human Interface Device)模式.本质上是一个把扫码枪作为一个硬件键盘,按照键盘协议把扫码后的结果逐个输入到 ...

随机推荐

  1. asp.net MVC EF Where 过滤条件怎么写

    做.Net开发的肯定都知道.Net Sql语句有个SqlParameter 一般用来做过滤判断逻辑写,那么到了EF 了还有这样的写法嘛?答案肯定是有的了,这里我只是把最粗糙和简单的写法罗列一些,具体封 ...

  2. android四种更新UI的方法

    笔记: // 使用handler.post(Runnable)更新UI public void updateUI_Fun1() { new Thread() { public void run() { ...

  3. 每天一道LeetCode--374. Guess Number Higher or Lower

    We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...

  4. Cisco基本命令配置

    实验一 路由器的基本命令操作 1 实验目标 ü 熟悉路由器的命令行操作 ü 能够使用命令行帮助 ü 能够查看路由器接口信息 ü 能够产看路由器配置信息 ü 能够配置以太网接口 ü 能够配置广域网接口 ...

  5. 命令行启动tomcat,怎么配置

    进和你tomcat的安装目录进入里面bin目录下列可以直接在cmd中运行(要进入tomcat的bin目录),也可直接双击startup.bat 启动tomcatshutdown.bat 关闭tomca ...

  6. 集合类学习之HashMap

    一.HashMap概述 HashMap基于哈希表的 Map 接口的实现.此实现提供所有可选的映射操作,并允许使用 null 值和 null 键.(除了不同步和允许使用 null 之外,HashMap  ...

  7. 20150221—LINQ to SQL 查询数据

    LINQ to SQL 可以快捷的查询基于SQL的数据,直接在VS中包括基本的Object/relation映射器,O/R映射器可以快速的将基于SQL的数据源映射为CLR对象,之后就可以使用LINQ查 ...

  8. 单机版简单弹幕墙demo (jqery+bootstrap)

    最近在看fcc  ,上面有一个弹幕墙设计的题目,要求从后端获取数据,显示出来.百度,谷歌都没找到相关好的例子作为借鉴,索性按照自己的思路写了一个简单的demo  .在做demo的过程中遇到最大的问题就 ...

  9. 试写Python内建函数range()

    还没查阅源码,先试着练手 class my_range(object): def __init__(self, *args): if not args: raise TypeError, 'range ...

  10. CentOS 5.8 升级php版本

    一:我们都知道系统的yum源安装出来的php版本不是5.1的就是5.3  那就是说 有些程序不支持那么低的版本的呢 那我们该怎么办呢 接下来 简单的说下php的版本升级  编译升级太慢了 这里我们选择 ...