蓝牙服务器重启后BLE配对出现问题。

huangapple go评论110阅读模式
英文:

Problem with BLE pairing after BLuetooth server is restarted

问题

我在使用低功耗蓝牙(Bluetooth Low Energy)连接两台Android设备之间存在一个带有绑定的问题。在两台设备上都运行着Android 8.0。问题如下:
在我建立两台设备之间的连接后,一切正常,但是在关闭BLE服务器(然后重新打开它)后,我无法从客户端重新连接。目前唯一的方法是从客户端中删除绑定信息。然而,这样做非常不方便。有没有一种方法可以在不手动删除绑定的情况下重新建立连接?例如,通过重置BLE协议中的某个标志或其他方式。此外,我从连接过程中获得了一段简短的输出:

1970-01-04 05:36:10.158 5254-5348/   D/BluetoothGatt: onClientRegistered() - status=0 clientIf=6
1970-01-04 05:36:10.164 5254-5348/   D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=7C:92:B3:23:C0:19
1970-01-04 05:36:10.164 5254-5348/   I/info: ######## 当前BLE状态:0 [已断开连接]
1970-01-04 05:36:10.164 5254-5348/   I/info: ######## 新BLE状态:2 [已连接]
1970-01-04 05:36:10.164 5254-5348/   D/BluetoothGatt: configureMTU() - device: 7C:92:B3:23:C0:19 mtu: 482
1970-01-04 05:36:10.238 5254-5348/   D/BluetoothGattServer: onConnectionUpdated() - 设备=7C:92:B3:23:C0:19 间隔=39 延迟=0 超时=500 状态=42
1970-01-04 05:36:10.239 5254-5268/   D/BluetoothGatt: onConnectionUpdated() - 设备=7C:92:B3:23:C0:19 间隔=39 延迟=0 超时=500 状态=42
1970-01-04 05:36:11.164 5254-5348/   D/BluetoothGatt: onConfigureMTU() - 设备=7C:92:B3:23:C0:19 mtu=482 状态=0
1970-01-04 05:36:11.165 5254-5348/   D/BluetoothGatt: requestConnectionPriority() - 参数:1
1970-01-04 05:36:11.360 5254-5348/   D/BluetoothGattServer: onConnectionUpdated() - 设备=7C:92:B3:23:C0:19 间隔=39 延迟=0 超时=500 状态=0
1970-01-04 05:36:11.361 5254-5268/   D/BluetoothGatt: onConnectionUpdated() - 设备=7C:92:B3:23:C0:19 间隔=39 延迟=0 超时=500 状态=0
1970-01-04 05:36:11.793 5254-5348/   D/BluetoothGatt: onConnectionUpdated() - 设备=7C:92:B3:23:C0:19 间隔=12 延迟=0 超时=2000 状态=0
1970-01-04 05:36:11.793 5254-5268/   D/BluetoothGattServer: onConnectionUpdated() - 设备=7C:92:B3:23:C0:19 间隔=12 延迟=0 超时=2000 状态=0
1970-01-04 05:36:13.353 5254-5348/   D/BluetoothGattServer: onServerConnectionState() - 状态=0 服务器接口=5 设备=7C:92:B3:23:C0:19
1970-01-04 05:36:13.355 5254-5348/   D/BluetoothGatt: onClientConnectionState() - 状态=19 客户端接口=6 设备=7C:92:B3:23:C0:19
1970-01-04 05:36:13.356 5254-5348/   I/info: ######## 当前BLE状态:19 [HID设备]
1970-01-04 05:36:13.356 5254-5348/   I/info: ######## 新BLE状态:0 [已断开连接]
1970-01-04 05:36:13.356 5254-5348/   D/BluetoothGatt: close()

正如您所见,客户端的初始状态是:已断开连接。之后,它尝试连接,但几秒钟后就会断开连接。有任何想法是什么原因吗?

非常感谢!

英文:

I have an issue with the connection(with bonding) between two android devices using the Bluetooth Low Energy. On both devices I'm running Android 8.0. The problem is the following.
When I establish the connection between both devices, everything works fine but after closing the BLE server(and open it again) I am not able to reconnect from the client. The only way so far is deleting the bonding information from the client. However this is not comfortable at all. Is there a way to reestablish the connection without deleting the bonding manually? For example, resetting some flag from the BLE protocol or something. Also, I have a short output from the connection process:

