每一个连接请求被视为直接连接请求+安卓BLE直接、被视为、BLE

由网友(男生高冷)分享简介:我们正在写在这里想与我们想要连接外围的持久连接的应用程序BLE。出于同样的目的,我们希望每当我们失去一个现有的连接与外围重新连接。因此,我们的Andr​​oid应用程序为中心仅有试图通过创造新的bluetoothgatt对象以重新调用bluetoothdevice.connectgatt与自动连接为真。但每当我们试图做...

我们正在写在这里想与我们想要连接外围的持久连接的应用程序BLE。出于同样的目的,我们希望每当我们失去一个现有的连接与外围重新连接。因此,我们的Andr​​oid应用程序为中心仅有试图通过创造新的bluetoothgatt对象以重新调用bluetoothdevice.connectgatt与自动连接为真。

但每当我们试图做的,我们重新连接被失败

  21 12-02:47:11.865:D / BluetoothGatt(31963):onClientConnectionState() - 状态= 133 clientIf = 6 DEVICE = ********回调。 

由于我们的连接请求被视为直接连接请求Nexus 5的棒棒糖

BLE5.0蓝牙通信原理及TI BLE协议栈在CC2642上的应用

下面是日志

 十一月12日至3日:46:12.804:D / BluetoothGatt(6902):连接() - 设备:58:EB:14:3D:2A:38,自动:真十一月12日至3日:46:12.804:D / BluetoothGatt(6902):registerApp()十一月12日至3日:46:12.804:D / BluetoothGatt(6902):registerApp() -  UUID = b8f9298b-4a95-41be-80d6-22d82c498c5c十一月12日至3日:46:12.807:D / BtGatt.GattService(31817):registerClient() -  UUID = b8f9298b-4a95-41be-80d6-22d82c498c5c十一月12日至3日:46:12.808:D / BtGatt.GattService(31817):onClientRegistered() -  UUID = b8f9298b-4a95-41be-80d6-22d82c498c5c,clientIf = 6十一月12日至3日:46:12.808:D / BluetoothGatt(6902):onClientRegistered() - 状态= 0 clientIf = 6十一月12日至3日:46:12.808:D / BtGatt.GattService(31817):clientConnect() - 地址= 58:EB:14:3D:2A:38,isDirect =真十一月12日至3日:46:12.809:D / BtGatt.btif(31817):btif_get_device_type:设备[58:EB:14:3D:2A:38] 2型,地址。 0型十一月12日至3日:46:12.811:D / BLEManager(6902):试图创建一个新的连接。 

解决方案

该问题是在这里所描述的竞争状态:的 HTTPS://$c$c.google.com/p/android/issues/detail ID = 69834

一个可能的解决方案,直到他们修复它(他们会?)是使用反射来手动构建一个关贸总协定对象,设置mAutoConnect标志为true,并调用connect。

We are writing a ble application where want to have a persistent connection with the peripheral we want to connect. For the same purpose we want to re-connect with the peripheral whenever we loose a existing connection. So our android application as a central just tries to reconnect by creating new bluetoothgatt object by calling bluetoothdevice.connectgatt with autoconnect as true.

But whenever we try to do that our reconnection gets failed with

12-02 21:47:11.865: D/BluetoothGatt(31963): onClientConnectionState() - status=133 clientIf=6 device=******** callback.

because our connection request is being treated as a direct connection request on nexus 5 lollipop

Here are the logs

12-03 11:46:12.804: D/BluetoothGatt(6902): connect() - device: 58:EB:14:3D:2A:38, auto: true
12-03 11:46:12.804: D/BluetoothGatt(6902): registerApp()
12-03 11:46:12.804: D/BluetoothGatt(6902): registerApp() - UUID=b8f9298b-4a95-41be-80d6-22d82c498c5c
12-03 11:46:12.807: D/BtGatt.GattService(31817): registerClient() - UUID=b8f9298b-4a95-41be-80d6-22d82c498c5c
12-03 11:46:12.808: D/BtGatt.GattService(31817): onClientRegistered() - UUID=b8f9298b-4a95-41be-80d6-22d82c498c5c, clientIf=6
12-03 11:46:12.808: D/BluetoothGatt(6902): onClientRegistered() - status=0 clientIf=6
12-03 11:46:12.808: D/BtGatt.GattService(31817): clientConnect() - address=58:EB:14:3D:2A:38, isDirect=true
12-03 11:46:12.809: D/BtGatt.btif(31817): btif_get_device_type: Device [58:eb:14:3d:2a:38] type 2, addr. type 0
12-03 11:46:12.811: D/BLEManager(6902): Trying to create a new connection.

解决方案

The problem is a race condition described here: https://code.google.com/p/android/issues/detail?id=69834

A possible solution until they fix it (will they?) is to use reflection to manually construct a gatt object, set the mAutoConnect flag to true and call connect.

阅读全文

相关推荐

最新文章