antoinebore
Posts: 53
Joined: Fri Apr 12, 2019 4:01 am

Pairing to bluetooth using a password

Wed Jun 26, 2019 6:47 am

Hi,

I want to connect my device (phone, computer..) to the Raspberry Pi Bluetooth without any access to the Raspberry Pi.

I have seen the solution bellow that automatically accept Bluetooth pairings but it's not safe and anybody can connect to the Raspberry Pi Bluetooth.

https://raspberrypi.stackexchange.com/ ... h-pairings

I was wondering if it's possible to connect a device to the Raspberry Pi using a password/pin code that we define before on the Raspberry Pi. That way, only people who know this password can connect to the Raspberry Pi Bluetooth. I'm not always using the same device to connect to the Bluetooth and setting all my devices as "trusted" is not an option for me.

It doesn't seem possible with bluetoothctl but maybe it's possible with a bash/python script ?

antoinebore
Posts: 53
Joined: Fri Apr 12, 2019 4:01 am

Re: Pairing to bluetooth using a password

Wed Jun 26, 2019 8:07 am

I found this answer which works for me : https://stackoverflow.com/a/52164888


Create a configuration file :

Code: Select all

sudo nano /root/bluetooth.cfg
Edit the file configuration with the mac address and the pin code :
XX:XX:XX:XX:XX:XX 1234
Or if you want a pin to all the devices the same pin code, for example 1234, edit the file like this: * 1234

Then, run the bt-agent with your configuration file

Code: Select all

sudo hciconfig hci0 sspmode 0
sudo bt-agent -c NoInputNoOutput -p /root/bluetooth.cfg

Return to “Beginners”