You are not logged in.

#1 2014-02-13 02:00:41

Neverlasting
Member
Registered: 2008-12-26
Posts: 13

Bluetooth keyboard not connecting automatically when booting

I have paired with and connected to my Bluetooth keyboard (and I also set it to be trusted in bluetoothctl) and it is working in principle. However, I could not manage to connect it automatically after booting. (I'm using Arch with bluez 5.14 and Linux 3.12.9 and -- don't know if it's relevant -- GNOME 3.)

Currently, the following two ways let me connect to it manually after booting:
a) Either I use a wired keyboard to execute bluetoothctl and enter "power on" and "connect <MAC>", or
b) I press any key on my wireless keyboard and it connects after a second. This is annoying because I want to use it right away.

The wiki page on Bluetooth mentions that in order to connect automatically to a Bluetooth keyboard, one ought to use a udev rule that calls "hciconfig hci0 up". However, this does not work. Even calling this after the boot has completed does not connect to the keyboard.

So I wrote a script that executes bluetoothctl and, in its prompt, enters "power on" and "connect <MAC>". This does work when I call it after booting has completed. But in the following udev rule it does not work:

$ cat /etc/udev/rules.d/10-local.rules     
# Set bluetooth power up
ACTION=="add", KERNEL=="hci0", RUN+="/usr/local/bin/my-script.sh"

The reason is that bluetoothctl complains: "No default controller available." It seems that this rule is triggered too early (as there is a default controller after completing the boot). So I tried to call my script from a systemd .service file with the intention of running the script only after the bluetooth service has been started.

$ cat /etc/systemd/system/btconnect.service
[Unit]
Description=bluetooth connect
After=bluetooth.target
Requires=bluetooth.service

[Service]
Type=oneshot
ExecStart=/usr/local/bin/my-script.sh

[Install]
WantedBy=bluetooth.target

This also does not help -- same problem.

Note that starting my script with these methods does work if I insert something like "sleep 5" at the start of my script; but this is, of course, not a solution. I hope any of you has some clues as I'm running out of ideas.

Offline

Board footer

Powered by FluxBB