Project

General

Profile

Support #810

Updated by Daniel Curtis almost 8 years ago

This is a guide on how I setup a bluetooth keyboard on Arch Linux. 

 h2. Prepare the Environment 

 * Make sure the system is up to date: 
 <pre> 
 sudo pacman -Syu 
 </pre> 

 h2. Install Bluetooth 

 * Install the bluez packages: 
 <pre> 
 sudo pacman -S bluez bluez-utils 
 </pre> 

 * Start and enable the bluetooth service at boot: 
 <pre> 
 sudo systemctl enable bluetooth 
 sudo systemctl start bluetooth 
 </pre> 

 * Use @bluetoothctl@ for the pairing process: 
 <pre> 
 bluetoothctl -a 
 </pre> 
 #* While in bluetoothctl power up the controller: 
 <pre> 
 power on 
 </pre> 
 #* Next, tell bluetoothctl to look only for keyboards, and make that the default agent: 
 <pre> 
 agent KeyboardOnly 
 default-agent 
 </pre> 
 #* Next, put the controller (the local dongle) in pairable mode: 
 <pre> 
 pairable on 
 </pre> 
 #* Next, put the +keyboard in an active mode+, where it is *discoverable*, i.e. pairable.  
 #* Then, let the controller scan the BT frequencies for a suitable device: 
 <pre> 
 scan on 
 </pre> 
 #* Next, actually do the pairing. The address used is the BT-MAC address of the keyboard: 
 <pre> 
 pair 01:02:03:04:05:06 
 </pre> 
 #* Next, make this a trusted device (this allows the device to establish the connection on itself). Again, the BT-MAC address is the address of the keyboard device: 
 <pre> 
 trust 01:02:03:04:05:06 
 </pre> 
 #* Finally connect to the device (keyboard). Again, the BT-MAC address is the address of the keyboard device: 
 <pre> 
 connect 01:02:03:04:05:06 
 </pre> 
 #* Leave the bluetoothctl utility: 
 <pre> 
 quit 
 </pre> 

 h2. Automatically enabling a Bluetooth Keyboard 

 *NOTE*: Remember that you have to pair and trust your device in bluetoothctl to cause autoconnect. 

 Custom systemd service file: 

 * Create a bluetooth keyboard config file: 
 <pre> 
 sudo vi /etc/btkbd.conf 
 </pre> 
 #* And add the following: 
 <pre> 
 # Config file for btkbd.service 
 # change when required (e.g. keyboard hardware changes, more hci devices are connected) 
 BTKBDMAC = "01:02:03:04:05:06" 
 HCIDEVICE = "hci0" 
 </pre> 

 * Next, create a new bluetooth keyboard service file: 
 <pre> 
 sudo vi /etc/systemd/system/btkbd.service 
 </pre> 
 #* And add the following: 
 <pre> 
 [Unit] 
 Description=systemd Unit to automatically start a Bluetooth keyboard 
 Documentation=https://wiki.archlinux.org/index.php/Bluetooth_Keyboard 
 Requires=dbus-org.bluez.service 
 After=dbus-bluez.org.service 
 ConditionPathExists=/etc/btkbd.conf 
 ConditionPathExists=/usr/bin/hcitool 
 ConditionPathExists=/usr/bin/hciconfig 

 [Service] 
 Type=oneshot 
 EnvironmentFile=/etc/btkbd.conf 
 ExecStart= 
 ExecStart=/usr/bin/hciconfig ${HCIDEVICE} up 
 # ignore errors on connect, spurious problems with bt? so start next command with - 
 ExecStart=-/usr/bin/hcitool cc ${BTKBDMAC} 

 [Install] 
 WantedBy=multi-user.target 
 And then enable this service with systemd's tools. 
 </pre> 

 * Then reload systemd and enable the service at boot: 
 <pre> 
 sudo systemctl daemon-reload 
 sudo systemctl enable btkbd 
 sudo systemctl start btkbd 
 </pre> 

 h2. Resources 

 * https://wiki.archlinux.org/index.php/bluetooth 
 * https://wiki.archlinux.org/index.php/bluetooth_keyboard

Back