Showing posts with label without GUI. Show all posts
Showing posts with label without GUI. Show all posts

Sunday, 20 March 2016

Pairing Bluetooth Keyboard with Raspberry Pi 3, without GUI

In brief 

The latest Raspberry Pi 3 now comes with its own built in  Bluetooth 4.1/Low Energy (LE) support. Here below, I just share how I did the pairing between my bluetooth keyboard and the raspberry pi.

Infrastructure  

- Raspberry Pi 3, running Raspbian Jessie Lite
- Bluetooth Keyboard (in my case Active Strike Pro mini )
- On my laptop, I run Debian 8
- The Raspberry Pi 3 (rpi) is already connected through the Wi-Fi and it has a static local IP assigned (192.168.0.28). Therefore I could accept any time the rpi via SSH :
  $ ssh pi@192.168.0.28



Steps

1. Install the BlueTooth library on rpi as a 'pi' user :
 $ sudo apt-get update
 $ sudo apt-get upgrade
 $ sudo apt-get install bluetooth


2. On the rpi, start the interactive bluetoothctl command line (as a pi user NOT AS ROOT):
 $ bluetoothctl -a
 [NEW] Controller B8:27:EB:1A:8A:A7 raspberrypi [default]
 Agent registered
 [bluethooth]# 

 3. Power up the controller:
  [bluethooth]# power on
  Changing power on succeeded
  [CHG] Controller B8:27:EB:1A:8A:A7 Powered: yes

 4. Set the controller to look only for keyboards:
  [bluethooth]# agent KeyboardOnly
  Agent registered

5. Set the controller to make the keyboard as a default agent:
  [bluethooth]# default-agent
  Default agent request successful
6. Set the controller in the 'pairable' mode:
  [bluethooth]# pairable on
  Changing pairable on succeeded

7. Enable the 'pairing mode' of your Bluetooth Keyboard (in Active Strike Pro mini, by pressing :  Fn + C) and scan with your rpi controller:
  [bluethooth]# scan on
  Discovery started
  [CHG] Controller B8:27:EB:1A:8A:A7 Discovering: yes
  [NEW] Device 20:73:00:16:12 Bluetooth 3.0 Keyboard 
  ... 

8. Do the pairing, wait for the PIN code:
  [bluethooth]# pair 20:73:00:16:12
  Attempting to pair with 20:73:00:16:12
  [CHG] Device 20:73:00:16:12 Connected: yes
  [agent] PIN code: 785148
9. Quickly, type the PIN code on the keyboard and press Enter:
  [CHG] Device 20:73:00:16:12 Modalias: usb:v04E8p7021d011B
  [CHG] Device 20:73:00:16:12 UUIDs
           0001000-0000-8000-00805f9b34fb
  [CHG] Device 20:73:00:16:12 Paired: Yes   
  Pairing successful  

10. Make the device a trusted device
  [bluethooth]# trust 20:73:00:16:12
  [CHG] Device 20:73:00:16:12 trust succeeded
  Changing 20:73:00:16:12 trust succeeded

11. Connect to the device
  [bluethooth]# connect 20:73:00:16:12
  Attempting to connect with 20:73:00:16:12 

  [CHG] Device 20:73:00:16:12 Connected: yes
  Connection successful

12. Leave the bluetoothctl command line
  [bluethooth]# quit

Done !