1

I have a raspberry pi 3 (raspbian jessie), which I can currently pair with my phone if I scan and initiate the pairing on the pi with bluetoothctl. I have two primary problems:

  • The device does not show up on the list of bluetooth devices on the phone
  • Pairing currently requires human interaction with the pi

The first problem is likely to do with what I'm advertising, I've been messing around with setting up the packet with hcitool and have dealt with iOS bluetooth specs in the past.

The second is what I'm stuck on. Ideally, I would enter a static PIN on the phone and connect like that. However, I heard that method was outdated, and bluetooth-agent MY_PIN didn't work (command not found). I don't want to turn off pairing authentication because it means all the random people living around me could connect to it.

Is there a better method I can use? If not, I'm looking for some direction on how to get the PIN authentication to work.

3

I have had the same problem for a while now (5 months), and I stumbled upon this page yesterday

The first few comments will show you how to implement a PIN code for the bluetooth on the Pi. It worked for me once I had installed this (I installed this before changing some files to implement the PIN code.

Basically the procedure is the following :

in /etc/apt/sources.list, uncomment the line beginning with "deb-src" After that, do a sudo apt-get update and a cd /usr/src; sudo apt-get source bluez


In the file /usr/src/bluez-5.23/test/simple-agent change this part : return ask("Enter PIN Code: ")
Into the following return "1234" where 1234 is the pin code you want to use.
After that you create the following script in /usr/bin, let's call it btscript.sh :

#!/bin/sh
result=`ps aux | grep -i "simple-agent" | grep -v "grep" | wc -l`
if [ $result -ge 0 ]; then
    sudo hciconfig hci0 piscan
    sudo hciconfig hci0 sspmode 0
    sudo /usr/bin/python /usr/src/bluez-5.23/test/simple-agent &
else
    echo "BT Agent already started" 
fi

Make this script executable with a sudo chmod +x
Add this line before exit 0 in the file /etc/rc.local :
/usr/bin/btscript.sh

After that, reboot your machine : sudo reboot

You should be able to connect to your Pi using a PIN code.

Although, as mentionned here, you will be able to see your Pi with an iOS device, but only once, so do not make your device forget your Pi, otherwise you will not be able to connect to it anymore.

To counter that, create a script called for example bt_iphone.sh, and put that code in it :

#!/bin/sh
sudo hciconfig hci0 sspmode 1 # Activate SSP which is the current standard
# for bluetooth pairing, this will make the RPi discoverable again but
# with a passkey instead of a PIN code
echo -e 'power off\n quit ' | bluetoothctl # Make the RPi undiscoverable
sleep 5
echo -e 'power on\n quit ' | bluetoothctl # Make the RPi discoverable again
sleep 1
sudo hciconfig hci0 sspmode 0 # Deactivate SSP and activate PIN code authentication
exit 0

Make it executable with sudo chmod +x bt_iphone.sh & execute this script every minute with a crontab : crontab -e and at the end of the file : * * * * * sudo bash /path/to/bt_iphone.sh

This is not elegant but it seems to work. If anyone has a better solution for this last problem, I'm open to suggestions.

A problem still persists (again with iDevices only), there is a timeout on the PIN code, which makes it impossible to connect if you have not typed and confirmed the PIN code within 3 seconds of the display of the PIN code screen. I have not found any workaround for this yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.