iOS 和 Android 蓝牙低功耗连接之间的区别
Difference between iOS and Android Bluetooth Low Energy connection
我有一个BLE周边设备。我无法使用 BluetoothLeGatt 示例 android 应用程序连接到它,Android 市场中没有其他 BLE 应用程序。但是 iOS BLE 应用程序可以连接到它。这是 BluetoothLeGatt 连接日志:
07-21 21:06:37.506 27402-27420/bluetoothlegatt D/BluetoothLeScanner: onScanResult() - ScanResult{mDevice=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。 Android版本:5.0.2
LG Nexus 5X。 Android 版本:6.0.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 phone 或只有你的测试 phone?
2)您设备的广告间隔是多少?
奇怪,搜索到设备却无法连接;或者它应该是您的 phone 和您的设备之间的 RF 问题。
看来我找到了答案。
我们使用 CC2564 德州仪器芯片。对于使用 BluetoothLeGatt Android 与此芯片的 BLE 连接,示例应用程序需要替换此命令:
mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
此命令:
mBluetoothGatt = device.connectGatt(this, false, mGattCallback,BluetoothDevice.TRANSPORT_LE);
我有一个BLE周边设备。我无法使用 BluetoothLeGatt 示例 android 应用程序连接到它,Android 市场中没有其他 BLE 应用程序。但是 iOS BLE 应用程序可以连接到它。这是 BluetoothLeGatt 连接日志:
07-21 21:06:37.506 27402-27420/bluetoothlegatt D/BluetoothLeScanner: onScanResult() - ScanResult{mDevice=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。 Android版本:5.0.2
LG Nexus 5X。 Android 版本:6.0.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 phone 或只有你的测试 phone? 2)您设备的广告间隔是多少?
奇怪,搜索到设备却无法连接;或者它应该是您的 phone 和您的设备之间的 RF 问题。
看来我找到了答案。 我们使用 CC2564 德州仪器芯片。对于使用 BluetoothLeGatt Android 与此芯片的 BLE 连接,示例应用程序需要替换此命令:
mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
此命令:
mBluetoothGatt = device.connectGatt(this, false, mGattCallback,BluetoothDevice.TRANSPORT_LE);