Difference between revisions of "Bluetooth keyboard"

From ArchWiki
Jump to: navigation, search
(recat)
(Bluetooth Keyboard at Startup: 2nd appearance error, removed)
(9 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{i18n|Bluetooth Keyboard}}
+
[[Category:Bluetooth]]
[[Category:Keyboards (English)]]
+
[[Category:Keyboards]]
 +
[[ru:Bluetooth Keyboard]]
 +
{{Stub|Unfinished, missing references.}}
  
This article describes how to set up a Bluetooth keyboard with Arch Linux, bluez version 3. I used an Apple Wireless Keyboard (aluminium) but it should work for other models.
+
== Bluetooth Keyboard Pairing Process ==
  
The setup is similar than the one of a [[Bluetooth Mouse]]. Follow this guide first to add kernel modules, bluetooth libraries.
+
This article describes how to set up a Bluetooth HID keyboard with Arch Linux, bluez version 5.
  
The tricky part for the Apple Wireless Keyboard is to have the correct settings in ''/etc/bluetooth/hcid.conf''. Obviously you need to replace the mac address with yours:
 
  
device 00:01:02:03:04:05 {
 
  name "Apple Wireless Keyboard";
 
  auth disable;
 
  encrypt disable;
 
}
 
  
And then to have ''/etc/conf.d/bluetooth'' with the following options to connect automatically when starting the bluetooth daemon:
+
Make sure the local BT controller (e.g. a BT dongle the built in BT radio) is recognized:
 +
{{bc|# 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
 +
}}
  
HCID_ENABLE="true"
+
The above output is from a Raspberry-Pi revision 'B' with archlinux-arm and a Keysonic BT Dongle.
HIDD_ENABLE="true"
+
HIDD_OPTIONS="--timeout 8 --master --server --connect 00:01:02:03:04:05"
+
  
