User avatar
BirchJD
Posts: 162
Joined: Tue Nov 13, 2012 7:43 pm

Pairing Bluetooth Devices From A Raspberry Pi Command Prompt

Thu May 24, 2018 6:48 pm

I have made a video on how to pair Bluetooth devices on the Raspberry Pi from a command prompt. Useful if you are using the Raspbian Lite distribution.

The video can be viewed here:
https://www.youtube.com/watch?v=lHwvoFLbAkM
http://www.newsdownload.co.uk/

User avatar
B.Goode
Posts: 14130
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Pairing Bluetooth Devices From A Raspberry Pi Command Prompt

Thu May 24, 2018 8:58 pm

And for people like me who prefer the economy of a few lines of text, Martin O'Hanlon has documented the steps needed as part of the documentation for his Blue Dot library -

http://bluedot.readthedocs.io/en/latest ... mmand-line

n67
Posts: 938
Joined: Mon Oct 30, 2017 4:55 pm

Re: Pairing Bluetooth Devices From A Raspberry Pi Command Prompt

Thu May 24, 2018 9:44 pm

I do agree that doing this via YouTube was a bit excessive.

I would have liked if OP had includes the "few lines of text" description in the OP, along with the YouTube URL.

Then all would be happy.

Meta note: If I were more ambitious, I would expend the effort necessary to deduce the "few lines of text" version and post it here. Alas, I am not.
"L'enfer, c'est les autres"

G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:

Epmu Sn!

J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!

User avatar
BirchJD
Posts: 162
Joined: Tue Nov 13, 2012 7:43 pm

Re: Pairing Bluetooth Devices From A Raspberry Pi Command Prompt

Fri May 25, 2018 4:04 am

The video was in relation to my OBDII project to read data from a car ECU via it's OBDII connector. I found people new to Raspberry Pi were having difficulty pairing Bluetooth devices. So I did a video they could follow to the letter, alas not all people have your technical background. However, below are the commands summarised as requested, which can also be found in the readme file of the Open Source Python script which can be found here:
https://github.com/BirchJD/PiOBDII


BLUETOOTH DONGLE (Perform operations here as root user)

EXAMPLE CONNECTING TO A BLUETOOTH ELM327 DONGLE FROM LINUX COMMAND LINE
OR THE BUILT IN RASPBERRY PI 3 BLUETOOTH DEVICE:


Bluetooth service

# Get the status of the Bluetooth service.
service bluetooth status

# If the Bluetooth service is not running, start it.
service bluetooth start

# Stop the Bluetooth service only if required.
service bluetooth stop


Pairing a Bluetooth device

# Once a device is paired it should automatically pair in future.

# Start the Bluetooth utility.
bluetoothctl

# Make sure the Bluetooth device is powered on.
power on

# Make sure an agent is running for the Bluetooth device.
agent on

# Start a scan for other Bluetooth devices in the area.
scan on

# Wait for the required Bluetooth device to be reported...

# Stop scanning when the required Bluetooth device is found.
scan off

# Attempt to pair the required Bluetooth device.
pair <dev>

e.g. <dev>=00:1D:A5:F7:FF:0D

# Pairing normally prompts for a password. Standard Bluetooth pairing passwords
# are: 0000 or 1234, try these if you are unsure of the password.

# If pairing fails or propt for password does not appear, try the following, and
# then try paring again.
agent off
power off
power on
agent on

# Once paired it should appear in the list of paired devices.
paired-devices

# You can now leave the Bluetooth utility and the device should be paired and
# ready for use.
quit


Creating a serial device for use in the OBDII application

# rfcomm associates the paired device ID with a serial device name.
rfcomm bind 0 <dev>

# The device it should create is:
/dev/rfcomm0

# To remove the serial device do the following if required.
rfcomm release <dev>

### Shouldn't need this command, force rfdevices to stop.
### rfkill list


Unpairing a Bluetooth device

# Start the Bluetooth utility.
bluetoothctl

# Unpair the Bluetooth device if required.
remove <dev>

# Make sure the agent is stopped for the Bluetooth device.
agent off

# Make sure the Bluetooth device is powered down.
power off

# Exit the Bluetooth utility.
quit
http://www.newsdownload.co.uk/

Roggerson
Posts: 1
Joined: Tue Dec 18, 2018 8:10 pm

Re: Pairing Bluetooth Devices From A Raspberry Pi Command Prompt

Tue Dec 18, 2018 8:17 pm

Hey,

I decided to come back to this post and make an account so I could give back to the community, since this was one of the posts / threads that helped me with my project.

if anybody is interested in automating the whole bluetooth process, you can check out my github project
https://github.com/Roggerson

So far I wrote bash scripts for scanning, pairing, connecting, disconnecting, remove-paired devices....
and built a little gui for basic audio control (js,php,html,..)

If you are interested, you can contact me however you like

Kind regards,
Michael

User avatar
BirchJD
Posts: 162
Joined: Tue Nov 13, 2012 7:43 pm

Re: Pairing Bluetooth Devices From A Raspberry Pi Command Prompt

Thu Dec 20, 2018 12:20 pm

Good project, thank you for automating the process into a nice application.
http://www.newsdownload.co.uk/

Return to “Interfacing (DSI, CSI, I2C, etc.)”