Quantcast
Viewing latest article 41
Browse Latest Browse All 44

Answer by Mohammad Ali for Automatically accepting Bluetooth connections on a Pi 3

(Note that this answer is no longer working as of Raspbian Jessie, since bluez removed the bluetooth-agent command)

So currently you state that you can connect to the Pi just fine, but require a monitor for the pairing process.

Note: accepting any connection is an incredibly insecure idea, and if you are only using a limited set of devices, setting them up as trusted devices would make a lot more sense as it would limit connection to your Mac addresses but wold not allow for new devices to be added without a monitor

But anyway, the commands that you will need to run to accept all connections being made to the Pi, to make it discoverable and to set a predictable pin are listed below:

Note: you may need to change the zero in hci0 to your devices Bluetooth number.

hciconfig hci0 uphciconfig hci0 sspmode 1hciconfig hci0 piscansudo bluetooth-agent 1234

Now after running these commands and seeing if they work as expected we can move on to setting them up to start on the boot of your Pi.

  1. We start by creating a bash file by running the command sudo nano mohammadIsAmazing.sh
  2. We now enter the following into that file:

    #!/bin/shsleep 20hciconfig hci0 uphciconfig hci0 sspmode 1hciconfig hci0 piscansudo bluetooth-agent 1234
  3. Now we save and close our file using the control key and x

  4. We open up the file /etc/rc.local using the following command:

    Sudo nano /etc/rc.local
  5. Now we enter the command to run our bash script into /etc/rc.local

    sudo /path/to/script/mohammadIsAmazing.sh &

    Note: you have to put the command before the last line in /etc/rc.local that contains: exit 0

  6. We now save and close that file, then reboot the Pi.

On a side note: be sure to chose a random pin to marginally increase security

On another side note: If you would like to change the bluetooth device name, you need to create a file called /etc/machine-info which should contain the following:

PRETTY_HOSTNAME=device-name

Then run service bluetooth restart after that


Viewing latest article 41
Browse Latest Browse All 44

Trending Articles