Project

General

Profile

Support #810

Setup a Bluetooth Keyboard on Arch Linux

Added by Daniel Curtis over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Workstation
Target version:
Start date:
05/13/2016
Due date:
% Done:

100%

Estimated time:
0.50 h
Spent time:

Description

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

Prepare the Environment

  • Make sure the system is up to date:
    sudo pacman -Syu
    

Install Bluetooth

  • Install the bluez packages:
    sudo pacman -S bluez bluez-utils
    
  • Start and enable the bluetooth service at boot:
    sudo systemctl enable bluetooth
    sudo systemctl start bluetooth
    
  • Use bluetoothctl for the pairing process:
    bluetoothctl -a
    
    • While in bluetoothctl power up the controller:
      power on
      
    • Next, tell bluetoothctl to look only for keyboards, and make that the default agent:
      agent KeyboardOnly
      default-agent
      
    • Next, put the controller (the local dongle) in pairable mode:
      pairable on
      
    • 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:
      scan on
      
    • Next, actually do the pairing. The address used is the BT-MAC address of the keyboard:
      pair 01:02:03:04:05:06
      
    • 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:
      trust 01:02:03:04:05:06
      
    • Finally connect to the device (keyboard). Again, the BT-MAC address is the address of the keyboard device:
      connect 01:02:03:04:05:06
      
    • Leave the bluetoothctl utility:
      quit
      

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:
    sudo vi /etc/btkbd.conf
    
    • And add the following:
      # 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" 
      
  • Next, create a new bluetooth keyboard service file:
    sudo vi /etc/systemd/system/btkbd.service
    
    • And add the following:
      [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
      
  • Then reload systemd and enable the service at boot:
    sudo systemctl daemon-reload
    sudo systemctl enable btkbd
    sudo systemctl start btkbd
    

Resources

#1

Updated by Daniel Curtis over 8 years ago

  • Description updated (diff)
  • Status changed from New to Resolved
  • % Done changed from 0 to 100
#2

Updated by Daniel Curtis over 8 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF