Bluetooth keyboard
This article describes how to set up a Bluetooth HID keyboard with Arch Linux, bluez version 5.
Pairing process
Login to the affected computer by a wired keyboard or by ssh.
First, make sure the local Bluetooth controller (e.g. a Bluetooth dongle the built in Bluetooth radio) is recognized:
# lsusb
Bus 001 Device 004: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode) Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. LAN9500 Ethernet 10/100 Adapter / SMSC9512/9514 Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
The above output is from a Raspberry-Pi revision 'B' with archlinux-arm and a Keysonic Bluetooth Dongle.
Three items worth remembering:
- Bluetooth devices (keyboard) and controllers (dongle) need to be paired once.
- The Bluetooth controller needs to be powered up after every boot.
- The Bluetooth controller needs to be told to connect to the keyboard after every boot.
Pairing is a one time process, required only once. There are Bluetooth keyboards sold with a Bluetooth dongle which come already paired, but that is not certain. We will use the bluetoothctl
command from bluez-utils to pair our dongle and the keyboard.
Power up can be done with bluetoothctl
, or automatically in /etc/bluetooth/main.conf
, see below.
Same for connecting, either bluetoothctl
or hcitool
can be used, the latter is more useful for scripting.
We will use bluetoothctl for the pairing process. Run the command to get at the [bluetooth]#
prompt.
# bluetoothctl
[bluetooth]#
While in bluetoothctl power up the controller:
[bluetooth]# power on
Changing power on succeeded [CHG] Controller 06:05:04:03:02:01 Powered: yes
Next, tell bluetoothctl
to look only for keyboards, and make that the default agent:
[bluetooth]# agent KeyboardOnly
Agent registered
[bluetooth]# default-agent
Default agent request successful
Next, put your controller (the local dongle) in pairable mode:
[bluetooth]# pairable on
Changing pairable on succeeded
Next, put your keyboard in an active mode, where it is discoverable, i.e. pairable. Some keyboards have a special button for this on the underside, or require a special key combination to be pressed. See the documentation of your keyboard. Please note that this discoverability of a device is time limited, some devices are only visible 30 seconds, other for 2 minutes. Your mileage may vary.
Next, let the controller scan the Bluetooth frequencies for a suitable device:
[bluetooth]# scan on
Discovery started [CHG] Controller 06:05:04:03:02:01 Discovering: yes
After a few seconds the address of the keyboard should be listed as found. This line will repeat over and over, but will not stop you from entering new commands.
Next, actually do the pairing. The address used is the Bluetooth MAC address of the keyboard:
[bluetooth]# pair 01:02:03:04:05:06
Pairing successful
[agent] Passkey: 501334
) which has to be typed in on the Bluetooth keyboard followed by the key Enter
in order to pair successfully. Use paired-devices
command to double check if the pairing succeeded.Next, make this a trusted device (this allows the device to establish the connection on itself). Again, the Bluetooth MAC address is the address of the keyboard device:
[bluetooth]# trust 01:02:03:04:05:06
Trusted
Next and finally connect to the device (keyboard). Again, the Bluetooth MAC address is the address of the keyboard device:
[bluetooth]# connect 01:02:03:04:05:06
Connection successful
Done. Leave the bluetoothctl utility:
[bluetooth]# quit
Now the external device (i.e. keyboard) and the USB Bluetooth dongle are paired permanently, unless you break the pairing intentionally. This does not mean that the keyboard will connect automatically to your Bluetooth device after a boot. This is mainly due to the fact that the Bluetooth controller will be automatically turned off after each reboot. To automatically connect the keyboard after a reboot, see Bluetooth#Auto power-on after boot/resume.
Troubleshooting
Bluetooth controller does not show up in lsusb
- Load generic Bluetooth driver:
# modprobe btusb
- Is it an USB adapter or integral to the system? Use
lspci
for integral adapters
Bluetooth controller is not visible in bluetoothctl
- Check the
bluetooth.service
unit status. - Check: You run the command with superuser privileges using
su
orsudo
. Otherwise you have blue [bluetooth]# prompt and get the following message when powering on the controller:[bluetooth]# power on No default controller available
Bluetooth keyboard still does not work
- Check: Does it have power?
- Check: Did it connect to the Bluetooth controller? If not, try with another controller or your smart phone.
Error: hci0 ACL packet for unknown connection handle 4
- Try a reset with
hciconfig hci0 reset
Xorg
Device should be added as /dev/input/event*
and your Xorg should add it automatically if you did not disable such feature.