[HowTo] OpenWRT WiFi Internet Radio Receiver (Enhanced)

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


hub
key
USB-Sound-Card

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 &

1 Like

You may want to take a look also at this post:

To get new URL's for your Internet Radio Receiver:

http://fmstream.org/

The Radio Stream Directory

OpenWRT Internet Radio Receiver, my 2021 prototype, based on TP-Link TL-WR 710N and a switching power supply working from 6 to 15 Vac (or Vcc) to be connected directly to an old vacuum tube radio (lamps and filaments 6.3 or 12 Vac internal power line).
The internal 110-220Vac/5Vcc switching power supply section of TL-WR 710N remains unused (cause it is too noisy for the high input impedance of a tube amplifier).
Total power consumption < 2.5 W (200mA @ 12V)

TL-WR 710n v1 - my Barrier Breaker mini custom build (No Luci, No IPv6, No PPoe, available on request)**
Services installed:
Wireless, Alsa, USB Audio, USB Numeric Keyboard, Triggerhappy, miniMPD + MPC, Uhttpd + PHP, Vsftpd, Z-RAM swap, Dropbear, Htop, BusyBox, MPD Watchdogs, Web control interface.
Incredibly everything fitted on 8 Mbytes flash.

uhttpd+PHP web interface to control MPD (optimized for smartphones and tablets)

1 Like

OpenWRT Internet Radio Receiver installed on an old Vacuum Tube Radio (1967), it used the Radio internal tube stereo amplifier and it is connected to the Phono/Aux input connector, without any original radio circuit modification, the only soldering it is on the internal lamp bulb terminals to get the 6.3 Vac.
On the second picture it is visible the optional ethernet cable (LAN/WAN connection alternative to WiFi).

2 Likes

disk
I was also able to add kmod-usb-storage, kmod-fs-vfat, kmod-nls-iso8859-1 and kmod-nls-cp437, into the 8 Mbytes flash, so I added three things:

  1. add FAT32 (universal filesystem) USB flash disk to store MP3 files to be played without any internet connection
opkg update
opkg install kmod-usb-storage kmod-fs-vfat kmod-nls-iso8859-1 kmod-nls-cp437 
reboot

after reboot:

mkdir /mnt/sda1
mount -t vfat /dev/sda1 /mnt/sda1 -o rw,sync

wifi
2) create in the USB storage a text file (command) containg configuration for WiFi connection, so anyone will be able to easily change the WiFi connection just by editing the file in the external USB storage (if USB storage is missing or unreadable, the system will load the default /etc/config/wireless configuration).

wifi configuration file:

/mnt/sda1/wifi.sh

/sbin/uci set wireless.@wifi-iface[0].ssid=new_wifi #change this
/sbin/uci set wireless.@wifi-iface[0].device=radio0 
/sbin/uci set wireless.@wifi-iface[0].mode=sta
/sbin/uci set wireless.@wifi-iface[0].key=wifi_password #change this
/sbin/uci set wireless.@wifi-iface[0].encryption=psk-mixed #universal wpa&wpa2
/sbin/uci commit wireless
/sbin/wifi reload

This command file will be reloaded and launched at each reboot just after the USB storage is mounted:

/etc/rc.local

#
/bin/mount -t vfat /dev/sda1 /mnt/sda1 -o rw,sync #mount FAT32 USB storage 
/bin/sleep 1
/bin/sh /mnt/sda1/wifi.sh #the command file stored in the external USB storage 
exit 0
  1. store MPD radio playlists (internet radios and MP3 files) in the USB storage instead of in the rc.local internal file as described in my previous HowTo, for easier modification.

mp3

  1. create in the USB disk a directory called "music" that will contain the MP3 files and create a symlink to this USB external directory (based on /etc/mpd.conf):
mkdir /mnt/sda1/music
/bin/ln -s /mnt/sda1/music /root/music

also, to avoid excessive writings on the internal flash storage let's move mpd.db on /mnt/sda1 and create a symlink:

