Pairing Stubborn Bluetooth Devices in Fedora 10 & Ubuntu Ibex
If you’re having problems pairing Bluetooth devices with the latest BlueZ 4 GNOME software (bluez-gnome-1.8) try this script. This script offers a work-around for the problem of pairing Bluetooth audio devices like Sony’s SRS-BT100 with the latest BlueZ GNOME wizard. The following script forces the BlueZ 4 audio service to request a pincode from the user for a particular device. In the case of SRS-BT100, the pincode is hardcoded as ‘0000′. So just enter your device’s pincode when prompted by the GNOME Bluetooth applet and then start playing your favorite audio files. Note: this script adds an ALSA virtual device named ‘bt_audio’ to the user’s .asoundrc ALSA configuration file.
For more information on BlueZ, please consult www.bluez.org and wiki.bluez.org.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | #!/bin/bash # # Copyright (c) 2008 Technetra Corp # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation # files (the "Software"), to deal in the Software without # restriction, including without limitation the rights to use, # copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following # conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. # echo "Please place your Bluetooth audio device into pairing mode, then press <Enter>" read echo "Scanning for Bluetooth audio device..." scan=`hcitool scan | sed 's/^\s*//' | grep -v 'Scanning'` line=$scan if [[ "`echo "$scan" | wc -l`" -gt "1" ]]; then echo "select device:" save_ifs=$IFS IFS=" " select line in $scan; do #echo got $line break done IFS=$save_ifs fi BT_BDADDR=`echo $line | awk '{print $1}'` [[ -z "$BT_BDADDR" ]] && echo no bluetooth device found && exit echo "Selected bluetooth device: $BT_BDADDR" # => e.g., 00:11:22:33:44:55 echo "Writing new ~.asoundrc..." cat >> ~/.asoundrc <<EOD pcm.bt_audioraw { type bluetooth device $BT_BDADDR profile "auto" } pcm.bt_audio { type plug slave.pcm "bt_audioraw" hint { show on description "Bluetooth audio device" } } EOD echo "Getting default adapter..." _BT_ADAPTER=`dbus-send --system --print-reply --dest=org.bluez / \ org.bluez.Manager.DefaultAdapter|awk '/object path/ {print $3}'` BT_ADAPTER=${_BT_ADAPTER//\"/} echo "$BT_ADAPTER" echo "Removing any stale Bluetooth audio device:" _OLD_BT_DEVICE=`dbus-send --system --print-reply --dest=org.bluez $BT_ADAPTER \ org.bluez.Adapter.FindDevice string:$BT_BDADDR|awk '/object path/ {print $3}'` OLD_BT_DEVICE=${_OLD_BT_DEVICE//\"/} dbus-send --system --print-reply --dest=org.bluez $BT_ADAPTER \ org.bluez.Adapter.RemoveDevice objpath:$OLD_BT_DEVICE echo "Creating Bluetooth audio device:" _BT_DEVICE=`dbus-send --system --print-reply --dest=org.bluez $BT_ADAPTER \ org.bluez.Adapter.CreateDevice string:$BT_BDADDR|awk '/object path/ {print $3}'` BT_DEVICE=${_BT_DEVICE//\"/} echo "$BT_DEVICE" # optional: echo "Connecting -- BlueZ applet will prompt for pin..." # optional: dbus-send --system --print-reply --dest=org.bluez \ # optional: $BT_DEVICE org.bluez.AudioSink.Connect # # NOTE: if the above dbus-send is NOT executed, then a pairing # request for an A2DP device will be initiated the first time # the ALSA virtual device bt_audio is used. Otherwise, when # "AudioSink.Connect" is executed, a pairing request to the device # will be initiated immediately and then ALSA will subsequently use # this paired connection for playing sound through bt_audio. Executing # "AudioSink.Connect" is useful for preparing devices ahead of time # to avoid undesired delays and to avoid pairing mode timeouts. # # Also note that a device conforming to the headset profile (HSP) # does not support "AudioSink.Connect". However, this script (without # running "AudioSink.Connect") will still work because BlueZ will # request pairing when "Adapter.CreateDevice" is executed for HSP # devices. You can check out your device's specific capabilities # using sdptool. #echo "Test sound sample..." #aplay -D bt_audio your_sound_file.wav |
Copyright © 2008 Technetra. This code is covered by the MIT License. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pings are currently closed.

