I followed the steps from jwaters42 (thanks!) and they work for me manually. Now I want to automate the process, but I am having no luck.
Specifically, I am doing the following:
Create directory
/usr/bin/bluez/
Edit /etc/rc.local
Add this line (right before the “exit 0” line).
/usr/bin/bluez/setpin.sh
Create the text file /usr/bin/bluez/setpin.sh
Code:
#!/bin/sh
hciconfig hci0 piscan
hciconfig hci0 sspmode 0
/usr/bin/python /usr/bin/bluez/simple-agent &
Copy these two files into /usr/bin/bluez/
simple-agent
bluezutils.py
These two files are available from downloading and untarring the latest Bluez tar file.
They are both in the test/ directory after you untar.
Copy these two files to the BeagleBone directory /usr/bin/bluez/.
You can make a file executable with these commands:
chmod +x setpin.sh
chmod +x simple-agent
Edit simple-agent
vi /usr/bin/bluez/simple-agent
Comment out contents of AuthorizeService
Code:
def AuthorizeService(self, device, uuid):
# print("AuthorizeService (%s, %s)" % (device, uuid))
# authorize = ask("Authorize connection (yes/no): ")
# if (authorize == "yes"):
# return
# raise Rejected("Connection rejected by user")
Modify
Code:
def RequestPinCode(self, device):
# print("RequestPinCode (%s)" % (device))
set_trusted(device)
# return ask("Enter PIN Code: ")
return "123456"
In main method near the bottom, change capability line to read
Code:
capability = "NoInputNoOutput"
If I start simple-agent manually from a command terminal as follows
/usr/bin/bluez/setpin.sh
and then connect to the Linux beaglebone via Bluetooth from a disconnected laptop, I will be prompted to enter the PIN. I must enter 123456 to match method RequestPinCode. Then the laptop connects. Good!
UNRESOLVED PROBLEM
If I reboot the beaglebone, so that simple-agent is started by /etc/rc.local, which starts /usr/bin/bluez/setpin.sh, then I will NOT be asked to enter a PIN. The laptop just connects. Bad!
Any advice, suggestions, and tips are appreciated.