旧 #temanote

Linux大好き。だけど進捗ありません。

RaspberryPi 3B+/Raspbian LiteでBluetoothオーディオレシーバー作成

参考 qiita.com

Raspbian LiteでのBluetoothレシーバーの構築に成功したのでメモ

検証環境

  • Raspberry Pi 3B+
  • Raspbian Lite
    • 2019-04-08-raspbian-stretch-lite

Raspbian Liteセットアップ

Raspbianのセットアップ、インターネットへの接続は省略

パッケージのインストール

# apt update && sudo apt upgrade
# apt install bluez pulseaudio-module-bluetooth mpd

mpdの有効化

mpdはpulseaudioを建てるためだけに利用します

/etc/mpd.conf

デフォルトで有効になっているalsaコメントアウトし、pulseaudioのコメントアウトを外す

#audio_output {
#   type        "alsa"
#   name        "My ALSA Device"
#   device      "hw:0,0"    # optional
#   mixer_type      "hardware"      # optional
#   mixer_device    "default"   # optional
#   mixer_control   "PCM"       # optional
#   mixer_index "0"     # optional
#}

audio_output {
    type        "pulse"
    name        "My Pulse Output"
#   server      "remote_server"     # optional
#   sink        "remote_server_sink"    # optional
}

mpd有効化

# usermod -G bluetooth mpd
# systemctl enable mpd

bluetooth設定

bluetoothのコントローラーにaudio-sinkを追加するための権限をbluetoothグループに渡す

/etc/dbus-1/system.d/bluetooth.conf

bluetoothのpolicyにorg.bluez.MediaPlayer1の行を追加

  <policy group="bluetooth">
    <allow send_destination="org.bluez"/>
    <allow send_interface="org.bluez.MediaPlayer1"/>
  </policy>

/etc/bluetooth/audio.conf

デフォルトだとファイルがないので新規作成してA2DP関連のProfileを使えるように設定

[General]
Enable=Source,Sink,Media,Socket

bluetooth.serviceを再起動、mpdを起動してペアリング
showでAudio Sinkがあることを確認、なければmpdかpulseaudioが建っていない可能性アリ

# systemctl restart bluetooth
# systemctl restart mpd
# bluetoothctl
[NEW] Controller XX:XX:XX:XX:XX:XX raspberrypi [default]
[Bluetooth]# show
Controller XX:XX:XX:XX:XX:XX
    Name: raspberrypi
    Alias: raspberrypi
    Class: 0x0c0000
    Powered: yes
    Discoverable: no
    Pairable: yes
    UUID: Headset AG                (00001112-0000-1000-8000-00805f9b34fb)
    UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
    UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
    UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
    UUID: Audio Sink                (0000110b-0000-1000-8000-00805f9b34fb)
    UUID: Audio Source              (0000110a-0000-1000-8000-00805f9b34fb)
    Modalias: usb:xxxxxxxxxxxxxxx
    Discovering: no
[Bluetooth]# discovering on
(Bluetooth接続したい機器から接続、失敗してログにMACアドレスが出るのにtrustとpair)
[Bluetooth]# trust YY:YY:YY:YY:YY:YY
[Bluetooth]# pair YY:YY:YY:YY:YY:YY
(再び機器から接続)

以降は機器側から接続するだけでOK

これでBluetoothレシーバーとして機能するはず。
pulseaudioを建てるためだけにMPDを使ってるのが悔しい