iOS 和 Android 蓝牙低功耗连接之间的区别
Posted
技术标签:
【中文标题】iOS 和 Android 蓝牙低功耗连接之间的区别【英文标题】:Difference between iOS and Android Bluetooth Low Energy connection 【发布时间】:2016-07-21 18:27:49 【问题描述】:我有一个 BLE 外围设备。我无法使用 BluetoothLeGatt 示例 android 应用程序和 Android Market 中的其他 BLE 应用程序连接到它。但 ios BLE 应用程序可以连接到它。这是 BluetoothLeGatt 连接日志:
07-21 21:06:37.506 27402-27420/bluetoothlegatt D/BluetoothLeScanner: onScanResult() - ScanResultmDevice=xx:xx:xx:xx:xx:xx, mScanRecord=ScanRecord [mAdvertiseFlags=2, mServiceUuids=null, mManufacturerSpecificData=, mServiceData=, mTxPowerLevel=-2147483648, mDeviceName=TestBLE], mRssi=-82, mTimestampNanos=12459248011929
07-21 21:06:37.506 27402-27402/bluetoothlegatt D/BluetoothDevice: mAddress: xx:xx:xx:xx:xx:xx
07-21 21:06:37.516 27402-27402/bluetoothlegatt D/BluetoothDevice: mAddress: xx:xx:xx:xx:xx:xx
07-21 21:06:40.930 27402-27402/bluetoothlegatt D/BluetoothAdapter: stopLeScan()
07-21 21:07:50.754 27402-27402/bluetoothlegatt D/BluetoothDevice: mAddress: xx:xx:xx:xx:xx:xx
07-21 21:07:50.764 27402-27402/bluetoothlegatt D/BluetoothAdapter: stopLeScan()
07-21 21:07:50.764 27402-27402/bluetoothlegatt D/BluetoothAdapter: scan not started yet
07-21 21:07:50.924 27402-27402/bluetoothlegatt D/BluetoothDevice: mAddress: xx:xx:xx:xx:xx:xx
07-21 21:07:50.924 27402-27402/bluetoothlegatt D/BluetoothGatt: connect() - device: xx:xx:xx:xx:xx:xx, auto: false
07-21 21:07:50.924 27402-27402/bluetoothlegatt D/BluetoothGatt: registerApp()
07-21 21:07:50.924 27402-27402/bluetoothlegatt D/BluetoothGatt: registerApp() - UUID=xxxxxxxx-xxxx-xxxxxxxxx-xxxxxxxxxxxx
07-21 21:07:50.924 27402-27420/bluetoothlegatt D/BluetoothGatt: onClientRegistered() - status=0 clientIf=5
07-21 21:07:50.924 27402-27420/bluetoothlegatt D/BluetoothDevice: mAddress: xx:xx:xx:xx:xx:xx
07-21 21:07:50.934 27402-27402/bluetoothlegatt D/BluetoothLeService: Trying to create a new connection.
07-21 21:07:56.060 27402-27421/bluetoothlegatt D/BluetoothGatt: onClientConnectionState() - status=133 clientIf=5 device=xx:xx:xx:xx:xx:xx
07-21 21:07:56.060 27402-27421/bluetoothlegatt D/BluetoothDevice: mAddress: xx:xx:xx:xx:xx:xx
07-21 21:07:56.060 27402-27421/bluetoothlegatt I/BluetoothLeService: Disconnected from GATT server.
我应该怎么做才能连接到这个设备? Android 和 iOS BLE 连接到 BLE 外围设备有什么区别?
更新: 我的 Android 设备:
HTC One M7。安卓版本:5.0.2
LG Nexus 5X。安卓版本:6.0.1
【问题讨论】:
【参考方案1】:07-21 21:07:50.934 27402-27402/bluetoothlegatt D/BluetoothLeService: Trying to create a new connection.
07-21 21:07:56.060 27402-27421/bluetoothlegatt D/BluetoothGatt: onClientConnectionState() - status=133 clientIf=5 device=xx:xx:xx:xx:xx:xx
07-21 21:07:56.060 27402-27421/bluetoothlegatt D/BluetoothDevice: mAddress: xx:xx:xx:xx:xx:xx
07-21 21:07:56.060 27402-27421/bluetoothlegatt I/BluetoothLeService: Disconnected from GATT server.
发送连接请求后,直到onClientConnectionState,大约有5秒的分页时间,我假设可能是分页超时。
查询很少: 1)这个问题是否也出现在其他Android手机或仅您的测试手机上? 2)你的设备的广告间隔是多少?
奇怪的是可以搜索到设备却无法连接;或者它应该是您的手机和您的设备之间的射频问题。
【讨论】:
我更新了我的帖子。这个问题发生在我的 HTC One M7 和 Android 5.0.2 和 LG Nexus 5X 和 Android 6.0.1。广告间隔 100 - 200 毫秒。 Android 设备在 3 -5 秒延迟后出现连接错误。 iOS 设备立即连接到 BLE 设备。【参考方案2】:看起来我找到了答案。 我们使用 CC2564 德州仪器芯片。使用 BluetoothLeGatt Android 示例应用程序与此芯片的 BLE 连接需要替换此命令:
mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
到这个命令:
mBluetoothGatt = device.connectGatt(this, false, mGattCallback,BluetoothDevice.TRANSPORT_LE);
【讨论】:
以上是关于iOS 和 Android 蓝牙低功耗连接之间的区别的主要内容,如果未能解决你的问题,请参考以下文章
Android BLE低功耗蓝牙开发极简系列(二)之读写操作