環境

1
2
3
4
5
6
$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 10 (buster)
Release: 10
Codename: buster

使ったもの

  • Bluetoothドングル: PLANEXのやつを使いました、何でもいいと思います。ラズパイに挿しておきます
  • Bluetoothキーボード: ThinkPad Bluetooth Trackpoint Keyboradを使いました、何でもいいと思います

必要なものインストール

たぶんそれぞれ依存関係にあると思いますが、とりあえず順番にインストールしたものを列挙してます

1
2
3
4
5
$ sudo apt update
$ sudo apt install -y bluetooth pi-bluetooth bluez

// 再起動
$ sudo reboot

スキャンしてみる(NG)

この時点では、 No default controller availableとなります

1
2
3
$ bluetoothctl
[bluetooth]# scan on
No default controller available

調べた

ログに、 Sap driver initialization failed.とエラーが出てる

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ sudo systemctl status bluetooth
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-12-08 22:28:43 JST; 1min 49s ago
Docs: man:bluetoothd(8)
Main PID: 359 (bluetoothd)
Status: "Running"
Tasks: 1 (limit: 4915)
CGroup: /system.slice/bluetooth.service
└─359 /usr/lib/bluetooth/bluetoothd

Dec 08 22:28:43 raspberrypi systemd[1]: Starting Bluetooth service...
Dec 08 22:28:43 raspberrypi bluetoothd[359]: Bluetooth daemon 5.50
Dec 08 22:28:43 raspberrypi bluetoothd[359]: Starting SDP server
Dec 08 22:28:43 raspberrypi bluetoothd[359]: Bluetooth management interface 1.14 initialized
Dec 08 22:28:43 raspberrypi bluetoothd[359]: Sap driver initialization failed.
Dec 08 22:28:43 raspberrypi bluetoothd[359]: sap-server: Operation not permitted (1)
Dec 08 22:28:43 raspberrypi systemd[1]: Started Bluetooth service.

piユーザが bluetoothグループに所属していないといけないようです

1
2
3
4
5
6
7
8
9
10
11
12
13
$ cat /etc/dbus-1/system.d/bluetooth.conf
<!-- This configuration file specifies the required security policies for Bluetooth core daemon to work. -->

(中略)

<!-- allow users of bluetooth group to communicate -->
<policy group="bluetooth">
<allow send_destination="org.bluez"/>
</policy>

(中略)

</busconfig>

という事で追加しました

1
2
3
4
$ sudo usermod -aG bluetooth pi

// 再起動
$ sudo reboot

スキャンしてみる(OK)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
$ bluetoothctl

// スキャンを開始
[bluetooth]# scan on
Discovery started
[CHG] Controller 00:1B:DC:08:77:5B Discovering: yes
[NEW] Device XX:XX:XX:XX:XX:XX 90-7F-61-11-42-72
[CHG] Device XX:XX:XX:XX:XX:XX LegacyPairing: no
[CHG] Device XX:XX:XX:XX:XX:XX Name: ThinkPad Compact Bluetooth Keyboard with TrackPoint // ←ペアリング対象が出てきた
[CHG] Device XX:XX:XX:XX:XX:XX Alias: ThinkPad Compact Bluetooth Keyboard with TrackPoint

// スキャンを停止
[bluetooth]# scan off
[CHG] Device XX:XX:XX:XX:XX:XX RSSI is nil
Discovery stopped

// ペアリングする
[bluetooth]# pair XX:XX:XX:XX:XX:XX
Attempting to pair with XX:XX:XX:XX:XX:XX
[CHG] Device XX:XX:XX:XX:XX:XX Connected: yes
[agent] Passkey: 461138 // ←Bluetoothキーボード側で入力してEnter
[agent] Passkey: 461138
[agent] Passkey: 461138
[agent] Passkey: 461138
[agent] Passkey: 461138
[agent] Passkey: 461138
[agent] Passkey: 461138
[CHG] Device XX:XX:XX:XX:XX:XX Modalias: usb:v17Exxxxxxxxxxx
[CHG] Device XX:XX:XX:XX:XX:XX UUIDs: 0000xxxx-0000-1000-8000-00xxxxxxxxxx
[CHG] Device XX:XX:XX:XX:XX:XX UUIDs: 0000xxxx-0000-1000-8000-00xxxxxxxxxx
[CHG] Device XX:XX:XX:XX:XX:XX UUIDs: 0000xxxx-0000-1000-8000-00xxxxxxxxxx
[CHG] Device XX:XX:XX:XX:XX:XX ServicesResolved: yes
[CHG] Device XX:XX:XX:XX:XX:XX Paired: yes
Pairing successful // ←つながった

// 次回から自動で接続する
[bluetooth]# trust XX:XX:XX:XX:XX:XX
[CHG] Device XX:XX:XX:XX:XX:XX Trusted: yes
Changing XX:XX:XX:XX:XX:XX trust succeeded

// 再起動
[bluetooth]# exit
$ sudo reboot