Skip to contentSkip to conversation

bluetooth on ubuntu without desktop environment

DISCUSSION Michael Jarosch 2 participants 4 messages Jun 3, 2011 – Jun 8, 2011 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

Hi!

I'm using the latest Ubuntu (11.04) minimal installation with XBMC and I try to make a Logitech Cordless MediaBoard Pro work with it. The keyboard-/touchpad-combination designed for the PS3 worked just fine with a "normal" install of Ubuntu 10.10 with the Gnome desktop environment (and I guess it should work with 11.04/Unity, also). My special problem now is, that I don't use any kind of desktop environment any more, it's just X and the XBMC-GUI. I tried to use "blueman" to configure the bluetooth connection, but it doesn't seem to start - just getting some weird errors. So, I totally depend on the console-tools of bluez and dbus - but, hey, this is linux and it shouldn't be a problem, right?

Well, partly, it actually isn't. Pairing and connecting the keyboard works right away. But if I reboot the computer or try to reconnect the keyboard for other reasons, I'm forced to pair the devices again and again, which isn't exactly the spirit of using bluetooth devices. :)

My goal is to make the keyboard connect to my PC whenever I need it. All I achieved is that the connection only works if the PC initialises it.

I used an entry from the arch linux wiki for my configuration, which only uses console-commands, mainly dbus-specific:
https://wiki.archlinux.org/index.php/Bluetooth_mouse_configuration

I tried this:

1) Pressing the reset button of the Logitech-device to make it discoverable to the PC.

2) Scanning for the Logitech-device with "hcitool scan". I get this answer from the kyeboard:
00:07:61:F6:97:F7 Logitech Cordless MediaBoard Pro(TM)

3) Getting the dbus adress of the BT-Dongle:

$ dbus-send --system --type=method_call --print-reply --dest=org.bluez
"/" org.bluez.Manager.ListAdapters

method return sender=:1.23 -> dest=:1.26 reply_serial=2
array [

      object path "/org/bluez/1926/hci0"

]

4) Create the bluez-device for the keyboard:

$ dbus-send --system --type=method_call --print-reply --dest=org.bluez
"/org/bluez/1926/hci0" org.bluez.Adapter.CreateDevice
string:00:07:61:F6:97:F7

5) Give keyboard permission to connect the PC:

$ dbus-send --system --type=method_call --print-reply --dest=org.bluez
"/org/bluez/1926/hci0/dev_00_07_61_F6_97_F7"
org.bluez.Device.SetProperty string:Trusted variant:boolean:true

I can connect the Logitech-device with hidd --connect 00:07:61:F6:97:F7, now, but if the connection somehow breaks, it's not possible to reconnect from the keyboard (by just pressing a button or turning the device off and on, f.e.)

This is the state of dbus/bluez/the PC system, now:

$ dbus-send --system --type=method_call --print-reply --dest=org.bluez
"/org/bluez/1926/hci0" org.bluez.Adapter.GetProperties

method return sender=:1.23 -> dest=:1.28 reply_serial=2
array [

      dict entry(
         string "Address"
         variant             string "00:19:86:00:3C:65"
      )
      dict entry(
         string "Name"
         variant             string "dog-0"
      )
      dict entry(
         string "Class"
         variant             uint32 4849920
      )
      dict entry(
         string "Powered"
         variant             boolean true
      )
      dict entry(
         string "Discoverable"
         variant             boolean false
      )
      dict entry(
         string "Pairable"
         variant             boolean true
      )
      dict entry(
         string "DiscoverableTimeout"
         variant             uint32 0
      )
      dict entry(
         string "PairableTimeout"
         variant             uint32 0
      )
      dict entry(
         string "Discovering"
         variant             boolean false
      )
      dict entry(
         string "Devices"
         variant             array [
               object path "/org/bluez/1926/hci0/dev_00_07_61_F6_97_F7"
            ]
      )
      dict entry(
         string "UUIDs"
         variant             array [
               string "00001000-0000-1000-8000-00805f9b34fb"
               string "00001001-0000-1000-8000-00805f9b34fb"
               string "00001112-0000-1000-8000-00805f9b34fb"
               string "0000111f-0000-1000-8000-00805f9b34fb"
               string "0000110a-0000-1000-8000-00805f9b34fb"
               string "0000110c-0000-1000-8000-00805f9b34fb"
               string "0000110e-0000-1000-8000-00805f9b34fb"
               string "00001103-0000-1000-8000-00805f9b34fb"
            ]
      )

]

$ dbus-send --system --type=method_call --print-reply --dest=org.bluez
"/org/bluez/1926/hci0/dev_00_07_61_F6_97_F7"
org.bluez.Device.GetProperties

method return sender=:1.23 -> dest=:1.31 reply_serial=2
array [

      dict entry(
         string "Address"
         variant             string "00:07:61:F6:97:F7"
      )
      dict entry(
         string "Name"
         variant             string "Logitech Cordless MediaBoard
Pro(TM)"
      )
      dict entry(
         string "Alias"
         variant             string "Logitech Cordless MediaBoard
Pro(TM)"
      )
      dict entry(
         string "Class"
         variant             uint32 9536
      )
      dict entry(
         string "Icon"
         variant             string "input-keyboard"
      )
      dict entry(
         string "Paired"
         variant             boolean false
      )
      dict entry(
         string "Trusted"
         variant             boolean true
      )
      dict entry(
         string "Blocked"
         variant             boolean false
      )
      dict entry(
         string "Connected"
         variant             boolean true
      )
      dict entry(
         string "UUIDs"
         variant             array [
               string "00001124-0000-1000-8000-00805f9b34fb"
               string "00001200-0000-1000-8000-00805f9b34fb"
            ]
      )
      dict entry(
         string "Services"
         variant             array [
            ]
      )
      dict entry(
         string "Adapter"
         variant             object path "/org/bluez/1118/hci0"
      )

]

