1

我正在运行sample BluetoothLeGatt app from google,并且无法保持设备连接。我觉得我有点随意的行为。蓝牙通常不会在第一次尝试时连接(所以通常我几乎想说永远不会)。Android BluetoothLEGatt BLE未与设备保持连接

当我按下连接按钮时,约有50%的时间该应用程序表示状态为已连接。但是,硬件设备有一个LED在连接时应亮起,并且不亮。然后5或6秒钟后它断开连接。我怀疑它连接了一秒钟,然后断开连接,应用程序暂时没有得到备忘录。这里是logcat的:

D/BluetoothGatt: connect() - device: 54:4A:16:2F:3C:F6, auto: false 
D/BluetoothGatt: registerApp() 
D/BluetoothGatt: registerApp() - UUID=60edb0ed-90de-4d7d-b4d0-690bcc359fb7 
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=10 
D/BluetoothLeService: Trying to create a new connection. 
D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=10 device=54:4A:16:2F:3C:F6 
I/BluetoothLeService: Connected to GATT server. 
D/BluetoothGatt: discoverServices() - device: 54:4A:16:2F:3C:F6 
I/BluetoothLeService: Attempting to start service discovery:true 
D/BluetoothGatt: onGetService() - Device=54:4A:16:2F:3C:F6 UUID=00001800-0000-1000-8000-00805f9b34fb 
D/BluetoothGatt: onGetService() - Device=54:4A:16:2F:3C:F6 UUID=00001801-0000-1000-8000-00805f9b34fb 
D/BluetoothGatt: onGetService() - Device=54:4A:16:2F:3C:F6 UUID=0000ffe0-0000-1000-8000-00805f9b34fb 
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a00-0000-1000-8000-00805f9b34fb 
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a01-0000-1000-8000-00805f9b34fb 
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a02-0000-1000-8000-00805f9b34fb 
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a03-0000-1000-8000-00805f9b34fb 
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a04-0000-1000-8000-00805f9b34fb 
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a05-0000-1000-8000-00805f9b34fb 
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=0000ffe1-0000-1000-8000-00805f9b34fb 
D/BluetoothGatt: onGetDescriptor() - Device=54:4A:16:2F:3C:F6 UUID=00002902-0000-1000-8000-00805f9b34fb 
D/BluetoothGatt: onGetDescriptor() - Device=54:4A:16:2F:3C:F6 UUID=00002902-0000-1000-8000-00805f9b34fb 
D/BluetoothGatt: onGetDescriptor() - Device=54:4A:16:2F:3C:F6 UUID=00002901-0000-1000-8000-00805f9b34fb 
D/BluetoothGatt: onSearchComplete() = Device=54:4A:16:2F:3C:F6 Status=0 
D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=10 device=54:4A:16:2F:3C:F6 
I/BluetoothLeService: Disconnected from GATT server. 

也许我打的连接按钮,并没有看到任何事情发生的时间10%:

D/BluetoothGatt: connect() - device: 54:4A:16:2F:3C:F6, auto: false 
D/BluetoothGatt: registerApp() 
D/BluetoothGatt: registerApp() - UUID=7dbe26bc-4cee-48d2-9f47-59af4edb33bb 
D/BluetoothGatt: onClientRegistered() - status=133 clientIf=0 
I/BluetoothLeService: Disconnected from GATT server. 
D/BluetoothLeService: Trying to create a new connection. 

和它实际上连接的时间,也许30%。

这可能是硬件/固件问题。虽然我用iPhone连接到设备时没有问题,但我想得出结论,Android代码已经被打破了。我可以发布所有的BLE代码,但我实际上只是下载了样本,以便我知道这并不是我打破的。

编辑:为那些跟踪我的数学。应用程序未找到的最后10%的时间什么它扫描时,我必须重新启动应用程序。

编辑:我已经从Play商店下载并尝试了2个其他BLE应用程序,并获得了与Google样本BLE应用程序相同的连接问题。是否有一些设置,Android的BLE实现需要具有与iOS不同的设置?

+0

嗨,你发现这个问题的根本原因? 我面临同样的问题,但无法获得相同的理由。 –

+0

有一堆东西。我读过很多文章,因为每个硬件制造商都使用不同的BLE芯片,所以很难有可靠的通用android BLE sdk。另一个问题是我们的芯片没有校准到正确的波特率。我猜测软件时钟有10%的变化导致我们丢包。 (我认为这是正确的 - 我不是硬件人) –

+0

https://atmosphere.anaren.com/wiki/Android_Issues_With_Bluetooth_Low_Energy –

回答

0

尝试使用: BluetoothDevice.connectGatt(上下文上下文中,布尔AUTOCONNECT,BluetoothGattCallback回调,INT传输)

与TRANSPORT_LE运输。

这对我来说诀窍。