我が家の寝室には、ソニーのMD/CD/ラジカセ・コンポが置いてあります。 MDドライブは調子が悪くなって使っていません。 主に、タイマー機能で目覚ましにNACK5(埼玉のFM放送)を鳴らすことくらいです。
もしもこの機能を実現できるなら、RaspyFIでコンポを置き換えることが可能です。
ここではそのものズバリのお手本(参考サイト15)を元に設定していきます。
ソフトウェアの導入の前に、パッケージツリーを最新にします。
updateだけで、upgradeはしません。
root@Raspyfi:~# apt-get update
Get:1 http://archive.raspberrypi.org wheezy Release.gpg [490 B]
Get:2 http://mirrordirector.raspbian.org wheezy Release.gpg [490 B]
Get:3 http://archive.raspberrypi.org wheezy Release [7,218 B]
Get:4 http://archive.raspbian.org wheezy Release.gpg [490 B]
Get:5 http://mirrordirector.raspbian.org wheezy Release [14.4 kB]
Get:6 http://archive.raspbian.org wheezy Release [14.4 kB]
Get:7 http://archive.raspbian.org wheezy/main Sources [6,252 kB]
Get:8 http://mirrordirector.raspbian.org wheezy/main Sources [6,252 kB]
Get:9 http://archive.raspberrypi.org wheezy/main armhf Packages [10.4 kB]
Ign http://archive.raspberrypi.org wheezy/main Translation-en_GB
Ign http://archive.raspberrypi.org wheezy/main Translation-en
Get:10 http://mirrordirector.raspbian.org wheezy/main armhf Packages [7,415 kB]
Get:11 http://archive.raspbian.org wheezy/contrib Sources [52.7 kB]
Get:12 http://archive.raspbian.org wheezy/non-free Sources [97.6 kB]
Get:13 http://archive.raspbian.org wheezy/rpi Sources [569 B]
Get:14 http://archive.raspbian.org wheezy/main armhf Packages [7,415 kB]
Ign http://mirrordirector.raspbian.org wheezy/main Translation-en_GB
Ign http://mirrordirector.raspbian.org wheezy/main Translation-en
Get:15 http://archive.raspbian.org wheezy/contrib armhf Packages [23.3 kB]
Get:16 http://archive.raspbian.org wheezy/non-free armhf Packages [48.0 kB]
Get:17 http://archive.raspbian.org wheezy/rpi armhf Packages [569 B]
Ign http://archive.raspbian.org wheezy/contrib Translation-en_GB
Ign http://archive.raspbian.org wheezy/contrib Translation-en
Ign http://archive.raspbian.org wheezy/main Translation-en_GB
Ign http://archive.raspbian.org wheezy/main Translation-en
Ign http://archive.raspbian.org wheezy/non-free Translation-en_GB
Ign http://archive.raspbian.org wheezy/non-free Translation-en
Ign http://archive.raspbian.org wheezy/rpi Translation-en_GB
Ign http://archive.raspbian.org wheezy/rpi Translation-en
Fetched 27.6 MB in 6min 47s (67.7 kB/s)
Reading package lists... Done
順番は関係ないですが、mplayer から導入していきます。
root@Raspyfi:~# apt-get install mplayer
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
esound-common fontconfig-config libaa1 libaacs0 libbluray1 libcaca0
libcdparanoia0 libdca0 libdirectfb-1.2-9 libdrm-nouveau1a libdrm-radeon1
libdrm2 libdvdnav4 libdvdread4 libenca0 libesd0 libfontconfig1 libfribidi0
libgif4 libgl1-mesa-dri libgl1-mesa-glx libglapi-mesa liblircclient0
liblzo2-2 libmpeg2-4 libopenal-data libopenal1 libpostproc52 libsdl1.2debian
libsmbclient libswscale2 libts-0.0-0 libxcb-glx0 libxdamage1 libxfixes3
libxinerama1 libxv1 libxvmc1 libxxf86dga1 libxxf86vm1 tsconf ttf-dejavu-core
Suggested packages:
libbluray-bdj libdvdcss2 pulseaudio-esound-compat libglide3 lirc
libportaudio2 libroar-compat2 fontconfig mplayer-doc netselect fping
ttf-freefont
The following NEW packages will be installed:
esound-common fontconfig-config libaa1 libaacs0 libbluray1 libcaca0
libcdparanoia0 libdca0 libdirectfb-1.2-9 libdrm-nouveau1a libdrm-radeon1
libdrm2 libdvdnav4 libdvdread4 libenca0 libesd0 libfontconfig1 libfribidi0
libgif4 libgl1-mesa-dri libgl1-mesa-glx libglapi-mesa liblircclient0
liblzo2-2 libmpeg2-4 libopenal-data libopenal1 libpostproc52 libsdl1.2debian
libsmbclient libswscale2 libts-0.0-0 libxcb-glx0 libxdamage1 libxfixes3
libxinerama1 libxv1 libxvmc1 libxxf86dga1 libxxf86vm1 mplayer tsconf
ttf-dejavu-core
0 upgraded, 43 newly installed, 0 to remove and 93 not upgraded.
Need to get 12.1 MB of archives.
After this operation, 49.9 MB of additional disk space will be used.
Do you want to continue [Y/n]?
(中略)
次にrtmpdumpです。 apt-getコマンドは、複数のパッケージを一度にインストールすることもできますが、ここでは確認のために一つ一つ導入しています。
root@Raspyfi:~# apt-get install rtmpdump
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
ffmpeg mplayer
The following NEW packages will be installed:
rtmpdump
0 upgraded, 1 newly installed, 0 to remove and 93 not upgraded.
Need to get 55.1 kB of archives.
After this operation, 142 kB of additional disk space will be used.
Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main rtmpdump armhf 2.4+20111222.git4e06e21-1 [55.1 kB]
Fetched 55.1 kB in 1s (49.0 kB/s)
Selecting previously unselected package rtmpdump.
(Reading database ... 33667 files and directories currently installed.)
Unpacking rtmpdump (from .../rtmpdump_2.4+20111222.git4e06e21-1_armhf.deb) ...
Setting up rtmpdump (2.4+20111222.git4e06e21-1) ...
localepurge: Disk space freed in /usr/share/locale: 0 KiB
localepurge: Disk space freed in /usr/share/man: 0 KiB
Total disk space freed by localepurge: 0 KiB
続いてswftoolsです。
root@Raspyfi:~# apt-get install swftools
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
gsfonts
Suggested packages:
gs-common
The following NEW packages will be installed:
gsfonts swftools
0 upgraded, 2 newly installed, 0 to remove and 93 not upgraded.
Need to get 5,409 kB of archives.
After this operation, 9,683 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main gsfonts all 1:8.11+urwcyr1.0.7~pre44-4.2 [3,364 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ wheezy/main swftools armhf 0.9.2+ds1-3 [2,045 kB]
Fetched 5,409 kB in 3s (1,363 kB/s)
Selecting previously unselected package gsfonts.
(Reading database ... 34163 files and directories currently installed.)
Unpacking gsfonts (from .../gsfonts_1%3a8.11+urwcyr1.0.7~pre44-4.2_all.deb) ...
Selecting previously unselected package swftools.
Unpacking swftools (from .../swftools_0.9.2+ds1-3_armhf.deb) ...
Setting up gsfonts (1:8.11+urwcyr1.0.7~pre44-4.2) ...
Setting up swftools (0.9.2+ds1-3) ...
localepurge: Disk space freed in /usr/share/locale: 0 KiB
localepurge: Disk space freed in /usr/share/man: 0 KiB
Total disk space freed by localepurge: 0 KiB
最後に libxml2-utilsです。
root@Raspyfi:~# apt-get install libxml2-utils
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
libxml2-utils
0 upgraded, 1 newly installed, 0 to remove and 93 not upgraded.
Need to get 93.8 kB of archives.
After this operation, 168 kB of additional disk space will be used.
Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libxml2-utils armhf 2.8.0+dfsg1-7+nmu2 [93.8 kB]
Fetched 93.8 kB in 0s (104 kB/s)
Selecting previously unselected package libxml2-utils.
(Reading database ... 34323 files and directories currently installed.)
Unpacking libxml2-utils (from .../libxml2-utils_2.8.0+dfsg1-7+nmu2_armhf.deb) ...
Setting up libxml2-utils (2.8.0+dfsg1-7+nmu2) ...
localepurge: Disk space freed in /usr/share/locale: 0 KiB
localepurge: Disk space freed in /usr/share/man: 0 KiB
Total disk space freed by localepurge: 0 KiB
root@Raspyfi:~#
パッケージの導入が終わったら、受信スクリプトの導入です。
Raspberry Pi • View topic - インターネットラジオの受信
(3) play_radiko.sh
radiko.jp受信用のスクリプトです。(4) play_nhk-radio.sh
らじる★らじる受信用のスクリプトです。なお、(3), (4)は以下のURLからダウンロード可能です。
https://gist.github.com/ihsoy-s/5292735
有難く使わせて頂きます。
ダウンロードしたスクリプトは、/rootに置いて実行権限を付加(chmod 755 *.sh)しておきます。
続いて設定です。
Raspberry Pi • View topic - インターネットラジオの受信
USB DACを使用する場合、"-ao alsa:device=hw=1.0"と指定することに
より、オーディオ出力が可能になります。また、設定ファイルにより出力系を変更
することが可能です。/etc/mplayer/mplayer.conf → グローバルな設定
~/.mplayer/config → ユーザごとの設定ここに、"ao=alsa:device=hw=1.0"と記載することでコマンドラインから指定
を省略できます。
ウチの環境でこれをやると、かえってUSB DACから音が出なくなりました。 そのままで音が出るなら、何もいじる必要はありません。
それでは音出ししてみます。 まずはNHK「らじる★らじる」のラジオ第1からです。
root@Raspyfi:~# ./play_nhk-radio.sh r1
RTMPDump v2.4
(c) 2010 Andrej Stepanchuk, Howard Chu, The Flvstreamer Team; license: GPL
WARNING: No application or playpath in URL!
WARNING: You haven't specified an output file (-o filename), using stdout
Connecting ...
WARNING: HandShake: Type mismatch: client sent 6, server answered 9
MPlayer svn r34540 (Debian), built with gcc-4.6 (C) 2000-2012 MPlayer Team
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing -.
Reading from stdin...
INFO: Connected...
Starting Live Stream
INFO: Metadata:
INFO: audiodatarate 48.00
INFO: audiocodecid mp4a
3.124 kB / 0.43 seclibavformat version 53.21.1 (external)
Mismatching header version 53.19.0
libavformat file format detected.
63.488 kB / 10.11 sec[flv @ 0xb643bc78]max_analyze_duration reached
[flv @ 0xb643bc78]Estimating duration from bitrate, this may be inaccurate
[lavf] stream 0: audio (aac), -aid 0
Load subtitles in ./
==========================================================================
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
libavcodec version 53.35.0 (external)
Mismatching header version 53.32.2
AUDIO: 48000 Hz, 2 ch, s16le, 0.0 kbit/0.00% (ratio: 0->192000)
Selected audio codec: [ffaac] afm: ffmpeg (FFmpeg AAC (MPEG-2/MPEG-4 Audio))
==========================================================================
AO: [pulse] Init failed: Connection refused
Failed to initialize audio driver 'pulse'
AO: [alsa] 48000Hz 2ch s16le (2 bytes per sample)
Video: no video
Starting playback...
A: 13.8 (13.7) of 0.0 (unknown) 26.2%
ちゃんと音が出ました。 音切れもなく、安定して受信できています、
ffmpegは導入していませんが、RaspyFi 1.0は Libav(libavcodec)が入っているので、それが使われているようです。
次に本題である radikoのNACK5です。
root@Raspyfi:~# ./play_radiko.sh NACK5
authtoken: maMyP0918NfeuogsjBq3RQ \noffset: 243133 length: 16 \npartialkey: owgIJIGOffP6+2KXWwrJPQ==
authentication success
areaid: JP13
RTMPDump v2.4
(c) 2010 Andrej Stepanchuk, Howard Chu, The Flvstreamer Team; license: GPL
WARNING: No application or playpath in URL!
WARNING: You haven't specified an output file (-o filename), using stdout
Connecting ...
WARNING: Trying different position for server digest!
MPlayer svn r34540 (Debian), built with gcc-4.6 (C) 2000-2012 MPlayer Team
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing -.
Reading from stdin...
INFO: Connected...
Starting Live Stream
INFO: Metadata:
INFO: StreamTitle
0.855 kB / 0.09 seclibavformat version 53.21.1 (external)
Mismatching header version 53.19.0
libavformat file format detected.
[flv @ 0xb6466c78]max_analyze_duration reached
[flv @ 0xb6466c78]Estimating duration from bitrate, this may be inaccurate
[lavf] stream 0: audio (aac), -aid 0
Clip info:
StreamTitle:
Load subtitles in ./
==========================================================================
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
libavcodec version 53.35.0 (external)
Mismatching header version 53.32.2
AUDIO: 48000 Hz, 2 ch, s16le, 0.0 kbit/0.00% (ratio: 0->192000)
Selected audio codec: [ffaac] afm: ffmpeg (FFmpeg AAC (MPEG-2/MPEG-4 Audio))
==========================================================================
AO: [pulse] Init failed: Connection refused
Failed to initialize audio driver 'pulse'
AO: [alsa] 48000Hz 2ch s16le (2 bytes per sample)
Video: no video
Starting playback...
A: 5.1 (05.0) of 0.0 (unknown) 25.9%
こちらも完璧。 文句ないです。
さて、目覚ましラジオとして使うには、指定した時間にラジオを受信・再生し、一定時間後にそれを切る必要があります。
コマンドラインで実行するメリットは、cronを使えることですね。
root@Raspyfi:~# vi /etc/crontab
(略)
root@Raspyfi:~# cat /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
59 5 * * * root /root/play_radiko.sh NACK5 > /dev/null 2>&1
50 6 * * * root killall mplayer
#
root@Raspyfi:~#
この例では、毎日05:59にNACK5を再生し、06:50に停止します。
ただここで問題が一つあります。 RaspyFi 1.0はcronサービスが自動で起動していないのです。
17 October 2013
10:13PeterLo
New Member
Forum Posts: 2
Member Since:
17 October 2013
Offline
1 QuoteHi,
I have been playing with Raspyfi for a few weeks now. I want to use the BBC Radio streams, to do this I use the bash script show here:
http://www.codedefied.co.uk/20…..-with-mpd/
with appropriate edits of course.
This script needs to run regularly, at boot and at least once a day.
I setup a crontab to do this. However cron is disabled at boot up. I have to start cron manually via ssh.
Once started it runs correctly, until reboot…
I have tried the script and the crontab in Raspbian and it runs without manual intervention.
I have tried various ways of persuading cron to start automatically but nothing works.
Any ideas?
Thanks
Peter
rpcbindの時と同じですね。
root@Raspyfi:~# find /etc/ -name "*cron"
/etc/rc5.d/S17cron
/etc/rc2.d/S17cron
/etc/default/cron
/etc/rc4.d/S17cron
/etc/rc3.d/S17cron
/etc/pam.d/cron
/etc/init.d/cron
root@Raspyfi:~# chkconfig
alsa-utils on
atd on
autofs on
avahi-daemon on
bootlogs on
bootmisc.sh on
checkfs.sh on
checkroot-bootclean.sh on
checkroot.sh on
console-setup on
cron on
dbus on
dropbear on
exim4 on
fake-hwclock on
hostname.sh on
hwclock.sh on
kbd on
keyboard-setup on
killprocs on
kmod on
minidlna off
motd on
mountall-bootclean.sh on
mountall.sh on
mountdevsubfs.sh on
mountkernfs.sh on
mountnfs-bootclean.sh on
mountnfs.sh on
mpd on
mtab.sh on
myruns on
networking on
nfs-common on
nginx off
nginx.dpkg-old off
ntp on
php5-fpm on
plymouth off
plymouth-log off
procps on
rc.local on
rcS off
rmnologin on
rpcbind on
rsync on
rsyslog off
samba on
sendsigs off
shairport 2345
ssh on
sudo on
triggerhappy on
udev on
udev-mtab on
umountfs off
umountnfs.sh off
umountroot off
urandom on
wicd on
x11-common off
root@Raspyfi:~#
ちゃんと起動することになっているんですけどね。
手動でサービスを起動することはできます。
root@Raspyfi:~# /etc/init.d/cron status
[FAIL] cron is not running ... failed!
root@Raspyfi:~# /etc/init.d/cron start
[ ok ] Starting periodic command scheduler: cron.
root@Raspyfi:~# /etc/init.d/cron status
[ ok ] cron is running.
常時電源Onで使うので、致命的な問題ではありませんが、リブートさせたときに忘れがちなので、なんとか修正したいですね。