0


BlueZ自动连接蓝牙耳机

问题:调好蓝牙之后,出现了一个客户问题,第一次连接好之后,开关机后没法自动连了。

解决方法:

针对这个情况,实际定位一下问题原因,原来是蓝牙耳机每次连时,都要求授权服务:
Authorize service

[agent] Authorize service 0000110e-0000-1000-8000-00805f9b34fb (yes/no):

在我们非交互界面的情况下,想办法如何自动授权连接蓝牙耳机。

最终在老外的网站,找了一编具体分析,BlueZ代理的文章。

D-Bus API

bluetoothd

exposes D-Bus API to allow external processes to act as Agents and manage pairing mechanisms. BlueZ Agent objects APIs provide methods for:

  1. Creation and registration of an Agent
  2. Setting the Agent capability, that is the kind of pairing mechanism
  3. Setting a previously registered Agent as default
  4. Accepting or rejecting connection requests, based on the policy of the Agent that is used

In particular, Agent's capability indicates how the authentication of two devices during the pairing process must be confirmed. Due to the nature and variety of Bluetooth devices, the value for capability can be:

  1. DisplayOnly or DisplayYesNo : authentication by PIN/passkey code
  2. KeyboardOnly or KeyboardDisplay : yes/no choice to the pairing attempt
  3. NoInputNoOutput : no user confirmation

bluetoothctl有一个内置的agent

  1. Using interactive commands
$ bluetoothctl
Agent registered
[bluetooth]# agent off
Agent unregistered
[bluetooth]# agent NoInputNoOutput
Agent registered
[bluetooth]# default-agent
Default agent request successful
  1. Using Bluetoothctl options
$ bluetoothctl --agent=NoInputNoOutput
Agent registered
[bluetooth]# default-agent
Default agent request successful

bt-agent tool¶

bt-agent is a tool part of the bluez-tools suite. We can set the capability of

bt-agent

with:

$ bt-agent --capability=NoInputNoOutput 

上面3种方法,都可以解决。其中bt-agent最是方便,不用任何交互,启动即可。不影响bluetoothctl的使用。


本文转载自: https://blog.csdn.net/proing/article/details/130751649
版权归原作者 proing 所有, 如有侵权,请联系我们删除。

“BlueZ自动连接蓝牙耳机”的评论:

还没有评论