cd /root
rm mpd.db
/bin/ln -s /mnt/sda1/mpd.db mpd.db
  1. MP3 files - play randomly
    when a specific key (Enter) is pressed launch the following mpc commands to scan the "music" directory on the USB storage, clear the current playlist, add all found mp3 files to the playlist and start playing.
    (tested OK with 160 mp3 files, but it needs a total of 7 seconds delay before starting playing)

/mnt/sda1/scan-mp3.sh

/usr/bin/mpc stop
/usr/bin/mpc repeat on 
/usr/bin/mpc random on
/usr/bin/mpc clear
/bin/sleep 1
/usr/bin/mpc update
/bin/sleep 1
/usr/bin/mpc ls | /usr/bin/mpc add
/bin/sleep 5 # to be tuned based on how many mp3 files you have and how fast is your USB storage
/usr/bin/mpc play

By this way any added or deleted MP3 file will be processed each time (playlist update).

note: it would be much easier and faster by using madplay to play mp3 files, but I have no more space available on /overlay and don't want to use extroot

Internet-Radio
3) external (USB storage) file to easily add/edit Internet Station url's

cd /root
/bin/ln -s /mnt/sda1/stations.sh stations.sh

/mnt/sda1/stations.sh

/usr/bin/mpc stop
/usr/bin/mpc clear
/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
/usr/bin/mpc repeat on

keypad

  1. associate keypad keys to play MP3 files or launch Inet Station (triggerhappy).
opkg update
opkg install triggerhappy

/etc/triggerhappy/triggers.d/example.conf (triggerhappy configuration file)

# This is a configuration for the triggerhappy daemon (thd)
######################################################################
# Important Notes:
# "Speaker" may need to be changed to "PCM", it depends on your audio hardware,
# discover the right name by giving the command " alsamixer "
# also the name of the keys (KEY_xyxz) may need to be changed,
# discover their name by giving the following command: "thd --dump /dev/input/event* "
######################################################################
## control mpd
###
# start playing MP3 files on external USB
KEY_KPENTER 1 /bin/sh /mnt/sda1/scan-mp3.sh # if USB not connected does nothing
###
# stop playing
KEY_KPDOT 1 /usr/bin/mpc stop
###
# select stations                                              
KEY_KP0 1 /bin/sh /root/stations.sh; /usr/bin/mpc play 1
KEY_KP1 1 /bin/sh /root/stations.sh; /usr/bin/mpc play 2
KEY_KP2 1 /bin/sh /root/stations.sh; /usr/bin/mpc play 3
KEY_KP3 1 /bin/sh /root/stations.sh; /usr/bin/mpc play 4
KEY_KP4 1 /bin/sh /root/stations.sh; /usr/bin/mpc play 5
KEY_KP5 1 /bin/sh /root/stations.sh; /usr/bin/mpc play 6
KEY_KP6 1 /bin/sh /root/stations.sh; /usr/bin/mpc play 7
KEY_KP7 1 /bin/sh /root/stations.sh; /usr/bin/mpc play 8
KEY_KP8 1 /bin/sh /root/stations.sh; /usr/bin/mpc play 9
KEY_KP9 1 /bin/sh /root/stations.sh; /usr/bin/mpc play 10
KEY_KPASTERISK 1 /bin/sh /root/stations.sh; /usr/bin/mpc play 11
KEY_KPSLASH 1 /bin/sh /root/stations.sh; /usr/bin/mpc play 12
###
# control audio volume                                                                                                       
#  increase volume +2%:                                             
KEY_KPPLUS 1 /usr/bin/amixer -q set Speaker 2%+                     
#  set the volume at the minimum audible level (MUTE mode)
KEY_BACKSPACE 1 amixer -q set Speaker 60     
# decrease volume -2%:                           
KEY_KPMINUS 1 /usr/bin/amixer -q set Speaker 2%-
#

Note: by using a standard numeric keypad you may have 13 selections plus four selections to increase/decrease audio volume, audio mute and stop music, but you can use a full keyboard to have many more selections available.

Just for reference.

Packets intalled on 8 Mbytes Flash of TL-WR 710N v1 - BARRIER BREAKER (14.07)

root@OpenWrt:~# opkg list-installed

alsa-lib - 1.0.27.2-1
alsa-utils - 1.0.28-2
base-files - 156-r42625
block-mount - 2014-06-22-e0430f5c62f367e5a8e02755412977b02c3fc45e
busybox - 1.22.1-2
dnsmasq - 2.71-5
dropbear - 2014.63-2
firewall - 2014-09-19
fstools - 2014-06-22-e0430f5c62f367e5a8e02755412977b02c3fc45e
glib2 - 2.41.1-2
hostapd-common - 2014-06-03.1-3
htop - 1.0.3-1
iptables - 1.4.21-1
iw - 3.15-1
iwinfo - 51
jshn - 2014-08-04-dffbc09baf71b294185a36048166d00066d433b5
jsonfilter - 2014-06-19-cdc760c58077f44fc40adbbe41e1556a67c1b9a9
kernel - 3.10.49-1-0114c71ed85677c9c1e4911437af4743
kmod-ath - 3.10.49+2014-05-22-1
kmod-ath9k - 3.10.49+2014-05-22-1
kmod-ath9k-common - 3.10.49+2014-05-22-1
kmod-button-hotplug - 3.10.49-3
kmod-cfg80211 - 3.10.49+2014-05-22-1
kmod-crypto-aes - 3.10.49-1
kmod-crypto-arc4 - 3.10.49-1
kmod-crypto-core - 3.10.49-1
kmod-fs-vfat - 3.10.49-1
kmod-gpio-button-hotplug - 3.10.49-1
kmod-hid - 3.10.49-1
kmod-hid-generic - 3.10.49-1
kmod-input-core - 3.10.49-1
kmod-input-evdev - 3.10.49-1
kmod-ipt-conntrack - 3.10.49-1
kmod-ipt-core - 3.10.49-1
kmod-ipt-nat - 3.10.49-1
kmod-ipt-nathelper - 3.10.49-1
kmod-lib-crc-ccitt - 3.10.49-1
kmod-lib-lzo - 3.10.49-1
kmod-mac80211 - 3.10.49+2014-05-22-1
kmod-nls-base - 3.10.49-1
kmod-nls-cp437 - 3.10.49-1
kmod-nls-iso8859-1 - 3.10.49-1
kmod-scsi-core - 3.10.49-1
kmod-slhc - 3.10.49-1
kmod-sound-core - 3.10.49-1
kmod-usb-audio - 3.10.49-1
kmod-usb-core - 3.10.49-1
kmod-usb-hid - 3.10.49-1
kmod-usb-ohci - 3.10.49-1
kmod-usb-storage - 3.10.49-1
kmod-usb-uhci - 3.10.49-1
kmod-usb2 - 3.10.49-1
kmod-zram - 3.10.49-1
libattr - 20140610-1
libblkid - 2.24.1-1
libblobmsg-json - 2014-08-04-dffbc09baf71b294185a36048166d00066d433b5
libc - 0.9.33.2-1
libcurl - 7.38.0-1
libffi - 3.0.13-1
libflac - 1.2.1-1
libgcc - 4.8-linaro-1
libip4tc - 1.4.21-1
libip6tc - 1.4.21-1
libiwinfo - 51
libiwinfo-lua - 51
libjson-c - 0.11-2
libjson-script - 2014-08-04-dffbc09baf71b294185a36048166d00066d433b5
liblua - 5.1.5-1
libmad - 0.15.1b-3
libmpdclient - 2.7-2
libncurses - 5.9-1
libnl-tiny - 0.1-3
libogg - 1.3.2-2
libpcre - 8.35-2
libpolarssl - 1.3.9-2
libpthread - 0.9.33.2-1
librt - 0.9.33.2-1
libubox - 2014-08-04-dffbc09baf71b294185a36048166d00066d433b5
libubus - 2014-09-17-4c4f35cf2230d70b9ddd87638ca911e8a563f2f3
libubus-lua - 2014-09-17-4c4f35cf2230d70b9ddd87638ca911e8a563f2f3
libuci - 2014-04-11.1-1
libuci-lua - 2014-04-11.1-1
libuuid - 2.24.1-1
libvorbisidec - 1.0.2+svn18153-2
libxml2 - 2.9.2-1
libxtables - 1.4.21-1
lua - 5.1.5-1
mpc - 0.26-2
mpd-mini - 0.17.6-4
mtd - 20
netifd - 2014-09-08-46c569989f984226916fec28dd8ef152a664043e
odhcpd - 2014-08-23-24452e1e3e9adfd9d8e183db1aa589f77727f5a7
opkg - 9c97d5ecd795709c8584e972bfdf3aee3a5b846d-7
php5 - 5.4.27-1
php5-cgi - 5.4.27-1
procd - 2014-09-15-c1a558f7d0c1e6c1ffa5a47d557a7b45205eef1d
swap-utils - 2.24.1-1
swconfig - 10
terminfo - 5.9-1
triggerhappy - 0.3.4-2
uboot-envtools - 2014.04-4
ubox - 2014-09-16-5c45b560bc8c9e13682269ed963a8a4a65959518
ubus - 2014-09-17-4c4f35cf2230d70b9ddd87638ca911e8a563f2f3
ubusd - 2014-09-17-4c4f35cf2230d70b9ddd87638ca911e8a563f2f3
uci - 2014-04-11.1-1
uhttpd - 2014-08-25-dabd7dea6445aaa0e5b8d9add1872fa7393b3a85
uhttpd-mod-ubus - 2014-08-25-dabd7dea6445aaa0e5b8d9add1872fa7393b3a85
whereis - 2.24.1-1
wpad-mini - 2014-06-03.1-3
zlib - 1.2.8-1
zram-swap - 1-2
root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    5.1M      4.9M    200.0K  96% /
/dev/root                 1.8M      1.8M         0 100% /rom
tmpfs                    14.1M     64.0K     14.0M   0% /tmp
/dev/mtdblock3            5.1M      4.9M    200.0K  96% /overlay
overlayfs:/overlay        5.1M      4.9M    200.0K  96% /
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/sda1                14.4G     10.4G      4.0G  72% /mnt/sda1
root@OpenWrt:~# free
             total         used         free       shared      buffers