1970-01-04 05:36:10.158 5254-5348/   D/BluetoothGatt: onClientRegistered() - status=0 clientIf=6
1970-01-04 05:36:10.164 5254-5348/   D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=7C:92:B3:23:C0:19
1970-01-04 05:36:10.164 5254-5348/   I/info: ######## CURRENT BLE STATUS: 0 [DISCONNECTED]
1970-01-04 05:36:10.164 5254-5348/   I/info: ######## NEW BLE STATUS: 2 [CONNECTED]
1970-01-04 05:36:10.164 5254-5348/   D/BluetoothGatt: configureMTU() - device: 7C:92:B3:23:C0:19 mtu: 482
1970-01-04 05:36:10.238 5254-5348/   D/BluetoothGattServer: onConnectionUpdated() - Device=7C:92:B3:23:C0:19 interval=39 latency=0 timeout=500 status=42
1970-01-04 05:36:10.239 5254-5268/   D/BluetoothGatt: onConnectionUpdated() - Device=7C:92:B3:23:C0:19 interval=39 latency=0 timeout=500 status=42
1970-01-04 05:36:11.164 5254-5348/   D/BluetoothGatt: onConfigureMTU() - Device=7C:92:B3:23:C0:19 mtu=482 status=0
1970-01-04 05:36:11.165 5254-5348/   D/BluetoothGatt: requestConnectionPriority() - params: 1
1970-01-04 05:36:11.360 5254-5348/   D/BluetoothGattServer: onConnectionUpdated() - Device=7C:92:B3:23:C0:19 interval=39 latency=0 timeout=500 status=0
1970-01-04 05:36:11.361 5254-5268/   D/BluetoothGatt: onConnectionUpdated() - Device=7C:92:B3:23:C0:19 interval=39 latency=0 timeout=500 status=0
1970-01-04 05:36:11.793 5254-5348/   D/BluetoothGatt: onConnectionUpdated() - Device=7C:92:B3:23:C0:19 interval=12 latency=0 timeout=2000 status=0
1970-01-04 05:36:11.793 5254-5268/   D/BluetoothGattServer: onConnectionUpdated() - Device=7C:92:B3:23:C0:19 interval=12 latency=0 timeout=2000 status=0
1970-01-04 05:36:13.353 5254-5348/   D/BluetoothGattServer: onServerConnectionState() - status=0 serverIf=5 device=7C:92:B3:23:C0:19
1970-01-04 05:36:13.355 5254-5348/   D/BluetoothGatt: onClientConnectionState() - status=19 clientIf=6 device=7C:92:B3:23:C0:19
1970-01-04 05:36:13.356 5254-5348/   I/info: ######## CURRENT BLE STATUS: 19 [HID_DEVICE]
1970-01-04 05:36:13.356 5254-5348/   I/info: ######## NEW BLE STATUS: 0 [DISCONNECTED]
1970-01-04 05:36:13.356 5254-5348/   D/BluetoothGatt: close()

As you can see, the initial state of the client is: DISCONNECTED. After that, he tries to connect, but after a few seconds gets disconnected.
Any ideas why?

Thanks a lot!

答案1

得分: 1

我相信这是因为Android设备中的一个可能有一个标志,表明它需要绑定,或者GATT表中的一个特征需要绑定(除非您明确调用了InitiatePairingCreateBond方法)。

您可以通过以下方法解决此问题:要么检查为什么您的Android设备会自动触发绑定(即遍历整个GATT表,找出是否有需要身份验证的特定属性),要么添加一个通过编程方式移除绑定的解决方法。后者可能是更快的方法,我在多个场合看到过这样的做法。请查看下面的链接,了解如何操作:-

我还推荐下面的链接,进一步描述了Android上的配对/绑定操作:-

英文:

I believe that this is happening because either one of the Android devices has a flag that indicates that it requires bonding, or one of the characteristics in the GATT table requires bonding (Unless you are specifically calling the InitiatePairing or CreateBond methods).

You can resolve this issue by either checking why your Android devices are automatically triggering the bonding (i.e. go through the entire GATT table and figuring out if there is a specific attribute that requires authentication), or by adding a workaround that removes the bonding programmatically. The latter would probably be the quicker method and I've seen it being done on multiple occasions. Have a look at the links below to see how this is done:-

I also recommend the links below that describe this and the pairing/bonding operations further on Android:-

huangapple
  • 本文由 发表于 2020年10月15日 20:44:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/64371879.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定