无需重新配对,能否更新蓝牙设备的服务信息?
无需重新配对更新蓝牙设备可用服务的方法?
设备配对后,在本地执行bluetoothctl info可查看远程设备的可用UUID列表:
root@device:~# bluetoothctl info Device A4:6B:B6:EB:3D:08 (public) Alias: A4-6B-B6-EB-3D-08 Class: 0x002a010c Icon: computer Paired: yes Trusted: yes Blocked: no Connected: yes LegacyPairing: no UUID: Service Discovery Serve.. (00001000-0000-1000-8000-00805f9b34fb) UUID: Audio Source (0000110a-0000-1000-8000-00805f9b34fb) UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb) UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb) UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb) UUID: PANU (00001115-0000-1000-8000-00805f9b34fb) UUID: Handsfree (0000111e-0000-1000-8000-00805f9b34fb) UUID: Handsfree Audio Gateway (0000111f-0000-1000-8000-00805f9b34fb) UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb) UUID: Vendor specific (c7f94713-891e-496a-a0e7-983a0946126e)
若后续在远程设备启动新服务,该列表不会自动更新,执行bluetoothctl info仍显示缓存信息,不会主动发现变更。目前仅通过重新配对能更新列表(此时可看到新增的Serial Port服务):
root@device:~# bluetoothctl info Device A4:6B:B6:EB:3D:08 (public) Alias: A4-6B-B6-EB-3D-08 Class: 0x002a010c Icon: computer Paired: yes Trusted: yes Blocked: no Connected: yes LegacyPairing: no UUID: Service Discovery Serve.. (00001000-0000-1000-8000-00805f9b34fb) UUID: Serial Port (00001101-0000-1000-8000-00805f9b34fb) UUID: Audio Source (0000110a-0000-1000-8000-00805f9b34fb) UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb) UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb) UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb) UUID: PANU (00001115-0000-1000-8000-00805f9b34fb) UUID: Handsfree (0000111e-0000-1000-8000-00805f9b34fb) UUID: Handsfree Audio Gateway (0000111f-0000-1000-8000-00805f9b34fb) UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb) UUID: Vendor specific (c7f94713-891e-496a-a0e7-983a0946126e)
是否存在无需重新配对即可更新远程设备可用服务的方法?不想再次验证PIN码等操作。
可行解决方案
1. 断开重连+重新扫描
- 先断开设备连接:
bluetoothctl disconnect A4:6B:B6:EB:3D:08 - 开启扫描重新发现设备:
等待几秒扫描完成后,关闭扫描并重新连接:bluetoothctl scan on
再次执行bluetoothctl scan off bluetoothctl connect A4:6B:B6:EB:3D:08bluetoothctl info即可看到更新后的服务UUID列表。
2. 通过D-Bus接口直接触发服务发现
无需断开连接,直接调用BlueZ的D-Bus接口刷新服务信息:
dbus-send --system --dest=org.bluez --print-reply /org/bluez/hci0/dev_A4_6B_B6_EB_3D_08 org.bluez.Device1.DiscoverServices
执行完成后,运行bluetoothctl info就能获取最新的服务列表。
3. 清除设备缓存(无需重新配对)
- 停止蓝牙服务:
systemctl stop bluetooth - 删除对应设备的缓存文件(路径中
XX:XX:XX:XX:XX:XX替换为本地蓝牙适配器的MAC地址):rm -rf /var/lib/bluetooth/XX:XX:XX:XX:XX:XX/A4:6B:B6:EB:3D:08 - 重启蓝牙服务并重新连接:
这种方式会重新拉取设备的服务信息,且不需要重新配对验证。systemctl start bluetooth bluetoothctl connect A4:6B:B6:EB:3D:08
内容的提问来源于stack exchange,提问作者Daniel Viaño
相关产品推荐
相关产品推荐

