15
13

More than 5 years have passed since last update.

Raspberry Pi3 の Bluetooth を Ubuntu Mate 16.04 LTS で使えるようにする

Last updated at Posted at 2016-12-28

Overview

Raspberry Pi3 で Bluetooth を使おうとすると、意外とはまったので、そのまとめ。

$ sudo dmesg | grep -i blue
[  711.501303] Bluetooth: Core ver 2.20
[  711.505882] Bluetooth: HCI device and connection manager initialized
[  711.505899] Bluetooth: HCI socket layer initialized
[  711.505909] Bluetooth: L2CAP socket layer initialized
[  711.505931] Bluetooth: SCO socket layer initialized

のように出ているのに、

$ sudo hciconfig up
Can't get device info: No such device
$ sudo bluetoothctl
[bluetooth]# 

のまますすまないときに、この解決方法が役に立つかもです。

また、このとき、

sudo systemctl status bluetooth
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: inactive (dead)
Condition: start condition failed
           ConditionPathIsDirectory=/sys/class/bluetooth was not met
     Docs: man:bluetoothd(8)

のように、inactiveでもあるはずです。

対処方法

Bluetooth系のmoduleのinstall

$ sudo apt-get update
$ sudo apt-get install bluetooth bluez blueman -y 
$ sudo apt-get install bluez-btsco bluez-dbg bluez-hcidump bluewho indicator-bluetooth -y

Raspberry Pi3のfirmwareのupdate

$ sudo apt-get install rpi-update -y
$ sudo rpi-update
$ sudo reboot

rpi-updateでは、以下のようなメッセージが出ると思います.

 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** Performing self-update
 *** Relaunching after update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** We're running for the first time
 *** Backing up files (this will take a few minutes)
 *** Backing up firmware
 *** Backing up modules 4.1.18-v7+
This update bumps to rpi-4.4.y linux tree
Be aware there could be compatibility issues with some drivers
Discussion here:
https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=144087
##############################################################
 *** Downloading specific firmware revision (this will take a few minutes)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   168    0   168    0     0    106      0 --:--:--  0:00:01 --:--:--   106
100 51.8M  100 51.8M    0     0   730k      0  0:01:12  0:01:12 --:--:-- 1156k
 *** Updating firmware
 *** Updating kernel modules
 *** depmod 4.4.38-v7+
 *** depmod 4.4.38+
 *** Updating VideoCore libraries
 *** Using HardFP libraries
 *** Updating SDK
 *** Running ldconfig
 *** Storing current firmware revision
 *** Deleting downloaded files
 *** Syncing changes to disk
 *** If no errors appeared, your firmware was successfully updated to af9cb14d5053f89857225bd18d1df59a089c171e
 *** A reboot is needed to activate the new firmware

pi-bluetooth

http://ppa.launchpad.net/ubuntu-pi-flavour-makers/ppa/ubuntu

http://kakurasan.blogspot.jp/2015/04/how-to-add-ppa-repository.html
などを参考に、Ubuntu software centerなどで、ちゃんと有効になっているか確認しましょう。
(Updateのタイミングで無効になっていることも。。。)

$ sudo apt-get install pi-bluetooth

上などが有効になっていないとできないようです。

bluetooth serviceの起動

$ sudo systemctl start bluetooth
$ sudo systemctl status bluetooth
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running)
     Docs: man:bluetoothd(8)
 Main PID: 2327 (bluetoothd)
   Status: "Running"
   CGroup: /system.slice/bluetooth.service
           └─2327 /usr/lib/bluetooth/bluetoothd

systemd[1]: Starting Bluetooth service...
bluetoothd[2327]: Bluetooth daemon 5.37
systemd[1]: Started Bluetooth service.
bluetoothd[2327]: Starting SDP server
bluetoothd[2327]: Bluetooth management interface 1.10 initialized

rfkillでのunblock化

$ sudo rfkill unblock bluetooth
$ sudo hciconfig hci0 up

agentの有効化

$ sudo bluetoothctl
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent
Default agent request successful
[bluetooth]# scan on
[bluetooth]# exit

how to fix bluetoothd saying "not enough free handles..."

上のようにすると、$ sudo systemctl status bluetooth
してみると、エラーが出て起動できていないことがあるかと思います。

そのときは、

$ sudo apt-get install indicator-bluetooth

を再度実施したり、

/lib/systemd/system/bluetooth.service

-ExecStart=/usr/lib/bluetooth/bluetoothd
+ExecStart=/usr/lib/bluetooth/bluetoothd -E -d

のように、起動scriptを書き換えてみてください。

で、

$ sudo bluetoothctl
[Bluetooth] agent on
[Bluetooth] default-agent
[Bluetooth] scan on

で、ちゃんとしたmac addressが帰ってくればOkです。

やっと、これで、bluetoothを使ったhackの開発に入れる・・・。

それではenjoy bluetooth on Raspberry Pi3 with Ubuntu Mate 16.04 LTS!

ちなみに、Raspberry Pi3のUARTを使う方は以下のおまじないもしておいたほうが良いみたいです。

/boot/config.txt
core_freq=250

昨今のupdateで、なぜかhci0がupされていないようです。

/lib/systemd/system/bluetooth.service
[Service]
Type=dbus
BusName=org.bluez
+ExecStartPre=/usr/sbin/rfkill unblock bluetooth
+ExecStartPre=/usr/bin/hciconfig hci0 up
ExecStart=/usr/lib/bluetooth/bluetoothd

ExecStartPreをすれば以下は不要だが、ダメな場合は以下を。。。

/etc/rc.local
rfkill unblock bluetooth
/bin/hciconfig hci0 up

SAP (Sim Access Profile) の load で error する件 の 暫定対処

$ systemctl status bluetooth
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running)
     Docs: man:bluetoothd(8)
 Main PID: 1316 (bluetoothd)
   Status: "Running"
   CGroup: /system.slice/bluetooth.service
           └─1316 /usr/lib/bluetooth/bluetoothd

..snip..
bluetoothd[1316]: Sap driver initialization failed.
sap-server: Operation not permitted (1)

の対処方法

/lib/systemd/system/bluetooth.service
-ExecStart=/usr/lib/bluetooth/bluetoothd
+ExecStart=/usr/lib/bluetooth/bluetoothd --noplugin=sap
$ sudo systemctl daemon-reload
$ systemctl status bluetooth

のようにして、そもそも非サポートにする・・・どうせ動かないので、読み込まない方がマシ。。。

15
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
13