Here’s a quick workaround for connecting and reconnecting a bluetooth keyboard (or any bluetooth device for that matter) in Ubuntu Jaunty and Karmic, even after rebooting. In short it’s a shell script that keeps connecting to your device in the background on a regular interval. Dirty? Absolutely. Does it work? Absolutely, no bluetooth configuration required at all.
Originally, this whole workaround came from a post on ubuntuforums.org by Unkie, which I modified only slightly (I’m plantface there). This workaround revolves around hidd, which was removed in Ubuntu 9.04 which you can get back as follows:
sudo apt-get install bluez-compat
Hidd is a tool that works like a charm for scanning and connecting to bluetooth devices. It’s still used these days because the Ubuntu dev team somehow manages to kill bluetooth support every new version. There are so many tutorials and flavors floating around to get a bluetooth device working and apparently with so little success that hidd remains popular. With 9.04 they gave bluetooth an overhaul and deprecated hidd.
Anyway, here’s the shell script that keeps connecting your keyboard. There’s one catch though: I haven’t figured out how to let the keyboard sleep, awake and reconnect itself, so you’ll need to hit the reset button on the keyboard to reveal itself to the bluetooth adapter looking for it. Reconnecting this way requires thus one extra manual action before it reconnects (same thing goes for when you rebooted). But it reconnects when you want it to, which is what I’m content with for the moment, considering the alternative.
-
First create a new file for the script:
sudo nano /etc/keyboard.sh
Add the following script:
while (sleep 10) do sudo hidd --connect AA:BB:CC:DD:EE:FF > /dev/null 2>&1 done
Close and save.
Note: that AA:BB address should be the MAC address of your keyboard. You can find it using the new bluetooth tool hcitool scan (make sure your keyboard is findable by hitting its reset switch) or with hidd –search, which coincidently will automatically attempt to connect your device while scanning it.
EDIT: August 8th, 2010
I updated the above script to react much more quickly and avoid unnecessary connect attempts:#! /bin/bash address="AA:BB:CC:DD:EE:FF" while (sleep 1) do connected=`sudo hidd --show` > /dev/null if [[ ! $connected =~ .*${address}.* ]] ; then sudo hidd --connect ${address} > /dev/null 2>&1 fi done -
Next we’ll make sure it’ll run in the background when booted. Create a new boot entry:
sudo nano /etc/init.d/keyboard
Add the following script:
#!/bin/sh /etc/keyboard.sh & exit 0
Close and save.
- Give both files execution rights with chmod +x {filename}
-
Now run the following command to get the script executing during boot:
sudo update-rc.d keyboard defaults
Reboot and check if it works. Remember to hit your keyboard’s reset switch when you want Ubuntu to connect your keyboard.
Pingback: How Ubuntu’s broken bluetooth support came to be « Benny’s Blog
Thank you very much! After a few days of fighting with this problem and making no progress, I stumbled upon this post and my keyboard connects effortlessly at startup. It’s curious that there seems to be no alternative to Bluez. I guess it works pretty well, but it’s a devil to use.