Goal: to create an OpenWRT low cost & low power digital stereo WiFi Internet Radio Receiver and MP3 player using only trashware and old hardware devices.
Note: no soldering or disassembling actions needed
TL-WR710N v1 - 400 Mhz CPU, 32 Mb RAM, 8 Mb Flash, 1 USB2, Wifi b/g/n, 2 eth wan/lan
Follwing my previous How-To located here: https://forum.archive.openwrt.org/viewtopic.php?id=49013&p=1 , since the post is no more editable, I would like to add here some updates and enhancements.
NOTE: I used Barrier Breaker 14.04 because in my opinion is still the best OpenWRT version for running MPD, but you may use any newer version, just adapt your MPD configuration file (/etc/mpd.conf)
1) Updated MPD URL station list:
/usr/bin/mpc add http://stream.srg-ssr.ch/m/rsj/mp3_128
/usr/bin/mpc add http://stream.srg-ssr.ch/m/rsc_it/mp3_128
/usr/bin/mpc add http://stream.srg-ssr.ch/m/rsp/mp3_128
/usr/bin/mpc add http://webradio.antennevorarlberg.at:80/partymix
/usr/bin/mpc add http://webradio.antennevorarlberg.at:80/lovesongs
/usr/bin/mpc add http://webradio.antennevorarlberg.at:80/lounge
/usr/bin/mpc add http://176.31.240.87:8025
/usr/bin/mpc add http://www.partyvibe.com:8010/stream2
/usr/bin/mpc add http://89.106.235.181:8000/1fmamstrance
/usr/bin/mpc add http://live-radio02.mediahubaustralia.com/CTRW/mp3
/usr/bin/mpc add http://vocaltrance.ru:8000/vocaltrance_320
/usr/bin/mpc add http://fr3.1mix.co.uk:8060/320h
2) MPD whatchdog to restart MPD when playback appears to hang (thanks to Tkem):
note: it switches to the next station in list
vi /root/mpd-whatchdog.sh
# MPD whatchdog - monitor mpd while playing internet streams
#
# Copyright (c) 2013, 2015 Thomas Kemmer <tkemmer@computer.org>
# https://github.com/pimusicbox/mpd-watchdog
# Based on http://mpd.wikia.com/wiki/Hack:stream-monitor
#
PROGRAM="$(basename "$0")"
INTERVAL=10
LOGLEVEL=1
LOGGER="log_stderr"
MPDHOST=localhost
MPDPORT=6600
USAGE=$(cat <<EOF
Usage: $PROGRAM [OPTION]...
Monitor mpd while playing internet streams.
-h HOST MPD server host [$MPDHOST]
-i INTERVAL monitoring interval in seconds [$INTERVAL]
-p PORT MPD server port [$MPDPORT]
-s write log output to syslog
-v produce more verbose output
EOF
)
log_stderr() {
shift
echo "$0:" "$@" >&2
}
log_syslog() {
loglevel="$1"
shift
logger -t "$PROGRAM" -p "user.$loglevel" "$@"
}
log() {
case $1 in
alert|crit|emerg|err|error|warn|warning)
$LOGGER "$@"
;;
notice)
[ $LOGLEVEL -gt 0 ] && $LOGGER "$@"
;;
info)
[ $LOGLEVEL -gt 1 ] && $LOGGER "$@"
;;
debug)
[ $LOGLEVEL -gt 2 ] && $LOGGER "$@"
;;
*)
echo "$0: invalid log level: $1"
;;
esac
}
mpc_status() {
$MPC status 2>/dev/null | grep -B1 '^\[playing\]' | tr '\n' ' '
}
while getopts "h::i:p:sv" opt; do
case $opt in
h)
MPDHOST=$OPTARG
;;
i)
INTERVAL=$OPTARG
;;
p)
MPDPORT=$OPTARG
;;
s)
LOGGER="log_syslog"
;;
v)
LOGLEVEL=$(($LOGLEVEL + 1))
;;
*)
echo "$USAGE" >&2
exit 2
;;
esac
done
shift $(($OPTIND - 1))
MPC="mpc -h $MPDHOST -p $MPDPORT"
trap 'log notice "terminating..." ; exit' INT QUIT KILL TERM
log notice "starting..."
prev_status=$(mpc_status)
while sleep $INTERVAL; do
status=$(mpc_status)
if [ -n "$status" ]; then
log info "$status"
if [ "$prev_status" = "$status" ]; then
log warning "restarting mpd"
$MPC stop && $MPC play || log err "error restarting mpd"
fi
else
log debug "mpd not running/playing"
fi
prev_status="$status"
done
3) Another scrip to restart MPD to solve the problem when Internet goes down and immediately returns up, MPD stops working and needs to be restarted manually:
vi /root/network-monitor.sh
# Make MPD resilient to the network disconnections
# https://discourse.mopidy.com/t/mpd-watchdog-not-working-good-enough/2999/5
# Which address do you want to ping to see if the internet connection is alive?
pingip='8.8.8.8'
MPDHOST=localhost
MPDPORT=6600
INTERVAL=15
##################################################################
mpc_status() {
$MPC status 2>/dev/null | grep -B1 '^\[playing\]' | tr '\n' ' '
}
MPC="mpc -h $MPDHOST -p $MPDPORT"
prev_status=$(mpc_status)
while sleep $INTERVAL; do
status=$(mpc_status)
if [ -n "$status" ]; then
if [ "$prev_status" = "$status" ]; then
echo "Performing Network check"
/bin/ping -c 1 $pingip > /dev/null 2> /dev/null
if [ $? -ge 1 ] ; then
echo "Network connection down! Try again in $INTERVAL seconds"
else
echo "Network is Okay, restart playing"
$MPC stop && $MPC play
fi
fi
else
echo "mpd not running/playing"
fi
prev_status="$status"
done
To lauch both scripts at startup, put the two following lines, just before "exit 0", in the "/etc/rc.local" file:
/bin/sh /root/network-monitor.sh &
/bin/sleep 1
/bin/sh /root/mpd-whatchdog.sh &