2017年8月30日水曜日

RPi_0029 PulseAudio

Raspberry Pi3からBluetoothスピーカにペアリングして音楽再生する。
なおPiZeroWで同じ設定をしたが非力で音飛びするようだった。

以下のWebページの内容をトレースして設定した。
《参照》
Raspberry PI 3 で Bluetooth(A2DP)
http://qiita.com/nattof/items/3db73a95e63100d7580a

(1) PulseAudioのインストール

# apt-get install pulseaudio-module-bluetooth

(2) PulseAudioの設定

3つのファイルを設定する。
○その1
# cat << EOF > /etc/systemd/system/pulseaudio.service
[Unit]
Description=Pulse Audio

[Service]
Type=simple
ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disable-shm

[Install]
WantedBy=multi-user.target
EOF
○その2
# cat << EOF > /etc/dbus-1/system.d/pulseaudio-bluetooth.conf
<busconfig>

  <policy user="pulse">
    <allow send_destination="org.bluez"/>
  </policy>

</busconfig>
EOF
○その3
# cat << EOF >> /etc/pulse/system.pa

### Automatically load driver modules for Bluetooth hardware
.ifexists module-bluetooth-policy.so
load-module module-bluetooth-policy
.endif

.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif
EOF

(3) 使用したbluetoothスピーカ


2年くらい前にSoftBankのキャンペーンでもらったOnyx Studioと、ことしの1月にauのキャンペーンでもらった座布団つきのGH-OTOMO。ともに再生は確認できたが、GH-OTOMOはボリュームがないので、AlsaMixerでの音量調整が必要。

(4) PulseAudioの起動

○pulseaudioサービスを起動
  # systemctl start pulseaudio.service
○pulseaudioサービスを自動で起動
  # systemctl enable pulseaudio.service
○bluetoothの再起動
  # /etc/init.d/bluetooth restart
[ ok ] Restarting bluetooth (via systemctl): bluetooth.service.

(5) bluetoothスピーカへの接続

bluetoothスピーカとペアリングして接続する
# bluetoothctl #bluetoothコントロールツール
[NEW] Controller 43:43:A1:12:AA:AA rapi3 [default]

[bluetooth]# scan on #スキャン開始
Discovery started
[CHG] Controller 43:43:A1:12:AA:AA Discovering: yes
[NEW] Device 0C:A6:94:0D:ZZ:ZZ HK Onyx Studio

[bluetooth]# pair 0C:A6:94:0D:ZZ:ZZ  #Onyx Studioとペアリング
Attempting to pair with 0C:A6:94:0D:ZZ:ZZ
[CHG] Device 0C:A6:94:0D:ZZ:ZZ Connected: yes
[CHG] Device 0C:A6:94:0D:ZZ:ZZ Paired: yes
Pairing successful

[bluetooth]# connect 0C:A6:94:0D:ZZ:ZZ #Onyx Studioに接続
Attempting to connect to 0C:A6:94:0D:ZZ:ZZ
[CHG] Device 0C:A6:94:0D:ZZ:ZZ Connected: yes
Connection successful

[bluetooth]# trust 0C:A6:94:0D:ZZ:ZZ #Onyx Studioを信頼
[CHG] Device 0C:A6:94:0D:ZZ:ZZ Trusted: yes
Changing 0C:A6:94:0D:ZZ:ZZ trust succeeded

[bluetooth]# info 0C:A6:94:0D:ZZ:ZZ #Onyx Studioの接続情報
Device 0C:A6:94:0D:ZZ:ZZ
 Name: HK Onyx Studio
 Alias: HK Onyx Studio
 Class: 0x240414
 Icon: audio-card
 Paired: yes
 Trusted: yes
 Blocked: no
 Connected: yes
 LegacyPairing: no
 UUID: Audio Sink                (XXX..XXX)
 UUID: A/V Remote Control Target (XXX..XXX)
 UUID: A/V Remote Control        (XXX..XXX)
[bluetooth]# scan off #スキャン終了
Discovery stopped
[CHG] Controller 43:43:A1:12:AA:AA Discovering: no
[bluetooth]# devices #検出したデバイス
Device 08:62:66:17:XX:XX 2F_NPlayer_2nd
Device 08:62:66:17:YY:YY 1F_NPlayer_1st
Device FC:58:FA:00:ZZ:ZZ GH-OTOMO
Device 0C:A6:94:0D:ZZ:ZZ HK Onyx Studio
[bluetooth]#

[bluetooth]# quit #終了
[DEL] Controller 43:43:A1:12:AA:AA rapi3 [default]

音を出すユーザーを「pulse-access」グループに追加
# gpasswd -a root pulse-access
# gpasswd -a user pulse-access
# grep pulse-access /etc/group
pulse-access:x:117:root,user #追加されたユーザを見る

(6) mplayerでの再生例

●1 bluetoothスピーカ再生
# mplayer --ao=pulse /usr/local/etc/mdetect/Mp3/01_Beautiful_World.mp3
# mplayer --ao=pulse 01_FIGHT_WITH_LOVE.m4a
●2 ミニプラグジャック再生
# mplayer --ao=alsa /usr/local/etc/mdetect/Mp3/01_Beautiful_World.mp3
●3 MUSIC BIRDデジタル音楽放送 岡山県 コミュニティFM レディオ モモ
# mplayer --ao=pulse --cache=900 --quiet 'http://musicbird-hls.leanstream.co/musicbird/JCB079.stream/playlist.m3u8?args=web_03'


2017年8月22日火曜日

RPi_0028 samba

(1) sambaのインストール

# apt-get install samba

(2) sambaの設定

設定ファイル smb.confを変更する。
# cp -p /etc/samba/smb.conf /etc/samba/smb.conf.org
# vi /etc/samba/smb.conf
にて、次の箇所をファイルの最後に追加する。

# diff -u /etc/samba/smb.conf.org /etc/samba/smb.conf
--- /etc/samba/smb.conf.org 2017-08-21 21:52:00.289168125 +0900
+++ /etc/samba/smb.conf 2017-08-21 21:57:37.187616391 +0900
@@ -252,3 +252,10 @@
 # to the drivers directory for these users to have write rights in it
 ;   write list = root, @lpadmin

+[mypiuser]
+path = /home/mypiuser
+read only = No
+browsable = yes
+guest ok = Yes
+force user = mypiuser

○ samba パスワードの変更
# smbpasswd -a mypiuser
New SMB password:
Retype new SMB password:
Added user mypiuser.

○ sambaを再起動させる
# /etc/init.d/samba restart
[ ok ] Restarting nmbd (via systemctl): nmbd.service.
[ ok ] Restarting smbd (via systemctl): smbd.service.
[ ok ] Restarting samba-ad-dc (via systemctl): samba-ad-dc.service.
macOSからは、Finderで、移動>サーバへ接続
サーバアドレス:smb://rapi3.local/mypiuser

windowsからは、エクスプローラから、ネットワーク
\\rapi3.local\mypiuser

とかでネットワーク越しにファイル操作できるようになる。