简体   繁体   English

使用无头蓝牙2.0加密狗与Raspberry Pi Zero配对

[英]Pair with Raspberry Pi Zero using Bluetooth 2.0 dongle headless

I have a Raspberry Pi Zero with a Bluetooth 2.0 dongle in the USB port, since it's Bluetooth 2.0 I can't use Simple Pairing Mode (only available on Bluetooth 2.1+). 我有一个Raspberry Pi Zero,其USB端口带有一个蓝牙2.0加密狗,因为它是蓝牙2.0,所以我无法使用简单配对模式(仅适用于蓝牙2.1+)。 I'd like to pair my computer with the Raspberry Pi but the computer asks me for a PIN and I don't want to have to interact with the Raspberry. 我想将我的计算机与Raspberry Pi配对,但是计算机要求我提供PIN,并且我不想与Raspberry进行交互。

Since Simple Pairing Mode is not available I thought of using a fixed PIN (like 0000) so that when the computer asks for a PIN I can input 0000 and it will pair the devices. 由于“简单配对模式”不可用,我想到了使用固定的PIN(例如0000),以便当计算机要求输入PIN时,我可以输入0000,它将与设备配对。 However, I have not found a way to set a fixed PIN. 但是,我还没有找到设置固定PIN的方法。

I've searched on the Internet but I could only found solutions for Bluetooth 2.1+ or using Bluez4 (I'm using Bluez 5.23-2+rpi2). 我已经在Internet上进行了搜索,但只能找到适用于Bluetooth 2.1+或使用Bluez4的解决方案(我使用的是Bluez 5.23-2 + rpi2)。

I've tried downloading simple-agent editing RequestPinCode to return "0000" as I've read somewhere that it would work, but then I run the code with: 我尝试下载简单代理编辑RequestPinCode以返回“ 0000”,因为我在某个地方可以正常工作,但是随后我使用以下代码运行代码:

python agent.py

And I get an error: 我得到一个错误:

Illegal instruction

I also tried with: 我也尝试过:

sudo python agent.py

In this case I don't get an error, I get no output whatsoever, the program just exists. 在这种情况下,我没有收到错误,也没有任何输出,程序只是存在。

I'm not sure how simple-agent works but I'm pretty sure it's supposed to wait on an infinite loop. 我不确定简单代理的工作方式,但是我很确定它应该在无限循环中等待。

I don't know what I'm doing wrong. 我不知道我在做什么错。 All I want is to set a fixed PIN (0000) for the Raspberry PI so that I can introduce that PIN every time a new device wants to connect to the Raspberry PI via Bluetooth. 我只想为Raspberry PI设置一个固定的PIN(0000),以便每次新设备想要通过蓝牙连接到Raspberry PI时都可以引入该PIN。 I don't really care how it's done as long as it works. 只要它有效,我都不在乎它是如何完成的。

UPDATE #1: I've tried the answer in this question so I guess I was executing the script the wrong way, so I tried this: 更新#1:我已经尝试过此问题的答案,所以我想我以错误的方式执行了脚本,所以我尝试了以下方法:

./simple-agent -c NoInputNoOutput

Just like the answer said but it gives an error: 就像答案说的一样,但它给出了一个错误:

-bash: ./simple-agent: Permission denied

I tried with: 我尝试过:

sudo ./simple-agent -c NoInputNoOutput

But then it says: 但是然后它说:

sudo: ./simple-agent: command not found

UPDATE #2: After giving executing permissions to the simple-agent file I'm getting this error now: 更新#2:在授予简单代理文件执行权限之后,我现在得到此错误:

-bash: ./simple-agent: /usr/bin/python^M: bad interpreter: No such file or directory
Actually, the ^M character is just a Windows character, I ran dos2unix and now the file should have no weird characters, I tested it again and it gives me the same errors as before (Illegal instruction) even after giving it executing permissions. 实际上,^ M字符只是Windows字符,我运行了dos2unix,现在文件应该没有奇怪的字符,我再次对其进行了测试,即使在授予执行权限后,它也像以前一样出现了错误(非法指令)。

I decided to ask separately about the Illegal instruction issue on StackOverflow: 我决定单独询问关于StackOverflow的Illegal instruction问题:

Python Illegal instruction on Raspberry Pi Zero Raspberry Pi Zero上的Python非法指令

So I solved that error, it was caused by packages installed that were compiled for a different architecture so I reinstalled everything with apt-get and now the script works. 因此,我解决了该错误,这是由为不同体系结构编译的软件包导致的,因此我使用apt-get重新安装了所有内容,现在脚本可以正常工作了。

The next thing to do is make sure I can pair the devices with the PIN 0000 which is the main reason I created this question. 接下来要做的是确保我可以将设备与PIN 0000配对,这是我创建此问题的主要原因。 So I ran the script then I tried to pair it with my computer and it asked for a PIN, I introduced 0000 and it worked! 因此,我运行了脚本,然后尝试将其与计算机配对,并要求输入PIN,我输入了0000,然后它起作用了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM