0

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+). 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.

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. However, I have not found a way to set a fixed 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).

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:

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. 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:

./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:

-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.

Community
  • 1
  • 1
redsalt
  • 1,519
  • 4
  • 20
  • 28
  • That [question](http://stackoverflow.com/questions/30233442/automate-bluetooth-pairing-trusting-in-bluez5) is for simple pairing which is not relevant for you. Instead, you need to modify the `RequestPasskey` function in `simple-agent`. The problem of not being able to run `simple-agent` appears to be a different issue. Have you check the file permissions? – kaylum Jun 10 '16 at 01:40
  • I gave it execute permissions but now it's giving me this error: `-bash: ./simple-agent: /usr/bin/python^M: bad interpreter: No such file or directory`, I checked and python exists in the directory /usr/bin, also, the file simple-agent contains the first file `#!/usr/bin/python` but there is no ^M anywhere, I'm not sure if there is any weird characters or something, I'm using nano to edit the file directly in the raspberry pi. – redsalt Jun 10 '16 at 02:13
  • My bad, apparently the ^M character is part of the Windows new line character, I run dos2unix to remove all those characters and now the file is giving the error `Illegal instruction` again. – redsalt Jun 10 '16 at 02:49

1 Answers1

0

I decided to ask separately about the Illegal instruction issue on StackOverflow:

Python Illegal instruction on Raspberry Pi Zero

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.

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. 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!

Community
  • 1
  • 1
redsalt
  • 1,519
  • 4
  • 20
  • 28