Mem:         28860        27872          988            0         2252
-/+ buffers:              25620         3240
Swap:        16380          796        15584

top

Mem: 26748K used, 2112K free, 0K shrd, 1464K buff, 4120K cached
CPU:  19% usr   3% sys   0% nic  76% idle   0% io   0% irq   0% sirq
Load average: 0.58 0.48 0.35 1/44 11523
  PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND
  945     1 root     S    19052  66%  21% /usr/bin/mpd
10734     2 root     SW       0   0%   0% [kworker/u2:2]
 1182     1 root     S     1364   5%   0% /bin/sh /root/mpd-whatchdog.sh
11509  2142 root     R     1364   5%   0% top
 2141   776 root     S     1220   4%   0% /usr/sbin/dropbear -F -P /var/run/dro
  732     1 root     S     1544   5%   0% /sbin/netifd
  792     1 root     S     1532   5%   0% /usr/sbin/uhttpd -f -h /www -r OpenWr
  967     1 root     S     1524   5%   0% /usr/sbin/wpa_supplicant -B -P /var/r
    1     0 root     S     1388   5%   0% /sbin/procd
 1118     1 root     S     1364   5%   0% /bin/sh /root/network-monitor.sh
 2142  2141 root     S     1364   5%   0% -ash
 1008   732 root     S     1360   5%   0% udhcpc -p /var/run/udhcpc-wlan0.pid -
11523  1182 root     S     1352   5%   0% sleep 10
11516  1118 root     S     1352   5%   0% sleep 15
  776     1 root     S     1152   4%   0% /usr/sbin/dropbear -F -P /var/run/dro
 1061     1 nobody   S      928   3%   0% /usr/sbin/dnsmasq -C /var/etc/dnsmasq
  461     1 root     S      880   3%   0% /sbin/ubusd
  970     1 root     S      804   3%   0% /usr/sbin/thd --socket /tmp/triggerha
  257     2 root     SW       0   0%   0% [kworker/0:2]
295     2 root     SW       0   0%   0% [kworker/u2:0]