December 9th, 2008 at 10:53 am (Comment)
Bjoern Says:
How do I load or execute this script? I am a Linux Newbie
December 9th, 2008 at 6:05 pm (Comment)
codeguru Says:
Hi Bjoern,
Copy and paste the code into a file (e.g., bt.sh) using your favorite text editor. Then, run bt.sh on the command line by typing in ‘bash bt.sh’
December 11th, 2008 at 4:37 am (Comment)
luke Says:
i would love some help with this.. i ran the above script and get the following:
[luke@FEDORA10PC ~]$ bash btsh
Please place your Bluetooth audio device into pairing mode, then press
Scanning for Bluetooth audio device…
Selected bluetooth device: 00:03:89:48:D7:02
Writing new ~.asoundrc…
Getting default adapter…
/org/bluez/hci0
Removing any stale Bluetooth audio device:
method return sender=:1.11 -> dest=:1.74 reply_serial=2
Creating Bluetooth audio device:
/org/bluez/hci0/dev_00_03_89_48_D7_02
[luke@FEDORA10PC ~]$
Also a bit of a linux noob.. in the bluetooth preferences i see myt head set and it says connected, but skype doesnt show it in the audio devices at all.. any ideas?
Running Fedora 10. Skypw 2.0.0.72, 320 Plantronics BT Headset
December 11th, 2008 at 7:42 pm (Comment)
codeguru Says:
Hi Luke,
Unfortunately, Skype is broken with regards to Bluetooth ALSA devices. We’ll have to wait for future Skype releases to fix this issue.
December 14th, 2008 at 7:48 pm (Comment)
Chris Schulz Says:
Howdy,
I have a stubborn barcode reader that wont allow me to enter the code “000″ on the host pc.
Is there a generic (non-audio) version of this script around? Im not quite skilled enough to hack this one
December 23rd, 2008 at 7:50 pm (Comment)
TankerKevo Says:
tankerkevo@tankerkevo-laptop:~$ ./bt.sh
Please place your Bluetooth audio device into pairing mode, then press
Scanning for Bluetooth audio device…
Selected bluetooth device: 00:22:A6:07:B0:DA
Writing new ~.asoundrc…
Getting default adapter…
/org/bluez/hci0
Removing any stale Bluetooth audio device:
method return sender=:1.83 -> dest=:1.135 reply_serial=2
Creating Bluetooth audio device:
Error org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
Connecting — BlueZ applet will prompt for pin…
Usage: dbus-send [--help] [--system | --session] [--dest=NAME] [--type=TYPE] [--print-reply=(literal)] [--reply-timeout=MSEC] [contents ...]
tankerkevo@tankerkevo-laptop:~$
December 23rd, 2008 at 11:56 pm (Comment)
codeguru Says:
@TankerKevo
Could you tell me which version of Fedora or Ubuntu you are running. The DBus commands in the script are supported in Fedora 10 and Ubuntu 8.10.
December 28th, 2008 at 7:17 pm (Comment)
ITAndrew Says:
I am also having the same problem as the above poster.
Creating Bluetooth audio device:
Error org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
Uname dump:
Linux evildeeds 2.6.27.9-159.fc10.i686 #1 SMP Tue Dec 16 15:12:04 EST 2008 i686 i686 i386 GNU/Linux
Using distro Fedora 10. I am currently trying to get a Moto HT820 sterio headset to work.
January 9th, 2009 at 7:59 pm (Comment)
Murz Says:
I have the same problem, Ubuntu Intrepid i386
$ ./bt.sh
Please place your Bluetooth audio device into pairing mode, then press
Scanning for Bluetooth audio device…
select device:
1) 00:02:76:64:4B:FE Motorola S705
#? 1
Selected bluetooth device: 00:02:76:64:4B:FE
Writing new ~.asoundrc…
Getting default adapter…
/org/bluez/hci0
Removing any stale Bluetooth audio device:
Error org.bluez.Error.DoesNotExist: Device does not exist
Error org.freedesktop.DBus.Error.Disconnected: Connection was disconnected before a reply was received
Creating Bluetooth audio device:
Error org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
January 10th, 2009 at 10:05 am (Comment)
Domenik Says:
Hi , got some issues with the sktipt. I’am getting ”
Scanning for Bluetooth audio device…
select device:
1) 00:0A:D9:AB:C6:60 Z600
2) 00:07:A4:B7:F7:8B Motorola HT820
#? 2
Selected bluetooth device: 00:07:A4:B7:F7:8B
Writing new ~.asoundrc…
Getting default adapter…
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.bluez was not provided by any .service files
Removing any stale Bluetooth audio device:
Must use org.mydomain.Interface.Method notation, no dot in “string:00:07:A4:B7:F7:8B”
Must use org.mydomain.Interface.Method notation, no dot in “objpath:”
Creating Bluetooth audio device:
Must use org.mydomain.Interface.Method notation, no dot in “string:00:07:A4:B7:F7:8B”
”
when executing bash ./bt_pair.sh…. *confused*
help would be epreciated
January 10th, 2009 at 10:52 am (Comment)
Domenik Says:
Using Intrepid Ibex Linux X40 2.6.27-7-generic #1 SMP Tue Nov 4 19:33:20 UTC 2008 i686 GNU/Linux
btsco v0.42
Device is 1:0
Bus 002 Device 003: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
and a Motorola HT820