Bluez-tools how-to

IMPORTANT: With OpenELEC 3.2 there is no need for this addon because of new OpenELEC settings where you can add your bluetooth devices.

Note 1: This article is made with linux beginers in my mind so linux gurus please be patient.

''Note 2: There are some bluetooth devices officialy supported by OpenELEC team: ps3 remote, sisaxis controller and wii remote by installing corespondent Add-ons: xbmc-ps3d and xbmc-wiimote. For this devices to work the bluetooth input plugin must be disabled. Other bluetooth input devices will not work until the input plugin will be enabled but in this case the officially supported ones will not work. Maybe this will change in the future.''

Prerequisites: nano, mksquashfs, bluez-tools Add-ons installed (and OpenELEC box rebooted after install).

The bluez-tools Add-on for OpenELEC installs only a subset of command line tools provided by the original bluez-tools but enough to connect many types of bluetooth devices. The tools are:

bt-adapter bt-device
 * lists bluetooth adapters attached to the OpenELEC box
 * shows adapter(s) info
 * discovers the remote device(s)
 * changes adapter(s) properties
 * lists added device(s)
 * connects and pairs remote device(s)
 * disconnects the remote device(s)
 * removes device(s)
 * changes device(s) properties

bt-input
 * connects input device(s)

bt-audio
 * connects audio device(s)

Step 0. Enable bluetooth input plugin Before trying to connect bluetooth input devices (keyboards, mice, s.o.) enable the bluetooth input plugin. For this, read and follow the steps outlined in the mksquashfs Add-on how-to. When the how-to says “Now you can make your changes”, go to  directory and edit the   file (with nano), comment the fourth line in the file so it will look like this. Then go update your system (like the how-to says). This change must be made every time a new OpenELEC build gets released. For bluetooth audio devices (like headsets) this step is not mandatory.

Connect by ssh to your OpenELEC box. Put your device in “discovery” mode (consult the device manual).

Step 1. Discover the device

Enter this at the command prompt: bt-adapter -d You will see something like this: Searching...

[XX:XX:XX:XX:XX:XX] Name: Macro Keyboard Alias: Macro Keyboard Address: XX:XX:XX:XX:XX:XX Icon: input-keyboard Class: 0x2540 LegacyPairing: 0 Paired: 0 RSSI: -78

[XX:XX:XX:XX:XX:XX] Name: (null) Alias: XX-XX-XX-XX-XX-XX Address: XX:XX:XX:XX:XX:XX Icon: phone Class: 0x520204 LegacyPairing: 0 Paired: 0 RSSI: -64

Done (The MAC addresses was anonymized.)

You can see a bluetooth keyboard and a phone discovered. Take note about the MAC address of the device you want to connect (in this case it would be the keyboard of course).

Step 2. Pairing

Enter at the command prompt bt-device -c XX:XX:XX:XX:XX:XX enter your MAC address from the first step you will see this on the screen Connecting to: XX:XX:XX:XX:XX:XX Agent registered Device: Macro Keyboard (XX:XX:XX:XX:XX:XX) Enter PIN code: Enter the pin code, first at the terminal screen, then at the device and you will see this (if everything goes well): Enter PIN code: 0000 Agent released Done

Step 3. Connecting

Issue this at command prompt: bt-input -c XX:XX:XX:XX:XX:XX the expected result must be Input service is connected If the result is Input service is not supported by this device it means that the input plugin is disabled (read step 0)

Step 4. Set the Trusted property

If you want your device to reconnect after reboot, sleep or device timeout, you must do this: bt-device --set XX:XX:XX:XX:XX:XX Trusted 1 and the answer will be: Trusted: 0 -> 1

Steps outlined above are for connecting bluetooth input device. For connecting audio devices (like bluetooth headsets) the difference is at step 3, where you must enter this: bt-audio –c XX:XX:XX:XX:XX:XX and continue with step 4. Then create a custom asound.conf with this content: pcm.btheadset { type plug slave { pcm { type bluetooth device XX:XX:XX:XX:XX:XX profile "auto" }	     }

hint { show on	   description "Twister" }	      }

ctl.btheadset { type bluetooth } finally in XBMC go to SYSTEM -> Settings -> System -> Audio Output and make this actions
 * at 'Audio output' choose 'Analog'
 * at 'Speaker Configuration' choose '2.1'
 * at 'Audio output device' choose 'Custom'
 * at 'Custom audio device' enter 'btheadset'

Tips.

I. Sometimes, even if it looks like the pairing was successfully finalised, the device is not working. You can try a 're-pairing', so remove first the device with bt-device -r XX:XX:XX:XX:XX:XX then pair again with bt-device -c XX:XX:XX:XX:XX:XX

II. You can pair with a 'predefined' PIN code if you use this command bt-device -c XX:XX:XX:XX:XX:XX -p 000 the PIN code in this case will be ‘0000’, and you will have to enter the PIN code only at the bluetooth device after on the terminal you will see waiting for PIN code from your device

III. bt-device tool has also an -e command line option. This option I used to ‘pair’ a ps3 remote with my OpenELEC box. The xbmc-ps3d add-on is initiate the pairing only at predefined intervals and the remote stays in 'discoverable mode' only for like 30 seconds so I had many problems with pairing my ps3 remote. So for pairing the ps3 remote I do this: The remote will work like it should. Note. There is no need to edit the main.conf file to enable the bluetooth input plugins.
 * install xbmc-ps3d Add-on (if not already installed);
 * put remote in discoverable mode;
 * issue bt-adapter -d at command prompt to find remotes MAC address;
 * put remote in discoverable mode again;
 * enter bt-device -e XX:XX:XX:XX:XX:XX (there is not necessary to enter PIN codes);
 * then bt-device -set XX:XX:XX:XX:XX:XX Trusted 1;

IV. If you are using some 'pretty' nano bluetooth adapters, take note that those adapters working range is not 10m (like it is advertised) but only 2-2.5m and for the discovery and pairing process you will have to be near the adapter (for avoiding the timeouts and other errors).