I've done everything like described in the wiki-entry except for one
thing: The author recommends using a non privileged user, I did everything with root.

And just another deviation: In the article of the arch-wiki it is said, that the dbus address reflects the pid of bluetoothd. Under Ubuntu this is not true!

Now here is my question: What else can I do to reach my goal? And then: What's your opinion: Is there a bug in the Ubuntu version of bluez?

Thanks for any hints!
And greetings!

Mitsch

#1 lore raw

Hi there!

Since nobody seems to matter about my post and the stuff you discuss about is rather code-specific - although not at all boring to me - I wonder if I'm at the right place with my problem.

I thought I subscribed at the bluez user mailing list, didn't I? At least the bluez-homepage lead me here. http://www.bluez.org/contact/

?!?

Well, if someone just tells me, where I'd better subscribe, then? :)

Greets
Mitsch

#2 lore raw
In reply to Michael Jarosch

Hi Michael,

Quoted 47 lines · Michael Jarosch

Hi!

I'm using the latest Ubuntu (11.04) minimal installation with XBMC and I try to make a Logitech Cordless MediaBoard Pro work with it. The keyboard-/touchpad-combination designed for the PS3 worked just fine with a "normal" install of Ubuntu 10.10 with the Gnome desktop environment (and I guess it should work with 11.04/Unity, also). My special problem now is, that I don't use any kind of desktop environment any more, it's just X and the XBMC-GUI. I tried to use "blueman" to configure the bluetooth connection, but it doesn't seem to start - just getting some weird errors. So, I totally depend on the console-tools of bluez and dbus - but, hey, this is linux and it shouldn't be a problem, right?

Well, partly, it actually isn't. Pairing and connecting the keyboard works right away. But if I reboot the computer or try to reconnect the keyboard for other reasons, I'm forced to pair the devices again and again, which isn't exactly the spirit of using bluetooth devices. :)

My goal is to make the keyboard connect to my PC whenever I need it. All I achieved is that the connection only works if the PC initialises it.

I used an entry from the arch linux wiki for my configuration, which only uses console-commands, mainly dbus-specific:
https://wiki.archlinux.org/index.php/Bluetooth_mouse_configuration

I tried this:

1) Pressing the reset button of the Logitech-device to make it discoverable to the PC.

2) Scanning for the Logitech-device with "hcitool scan". I get this answer from the kyeboard:
00:07:61:F6:97:F7 Logitech Cordless MediaBoard Pro(TM)

3) Getting the dbus adress of the BT-Dongle:

$ dbus-send --system --type=method_call --print-reply --dest=org.bluez
"/" org.bluez.Manager.ListAdapters

method return sender=:1.23 -> dest=:1.26 reply_serial=2
array [

      object path "/org/bluez/1926/hci0"

]

4) Create the bluez-device for the keyboard:

Quoted 9 lines
$ dbus-send --system --type=method_call --print-reply --dest=org.bluez
"/org/bluez/1926/hci0" org.bluez.Adapter.CreateDevice
string:00:07:61:F6:97:F7

5) Give keyboard permission to connect the PC:

$ dbus-send --system --type=method_call --print-reply --dest=org.bluez
"/org/bluez/1926/hci0/dev_00_07_61_F6_97_F7"
org.bluez.Device.SetProperty string:Trusted variant:boolean:true

I didn't read the Arch wiki closely, but there are much better ways to that. This is what I would do:

1. Get the BlueZ sources, and go to the test/ directory;

2. ./simple-agent hci0 <keyboard address>
(follow the instructions from the keyboard for pairing, usually putting the same passkey in both sides). This will pair your computer with the keyboard. If it complains about that the pairing already exists, just add a third parameter, it can be anything.

3. ./test-device trusted <keyboard address> yes
This will set the device as trusted, so connection comming from it will be automatically accepted.

4. Now as the device is already bonded and connections are automatically accepted, reconnections should work as they should.

Some notes: those are simple python scripts, be sure to have python already installed. In case you still have some troubles drop by #bluez-users on freenode.

Quoted 6 lines

I can connect the Logitech-device with hidd --connect 00:07:61:F6:97:F7, now, but if the connection somehow breaks, it's not possible to reconnect from the keyboard (by just pressing a button or turning the device off and on, f.e.)

[ snip ]

Cheers,

Signature · 1 line
Vinicius
#3 lore raw

Am Dienstag, den 07.06.2011, 20:11 -0300 schrieb Vinicius Costa Gomes:

Quoted 10 lines

This is what I would do:

1. Get the BlueZ sources, and go to the test/ directory;

2. ./simple-agent hci0 <keyboard address>
(follow the instructions from the keyboard for pairing, usually putting the same passkey in both sides). This will pair your computer with the keyboard. If it complains about that the pairing already exists, just add a third parameter, it can be anything.

Quoted 6 lines

3. ./test-device trusted <keyboard address> yes
This will set the device as trusted, so connection comming from it will be automatically accepted.

4. Now as the device is already bonded and connections are automatically accepted, reconnections should work as they should.

Unbelievable: It's working! Thanks!

Those scripts are part of the ubuntu "bluez"-package with a little change in naming them: There is always a "bluez-" in front of it.

simple-agent -> bluez-simple-agent
test-device -> bluez-test-device

So no need to download them.
I must confess, I was sceptical at first, because I already tried bluez-simple-agent without success. I guess I was lucky to have the right combination of packages installed, now - got to figure out, why it didn't work last time!

Well, then: I'll spread the word!
Thanks again!

Bye!