I already had bluez-5.43 installed. This is how to automate the pairing process on a raspberry pi.
(1) First test a line like this out to make sure bluetooth agent works:
bluez-5.43/test/simple-agent -c NoInputNoOutput
(2) To automate pairing, put this code into a shell file (I named mine pairbot.sh):
if [ "$(id -un)" != "pi" ]; then
exec sudo -u pi $0 "$@"
fi
export XAUTHORITY=/home/pi/.Xauthority
export DISPLAY=:0
lxterminal --command="/bin/bash -c '/home/pi/bluez-5.43/test/simple-agent -c NoInputNoOutput &; read'"
(3) Go to crontab:
sudo cronetab -e
(4) At the bottom add:
@reboot sleep 20 && /home/pi/pairbot.sh > /home/pi/blelog.txt 2>&1
(5) Reboot and test if it works.
My recommendation for others facing the same issue would be to look into your bluez folder (or if you don't have one install the latest version of bluez) and search for the folder that says "test" for "simple agent" to locate the file path. From here, you should be able to construct the command line shown above (1). Hopefully it will work for you too.
bluetoothctl
. Then enteragent on
. Then initiate a pairing from either end. The pin should be auto generated/negotiated by the two ends (as per the bluetooth spec).bluetoothctl
will provide the correct pin prompts if a pin is required. If you do need a fixed pin for some reason please describe why you need it and I may be able to provide that if it makes sense to do so.agent NoInputNoOutput
. This will result in "Just Works" pairing where no user interaction is required. So I still don't think you need fixed pins (fixed pins are for legacy paring and is less secure than the new pairing modes).