#author("2021-08-18T02:45:49+09:00","","")
#author("2021-08-19T01:57:20+09:00","","")
[[Raspberry Pi/Raspbian]]

* bluetooth ヘッドセット設定 [#mdf817db]

 apt install pi-bluetooth
 apt install bluealsa
 apt install pulseaudio pulseaudio-utils pulseaudio-module-bluetooth
** 必要なソフトをインストールする。 [#scd247a6]
 apt install pi-bluetooth bluealsa pulseaudio pulseaudio-utils pulseaudio-module-bluetooth

** タイマーベースのスケジューリングを無効にする [#zdda25a5]
 sudo vi /etc/pulse/default.pa

* [#gf722fba]
 sudo vi /etc/systemd/system/pulseaudio.service
-変更前
 load-module module-udev-detect
-変更後
 load-module module-udev-detect tsched=0

 [Unit] 
 Description=Pulse Audio 
 
 [Service] 
 Type=simple 
 ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disable-shm
 
 [Install]
 WantedBy=multi-user.target

 sudo systemctl start pulseaudio.service
 sudo systemctl enable pulseaudio.service
** org.bluez を許可する [#p018b0c1]
 sudo vi /etc/dbus-1/system.d/bluetooth.conf

-変更前
 <policy context="default"
   <deny send_destination="org.bluez"/>
 </policy>
-変更後
 <policy context="default"
   <allow send_destination="org.bluez"/>
 </policy>

** bluetooth サービス起動設定 [#x0182506]
 sudo vi /lib/systemd/system/bluetooth.service
下記変更する。
-変更前
 ExecStart=/usr/lib/bluetooth/bluetoothd
-変更後
 ExecStart=/usr/lib/bluetooth/bluetoothd --noplugin=sap -E
 ExecStartPre=/usr/sbin/rfkill unblock bluetooth

** bluetooth サービス起動 [#u4778d36]
 service bluetooth start

** bluetooth サービス状態確認 [#eb011bbf]
 service bluetooth status
 or
 systemctl status bluetooth


** 接続してみる [#b23af713]
 $ pulseaudio --start
 $ sudo bluetoothctl
 [bluetooth]# scan on               <-- スキャン開始
 [bluetooth]# pair [アドレス]       <-- アドレスを指定してペアリングする
 [bluetooth]# trust [アドレス]      <-- アドレスを指定して信頼されたデバイスとする
 [bluetooth]# scan off
 [bluetooth]# connect [アドレス]    <-- アドレスを指定して接続する
 [bluetooth]# quit
 
 <その他 bluetoothctl で使うコマンド>
 [bluetooth]# devices               <-- デバイス一覧表示
 [bluetooth]# paired-devices        <-- ペアリング設定されたデバイス表示
 [bluetooth]# info [アドレス]       <-- 指定したデバイス情報表示
 [bluetooth]# disconnect [アドレス] <-- 切断
 [bluetooth]# remove [アドレス]     <-- デバイス削除

* 接続 [#x1a2f425]
 bluetoothctl
- スキャン開始
 scan on
- スキャン終了
 scan off
- デバイス一覧表示
 devices
- ペアリング
 pair [デバイスのアドレス]
- ペアリング解除
 remove [デバイスのアドレス]
- 接続
 connect [デバイスのアドレス]
 ※通常 pair にて connect までされる。
- 切断
 disconnect [デバイスのアドレス]
- 終了
 quit
** bluetooth サービスの自動起動設定 [#oaea568c]
 sudo systemctl enable bluetooth.service

* [#l103f189]
/lib/systemd/system/bluetooth.service の bluetoothd に --noplugin=sap オプションをつける
** 以降、起動時は、下記実施で [#o18bdc61]
 pulseaudio --start
 sudo bluetoothctl
 [bluetooth]# connect [アドレス]

 [Service]
 Type=dbus
 BusName=org.bluez
 ExecStart=/usr/lib/bluetooth/bluetoothd --noplugin=sap
** pulseaudio 停止 [#j11e62d2]
 pulseaudio --kill


* ログ確認 [#f5212824]
 systemctl status bluetooth
*その他 [#p7b7ff6f]

** bluetooth のヘッドセット接続できているか確認 [#h5967325]
 pacmd list

** 音を鳴らす [#tcec7062]
 aplay [webファイル]

*うまくいかないとき [#n3b3c0b0]
 pacmd list で認識しているけど、aplay で再生されない場合
 pulseaudio --kill
 pulseaudio --start
 sudo systemctl
 connect [アドレス]
でうまくいくか試してみる

トップ   一覧 検索 最終更新   ヘルプ   最終更新のRSS