Difference between revisions of "Bluetooth keyboard"

From ArchWiki
Jump to: navigation, search
(Bluetooth Keyboard at Startup: 2nd appearance error, removed)
(Restructuring of formatting, correct templates etc.)
Line 2: Line 2:
 
[[Category:Keyboards]]
 
[[Category:Keyboards]]
 
[[ru:Bluetooth Keyboard]]
 
[[ru:Bluetooth Keyboard]]
{{Stub|Unfinished, missing references.}}
 
 
== Bluetooth Keyboard Pairing Process ==
 
  
 
This article describes how to set up a Bluetooth HID keyboard with Arch Linux, bluez version 5.
 
This article describes how to set up a Bluetooth HID keyboard with Arch Linux, bluez version 5.
  
 +
== Bluetooth Keyboard Pairing Process ==
  
 
+
First, make sure the local BT controller (e.g. a BT dongle the built in BT radio) is recognized:
Make sure the local BT controller (e.g. a BT dongle the built in BT radio) is recognized:
+
{{hc|# lsusb|
{{bc|# lsusb
+
 
Bus 001 Device 004: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
 
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 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Line 20: Line 17:
 
The above output is from a Raspberry-Pi revision 'B' with archlinux-arm and a Keysonic BT Dongle.
 
The above output is from a Raspberry-Pi revision 'B' with archlinux-arm and a Keysonic BT Dongle.
  
Start bluetooth service (as root):
+
Start bluetooth service with '''systemctl''', or even better, enable it permanently in the start up process. See [[systemd]].
{{bc|# systemctl start bluetooth}}
+
  
If you are sure you want to have Bluetooth available after every booth automatically, permanently enable the service (as root):
+
Three items worth remembering:
{{bc|# systemctl enable bluetooth}}
+
* BT devices (keyboard) and controllers (dongle) need to be paired once.
 +
* The BT controller needs to be powered up after every boot.
 +
* The BT controller needs to be told to connect to the keyboard after every boot.
  
Two items worth remembering:
+
''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 {{ic|bluetoothctl}} command from bluez5 to pair our dongle and the keyboard.
* 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 be done with {{ic|bluetoothctl}}, or with {{ic|hciconfig}} which is more suitable for scripting. See below.
  
'''Power up''' can also be done with '''bluetoothctl''', or with '''hciconfig''' which is more suitable for scripting. See below.
+
Same for ''connecting'', either {{ic|bluetoothctl}} or {{ic|hcitool}} can be used, the latter is more useful for scripting.
  
  
We will use '''bluetoothctl''' for the pairing process:
+
We will use {{ic|bluetoothctl}} for the pairing process:
  
{{bc|# bluetoothctl -a}}
+
{{hc|# bluetoothctl -a|
 +
[bluetooth]#
 +
}}
 
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.
 
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:
 
While in '''bluetoothctl''' power up the controller:
{{bc|[...]# power on
+
{{hc|[bluetooth]# power on|
 
Changing power on succeeded
 
Changing power on succeeded
[CHG] Controller 00:15:83:12:30:16 Powered: yes
+
[CHG] Controller 06:05:04:03:02:01 Powered: yes
[...]#
+
[bluetooth]#
 
}}
 
}}
  
Next, tell bluetoothctl to look only for keyboards, and make that the default agent:
+
Next, tell {{ic|bluetoothctl}} to look only for keyboards, and make that the default agent:
{{bc|[...]# agent KeyboardOnly
+
{{hc|[bluetooth]# agent KeyboardOnly|
 
Agent registered
 
Agent registered
[...]# default-agent
+
[bluetooth]# default-agent
 
Default agent request successful
 
Default agent request successful
[...]#  
+
[bluetooth]#  
 
}}
 
}}
  
 
Next, put your controller (the local dongle) in 'pairable' mode:
 
Next, put your controller (the local dongle) in 'pairable' mode:
{{bc|[...]# pairable on
+
{{hc|[bluetooth]# pairable on|
 
Changing pairable on succeeded
 
Changing pairable on succeeded
[...]#  
+
[bluetooth]#  
 
}}
 
}}
  
Line 64: Line 62:
  
 
Next, let the controller scan the BT frequencies for a suitable device:
 
Next, let the controller scan the BT frequencies for a suitable device:
{{bc|[...]# scan on
+
{{hc|[bluetooth]# scan on|
 
Discovery started
 
Discovery started
[CHG] Controller 00:15:83:12:30:16 Discovering: yes
+
[CHG] Controller 06:05:04:03:02:01 Discovering: yes
[...]#  
+
[bluetooth]#  
 
}}
 
}}
  
Line 73: Line 71:
  
 
Next, actually do the pairing. The address used is the BT-MAC address of the keyboard:
 
Next, actually do the pairing. The address used is the BT-MAC address of the keyboard:
{{bc|[...]# pair 01:02:03:04:05:06
+
{{hc|[bluetooth]# pair 01:02:03:04:05:06|
 
Pairing successful
 
Pairing successful
[...]#  
+
[bluetooth]#  
 
}}
 
}}
  
Next, make this a trusted device (the author does not know the effects of this command, but it seems to be required):
+
Next, make this a trusted device (the author does not know the effects of this command, but it seems to be required). Again, the BT-MAC address is the address of the keyboard device:
{{bc|[...]# trust 01:02:03:04:05:06
+
{{hc|[bluetooth]# trust 01:02:03:04:05:06|
 
Trusted  
 
Trusted  
[...]#  
+
[bluetooth]#  
 
}}
 
}}
  
Next and finally connect to the device (keyboard):
+
Next and finally connect to the device (keyboard). Again, the BT-MAC address is the address of the keyboard device:
{{bc|[...]# connect 01:02:03:04:05:06
+
{{hc|[bluetooth]# connect 01:02:03:04:05:06|
 
Connection successful
 
Connection successful
[...]#  
+
[bluetooth]#  
 
}}
 
}}
  
'''Done.'''
+
'''Done.''' Leave the {{ic|bluetoothctl}} utility:
 
+
{{hc|[bluetooth]# quit|
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'''.
+
  
 +
Now the external device (i.e. keyboard) and the USB BT dongle are paired permanently, unless you break the pairing intenionally. This does not mean that the keyboard will connect automatically to your BT device after a boot. ''Power up'' of the controller and ''connecting'' device and controller needs to be done after every startup of your computer.
  
== Automatic start of a BT Keyboard ==
+
== Manually enabling a Bluetooth Keyboard ==
  
TBD
+
Although the device and the controller are now paired (see above), you need to connect them every time the computer starts.
  
 +
First the BT controller (i.e. BT Dongle) needs to be powered up. This is done with the {{ic|hciconfig}} utility. We assume that you have only one BT device connected, and this one has the symbolic name '''hci0'''.
 +
{{hc| # hciconfig hci0 up| #}}
  
 +
Next, make the connection, now using the {{ic|hcitool}} utility. Make sure that the keyboard is powered up and connectable, i.e. not in a power saving sleep state.
 +
{{hc| # hcitool cc 01:02:03:04:05:06| <# prompt or possible error message here>}}
  
 +
Your BT keyboard should be useable now, even if an error message ("Can't create connection: Input/output error") is shown. Next we will discuss how to automate this process with [[systemd]].
  
 +
== Automatically enabling a Bluetooth Keyboard ==
 +
{{Expansion|Needs more investigation. So many toys, so little time.}}
  
 
== Xorg ==
 
== Xorg ==
 
Device should be added as /dev/input/event* and your Xorg should add it automatically if you did not disable such feature.
 
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 18:09, 2 December 2013


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

Bluetooth Keyboard Pairing Process

First, 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 with systemctl, or even better, enable it permanently in the start up process. See systemd.

Three 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.
  • The BT controller needs to be told to connect to the keyboard 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 be done with bluetoothctl, or with hciconfig which is more suitable for scripting. 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:

# bluetoothctl -a
[bluetooth]#

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:

[bluetooth]# power on
Changing power on succeeded
[CHG] Controller 06:05:04:03:02:01 Powered: yes
[bluetooth]#

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
[bluetooth]# 

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

[bluetooth]# pairable on
Changing pairable on succeeded
[bluetooth]# 

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:

[bluetooth]# scan on
Discovery started
[CHG] Controller 06:05:04:03:02:01 Discovering: yes
[bluetooth]# 

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:

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

Next, make this a trusted device (the author does not know the effects of this command, but it seems to be required). Again, the BT-MAC address is the address of the keyboard device:

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

Next and finally connect to the device (keyboard). Again, the BT-MAC address is the address of the keyboard device:

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

Done. Leave the bluetoothctl utility:

[bluetooth]# quit
 # 

Now the external device (i.e. keyboard) and the USB BT dongle are paired permanently, unless you break the pairing intenionally. This does not mean that the keyboard will connect automatically to your BT device after a boot. Power up of the controller and connecting device and controller needs to be done after every startup of your computer.

Manually enabling a Bluetooth Keyboard

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

First the BT controller (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
 <# prompt or possible error message here>

Your BT keyboard should be useable now, even if an error message ("Can't create connection: Input/output error") is shown. Next we will discuss how to automate this process with systemd.

Automatically enabling a Bluetooth Keyboard

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: Needs more investigation. So many toys, so little time. (Discuss in Talk:Bluetooth keyboard#)

Xorg

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