How to connect a bluetooth keyboard in Ubuntu 9.04 Jaunty and 9.10 Karmic (workaround)

PDF

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:

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.

  1. First create a new file for the script:
    Add the following script:
    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:

  2. Next we’ll make sure it’ll run in the background when booted. Create a new boot entry:

    Add the following script:

    Close and save.

  3. Give both files execution rights with chmod +x {filename}
  4. Now run the following command to get the script executing during boot:

Reboot and check if it works. Remember to hit your keyboard’s reset switch when you want Ubuntu to connect your keyboard.

Tags:
  • 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.

    Reply

  • 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?

    Reply

  • 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!

    Reply

  • 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/null
    if [[ ! $connected =~ .*${address}.* ]] ; then
    sudo hidd –connect ${address} > /dev/null 2>&1
    else
    break;
    fi
    done

    Reply

  • 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.

    Reply

  • Bend3r

    It stopped complaining.

    Reply

  • 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…

    Reply

Leave a Reply