Bluetooth from the command line in 12.04?

I've been trying to pair up my bluetooth keyboard with my computer after reinstalling from a standard ubuntu 12.04 to a minimal install.

In the minimal install I have no gui, so I've been trying to use the various command line tools available, but I can't figure out how the pairing is supposed to go. Pairing when I had a gui worked flawlessly.

I've asked for help here: http://ubuntuforums.org/showthread.php?p=12234695

No one has replied but a lot of details of my situation is available there.

How is one supposed to pair bluetooth devices from the command line?


Solution 1:

Pair a new device

In Bluez4 install the bluez Install bluez package to be able to pair a device from the command line with bluez-simple-agent (Bluez5 will provide the bluetoothctl command):

bluez-simple-agent hci# xx:xx:xx:xx:xx:xx

Replace # with the Bluetooth adapter number (e.g. hci0) and xx:xx:xx:xx:xx:xx with the MAC of our Bluetooth device.

  • To get the number of our adapter we may issue:

      hciconfig
    
  • The MAC of devices can be scanned for with the following command:

      hcitool scan
    

The Bluetooth device should be in pairing mode of course. Enter the pin code when asked to pair the device.


Remove a paired device

If we already had paired a device and need to remove it from the database (e.g. for re-pairing) we may do so with

bluez-simple-agent hci# xx:xx:xx:xx:xx:xx remove

Note for keyboards (or mice): Until the Bluetooth keyboard is paired we may need to enter the PIN using an additional wired keyboard. See with the manual of your keyboard how the pairing is done (some expect PIN in computer first, some in keyboard first. Some may have a fixed PIN).

After pairing, we connect the keyboard with:

sudo bluez-test-input connect xx:xx:xx:xx:xx:xx 

To allow auto-connection after a reboot we can add the device to the trusted devices:

sudo bluez-test-device trusted xx:xx:xx:xx:xx:xx yes