How to connect a bluetooth keyboard in Ubuntu 9.04 Jaunty and 9.10 Karmic (workaround)
PDFHere’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:
1 | 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:
1sudo nano /etc/keyboard.sh
1234while (sleep 10)dosudo hidd --connect AA:BB:CC:DD:EE:FF > /dev/null 2>&1doneNote: 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:123456789101112</p>#! /bin/bashaddress="AA:BB:CC:DD:EE:FF"while (sleep 1)doconnected=`sudo hidd --show` > /dev/nullif [[ ! $connected =~ .*${address}.* ]] ; thensudo hidd --connect ${address} > /dev/null 2>&1fidone - Next we’ll make sure it’ll run in the background when booted. Create a new boot entry: 1sudo nano /etc/init.d/keyboard
Add the following script:
12345#!/bin/sh/etc/keyboard.sh &exit 0Close and save.
- Give both files execution rights with chmod +x {filename}
- Now run the following command to get the script executing during boot: 1sudo 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.
Tags: jaunty • karmic • keyboard • ubuntu • ubuntu bluetooth
Pingback: How Ubuntu’s broken bluetooth support came to be « Benny’s Blog
Peter Davoust
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.
Alex J
Works great, except my auto-connected bluetooth device doesn’t input!
If I stop auto connect and manually connect to input service, I can use the ps3 bd remote to navigate xbmc. Am I missing a hidd config to auto connect to inputservice?
Sergi
Year 2015, Raspberry Pi 2 running Raspbian. Samsung VG-KBD1500. One day researching till I found this post.
Works great from the boot and powering off/on the keyboard (and pressing the pairing button again).
Thank you!
Bernardo
Great Article!
if you add an else to exit your loop you will save some cpu.
#! /bin/bash
address=”AA:BB:CC:DD:EE:FF”
while (sleep 1)
do
connected=
sudo hidd --show
> /dev/nullif [[ ! $connected =~ .*${address}.* ]] ; then
sudo hidd –connect ${address} > /dev/null 2>&1
else
break;
fi
done
Bend3r
I tried this in Ubuntu Xenial 16.04 and it didn’t work. In the last step (sudo update-rc.d keyboard defaults) I get this message:
insserv: warning: script ‘keyboard’ missing LSB tags and overrides
After googling I added this to the script after the ‘#!/bin/sh’ line:
### BEGIN INIT INFO
# Provides: blabla
# Required-Start: $syslog
# Required-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: blabla
# Description:
#
### END INIT INFO
I stopped complaining, but still doesn’t connect with the keyboard.
Bend3r
It stopped complaining.
Flurrywinde
@Bend3r, did you ever get it to work? I’m also on Ubuntu 16.04, and my keyboard doesn’t auto-connect at startup. I have to manually hit a key and wait for it to connect.
bluetoothctl
‘s connect command gives: “Failed to connect: org.bluez.Error.Failed.” Do you think this hidd way will work when this doesn’t? I’m afraid to install bluez-compat lest it breaks something. Needless fear? Maybe, but…