If you loaded the bluetooth modules from the [[Bluetooth Mouse]] guide you can now test by doing a ''/etc/rc.d/bluetooth restart''
+
Start bluetooth service (as root):
 +
{{bc|# systemctl start bluetooth}}
  
== Bluetooth Keyboard at Startup ==
+
If you are sure you want to have Bluetooth available after every booth automatically, permanently enable the service (as root):
 +
{{bc|# systemctl enable bluetooth}}
  
in ''/etc/rc.conf'' add the following modules:
+
Two items worth remembering:
 +
* BT devices (keyboard) and controllers (dongle) need to be paired once
 +
* The BT controller needs to be powered up after every boot
  
MODULES=(... hci_usb bluetooth hidp l2cap)
+
'''Pairing''' is a one time process, required only once. There are BT keyboards sold with a BT dongle which come already paired, but that's not certain. We will use the '''bluetoothctl''' command from bluez5 to pair our dongle and the keyboard.  
  
and add the bluetooth daemon:
+
'''Power up''' can also be done with '''bluetoothctl''', or with '''hciconfig''' which is more suitable for scripting. See below.
DAEMONS=(... @bluetooth ...)
+
  
Then it should work on reboot automatically !
 
  
== Bluez v4.39 ==
+
We will use '''bluetoothctl''' for the pairing process:
In this version of bluez, there is no ''/etc/bluetooth/hcid.conf''
+
 
To create a trust between your BT adapter and a BT device, add the device's BT address to a file called ''trusts'' inside /var/lib/bluetooth/<MAC address of BT host adapter>/trusts, like so:
+
{{bc|# bluetoothctl -a}}
echo "00:02:76:05:45:E1 [all]" >> /var/lib/bluetooth/00\:1E\:37\:B0\:47\:24/trusts
+
puts you at the '''[bluetooth]#''' prompt. If you are on a colour console: the word 'bluetooth' is in the default colour as long as no devices are available, and blue as soon as required devices and/or controllers have been found.
This line appends a new line to that file.
+
 
 +
While in '''bluetoothctl''' power up the controller:
 +
{{bc|[...]# power on
 +
Changing power on succeeded
 +
[CHG] Controller 00:15:83:12:30:16 Powered: yes
 +
[...]#
 +
}}
 +
 
 +
Next, tell bluetoothctl to look only for keyboards, and make that the default agent:
 +
{{bc|[...]# agent KeyboardOnly
 +
Agent registered
 +
[...]# default-agent
 +
Default agent request successful
 +
[...]#
 +
}}
 +
 
 +
Next, put your controller (the local dongle) in 'pairable' mode:
 +
{{bc|[...]# 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. YMMV.
 +
 
 +
Next, let the controller scan the BT frequencies for a suitable device:
 +
{{bc|[...]# scan on
 +
Discovery started
 +
[CHG] Controller 00:15:83:12:30:16 Discovering: yes
 +
[...]#
 +
}}
 +
 
 +
After a few seconds the adress of the keyboard should be listed as found. This line will repeat over and over, but won't stop you from entering new commands.
 +
 
 +
Next, actually do the pairing. The address used is the BT-MAC address of the keyboard:
 +
{{bc|[...]# pair 01:02:03:04:05:06
 +
Pairing successful
 +
[...]#
 +
}}
 +
 
 +
Next, make this a trusted device (the author does not know the effects of this command, but it seems to be required):
 +
{{bc|[...]# trust 01:02:03:04:05:06
 +
Trusted
 +
[...]#
 +
}}
 +
 
 +
Next and finally connect to the device (keyboard):
 +
{{bc|[...]# connect 01:02:03:04:05:06
 +
Connection successful
 +
[...]#
 +
}}
 +
 
 +
'''Done.'''
 +
 
 +
Now the external device (i.e. keyboard) and the USB BT dongle are paired permanently, until you break the pairing manually. This does not mean that the keyboard will connect automatically to your BT device. This needs to be done after startup of your computer.
 +
 
 +
== Enable Bluetooth Keyboard at Startup ==
 +
 
 +
Although the device and the controller are now paired, you need to connect them every time the computer starts.
 +
 
 +
First the device (i.e. BT Dongle) needs to be powered up. This is done with the '''hciconfig''' utility. We assume that you have only one BT device connected, and this one has the symbolic name '''hci0'''.
 +
{{bc| # hciconfig hci0 up}}
 +
 
 +
Next, make the connection, now using the '''hcitool''' utility. Make sure that the keyboard is powered up and connectable, i.e. not in a power saving sleep state.
 +
{{bc| # hcitool cc 01:02:03:04:05:06}}
 +
 
 +
Your BT keyboard should be useable now. Nex twe will discuss how to automate this with '''systemd'''.
 +
 
 +
 
 +
== Automatic start of a BT Keyboard ==
 +
 
 +
TBD
 +
 
 +
 
 +
 
 +
 
 +
 
 +
== Xorg ==
 +
Device should be added as /dev/input/event* and your Xorg should add it automatically if you did not disable such feature.

Revision as of 23:53, 1 December 2013

Tango-document-new.pngThis article is a stub.Tango-document-new.png

Notes: Unfinished, missing references. (Discuss in Talk:Bluetooth keyboard#)

Bluetooth Keyboard Pairing Process

This article describes how to set up a Bluetooth HID keyboard with Arch Linux, bluez version 5.


Make sure the local BT controller (e.g. a BT dongle the built in BT 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 BT Dongle.

Start bluetooth service (as root):

# systemctl start bluetooth

If you are sure you want to have Bluetooth available after every booth automatically, permanently enable the service (as root):

# systemctl enable bluetooth

Two items worth remembering:

  • BT devices (keyboard) and controllers (dongle) need to be paired once
  • The BT controller needs to be powered up after every boot

Pairing is a one time process, required only once. There are BT keyboards sold with a BT dongle which come already paired, but that's not certain. We will use the bluetoothctl command from bluez5 to pair our dongle and the keyboard.

Power up can also be done with bluetoothctl, or with hciconfig which is more suitable for scripting. See below.


We will use bluetoothctl for the pairing process:

# bluetoothctl -a

puts you at the [bluetooth]# prompt. If you are on a colour console: the word 'bluetooth' is in the default colour as long as no devices are available, and blue as soon as required devices and/or controllers have been found.

While in bluetoothctl power up the controller:

[...]# power on
Changing power on succeeded
[CHG] Controller 00:15:83:12:30:16 Powered: yes
[...]#

Next, tell bluetoothctl to look only for keyboards, and make that the default agent:

[...]# agent KeyboardOnly
Agent registered
[...]# default-agent
Default agent request successful
[...]# 

Next, put your controller (the local dongle) in 'pairable' mode:

[...]# 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. YMMV.

Next, let the controller scan the BT frequencies for a suitable device:

[...]# scan on
Discovery started
[CHG] Controller 00:15:83:12:30:16 Discovering: yes
[...]# 

After a few seconds the adress of the keyboard should be listed as found. This line will repeat over and over, but won't stop you from entering new commands.

Next, actually do the pairing. The address used is the BT-MAC address of the keyboard:

[...]# pair 01:02:03:04:05:06
Pairing successful
[...]# 

Next, make this a trusted device (the author does not know the effects of this command, but it seems to be required):

[...]# trust 01:02:03:04:05:06
Trusted 
[...]# 

Next and finally connect to the device (keyboard):

[...]# connect 01:02:03:04:05:06
Connection successful
[...]# 

Done.

Now the external device (i.e. keyboard) and the USB BT dongle are paired permanently, until you break the pairing manually. This does not mean that the keyboard will connect automatically to your BT device. This needs to be done after startup of your computer.

Enable Bluetooth Keyboard at Startup

Although the device and the controller are now paired, you need to connect them every time the computer starts.

First the device (i.e. BT Dongle) needs to be powered up. This is done with the hciconfig utility. We assume that you have only one BT device connected, and this one has the symbolic name hci0.

 # hciconfig hci0 up

Next, make the connection, now using the hcitool utility. Make sure that the keyboard is powered up and connectable, i.e. not in a power saving sleep state.

 # hcitool cc 01:02:03:04:05:06

Your BT keyboard should be useable now. Nex twe will discuss how to automate this with systemd.


Automatic start of a BT Keyboard

TBD



Xorg

Device should be added as /dev/input/event* and your Xorg should add it automatically if you did not disable such feature.