自动蓝牙配对/信任Bluez5 [英] Automate Bluetooth Pairing/Trusting in Bluez5

查看:2768
本文介绍了自动蓝牙配对/信任Bluez5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在做我的RPI 2功能,如汽车蓝牙接收器,一切都很好,除了我不知道我如何能够自动配对蓝牙设备在Bluez5。过去我会使用蓝牙代理和一个简单的脚本,但是似乎已经从4 - > 5移出了窗口。设置的本质意味着我的RPi上没有kb /鼠标一次它在汽车中,所以它需要一个完全自动的设置,任何人都可以扫描RPi,如果可能硬编码的PIN是正确的,设备的信任需要自动完成,没有cli输入。 p>

我已经搜索了整个网络,但每个人都似乎说使用bluetoothctl为他们工作,但在这个特定的设置,我想要能够有朋友对他们自己的手机,不得不相信设备与RPi出车不是理想的。

解决方案

我不知道为什么你说使用一个简单的脚本是不可能的bluez5。我想你可以做到下面是一个例子。



下载bluez5源码并编辑 test / simple-agent 。注释掉代码行,如下所示:

  def RequestAuthorization(self,device):
print(RequestAuthorization (%s)%(device))
#auth = ask(授权?(是/否):)
#if(auth ==yes):
return
#raise被拒绝(配对拒绝)

授权并且始终接受配对请求。



现在可以启动具有NoInputNoOutput功能的简单代理,以便它使用简单配对,并将通过上述代码路径: / p>

./ simple-agent -c NoInputNoOutput



之后,您应该能够与RPi配对,无需任何用户提示或PIN。



请注意,这只是您可以做的一个例子。如果你想要使用硬编码的PIN码而不是简单的配对,那么请编辑相同的 simple-agent 代码的相应部分。我会把它作为一个练习。


I've been working on making my RPi 2 function like a car bluetooth receiver and all is well, except I have no idea how I could automate the pairing of bluetooth devices in Bluez5. In the past I would've used the bluetooth agent and a simple script, but that seems to have gone out the window with the move from 4 -> 5. The nature of the setup means I have no kb/mouse on the RPi once its in the car, so it needs to be a fully automated setup where anyone can scan for the RPi, and if the probably hard-coded PIN is correct, the trusting of the device needs to be automatically done, no cli input.

I've searched all over the web but everyone seems to say that using bluetoothctl works for them, but in this particular setup where I'd like to be able to have friends pair their own phones, having to trust devices with the RPi out of the car isn't ideal.

解决方案

I'm not sure why you say using a simple script is not possible with bluez5. I think you can do it. Below is one example how.

Download the bluez5 source and edit test/simple-agent. Comment out the lines of code as shown below:

def RequestAuthorization(self, device):
        print("RequestAuthorization (%s)" % (device))
        #auth = ask("Authorize? (yes/no): ")
        #if (auth == "yes"):
        return
        #raise Rejected("Pairing rejected")

What that does it remove the prompt for authorisation and always accepts the pairing request.

Can now start the simple-agent with the NoInputNoOutput capability so that it uses simple pairing and will go through the above code path:

./simple-agent -c NoInputNoOutput

After that you should be able to pair with the RPi without any user prompt or PIN.

Note that this is just one example of what you can do. If say you wanted to have a hard coded PIN instead of simple pairing then edit the appropriate section of the same simple-agent code to do that. I'll leave that as an exercise for you.

这篇关于自动蓝牙配对/信任Bluez5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