OpenWrt Forum Archive

Topic: [HowTo] Openwrt cheap Digital Stereo WiFi Internet Radio & MP3 Player

The content of this topic has been archived between 7 Apr 2018 and 5 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Thanks! I already wrote you smile Looking forward to talk

Improve use of memory and increase stability of the Internet Radio by using Zram.

zram (also called zRAM and, initially, compcache) is a Linux kernel feature that provides a form of virtual memory compression. zram increases performance by avoiding paging to disk and using a compressed block device in RAM instead, inside which paging takes place until it is necessary to use the swap space on a hard disk drive. Since using zram is an alternative way to provide swapping on RAM, zram allows Linux to make a better use of RAM when swapping/paging is required, especially on older computers with less RAM installed.
zram offers advantages for low-end hardware devices such as embedded devices, such devices usually use flash-based storage, which has limited lifespan due to write amplification, and also use it to provide swap space. The reduction in swap usage as a result of using zram effectively reduces the amount of wear placed on such flash-based storage, resulting in prolonging its usable life. Also, using zram results in a significantly reduced I/O for Linux systems that require swapping.
Google uses zram in Android since its version 4.4


In our case  it stops the router from beeing reset by watchdog/low memory and "virtually" increase the total free RAM available wink
Zram uses a little CPU power but in our case we have no problem with CPU, we have shortage of RAM instead, so it's a perfect solution!
-----------------------------------------------

OpenWRT Barrier Breaker install instructions:

prerequisites: you need at least 300 Kbytes of free flash space, check it with "df" command.

opkg update
opkg install zram-swap

then reboot.

After reboot you'll have a device called /dev/zram0

check free memory with "free" command, you should get something like this:

root@(none):/dev# free
             total         used         free       shared      buffers
Mem:         28860        27724         1136            0         1244
-/+ buffers:              26480         2380
Swap:            0            0            0

now insert the following lines right at the begginning of the file "/etc/rc.local" to activate a Zram of 10 Megabytes:

/bin/echo $((10*1024*1024)) > /sys/block/zram0/disksize
/usr/sbin/mkswap /dev/zram0 
/usr/sbin/swapon /dev/zram0

Reboot the router and check again with "free" command:

root@(none):/dev# free
             total         used         free       shared      buffers
Mem:         28860        27376         1484            0         1248
-/+ buffers:              26128         2732
Swap:        10236            0        10236


That's all smile


Note: if your router has more of 32 Mbytes of RAM, you may increase the Zram size, the best choice is about 30% of total ram.

(Last edited by pilovis on 8 Sep 2016, 20:54)

hi i have  awus036h 1 watt wifi usb can i connect wifi usb to mr3220  ?

killerjatt wrote:

hi i have  awus036h 1 watt wifi usb can i connect wifi usb to mr3220  ?

I think so, but you need to use an external powered USB Hub since this dongle needs a lot of current.

Hey guys smile
I created a very similar project without hardware keys using the very cheap A5-V11 openwrt router. Here is my portable wireless music system with webradio, dlna/upnp server and dlna/upnp renderer: http://board.nwrk.biz/viewtopic.php?pid=344#p344

All in all this project costs about 25€ and the setup is pretty small. The installation should be quite easy because everything is preconfigured in an extroot filesystem. I also included ympd, a lightweight but powerful web based mpd client! (ympd is a standalone binary, php and uhttpd are not needed.)

http://www70.zippyshare.com/scaled/PjCGi1Ev/file.html
https://fredfire1.files.wordpress.com/2015/09/ympd-client-in-webbrowser.png

(Last edited by giri@nwrk.biz on 29 Sep 2016, 02:35)

giri@nwrk.biz wrote:

Hey guys smile
I created a very similar project without hardware keys using the very cheap A5-V11 openwrt router. Here is my portable wireless music system with webradio, dlna/upnp server and dlna/upnp renderer: http://board.nwrk.biz/viewtopic.php?pid=344#p344


Nice job! smile

If you want to see in real time (updated every second) the WiFi signal in client mode of your router, this is the shell single line "multi-commands" for you:

while true; do iw dev wlan0 station dump | grep -i signal: | tr '\012' '\015'; sleep 1; done

(Last edited by pilovis on 19 Dec 2016, 23:59)

Add an external serial LCD display to our Internet Radio (first part)


To display the current MPD channel and the playing song, this is the command:

while true; do mpc current | tr '\012' '\015'; sleep 1; done
(real time output)

or if you want a more exaustive output:

echo "currentsong" | nc localhost 6600
(one shoot output)

or even:

echo "currentsong" | nc localhost 6600 | grep -e "^Title: " -e "^Name: "

you can redirect this information to an output device connected to the router's serial port, by this way:

while true; do mpc current | tr '\012' '\015'; sleep 1; done > /dev//dev/ttyATH0

However, the serial port’s default speed of 115200 baud is too fast for some external serial displays, so we need to change the speed of the serial port from it’s default value of 115200 to 9600 baud. 
This can be easily done by using the "stty" command.

First you need to install stty with the following commands:

opkg update
opkg install coreutils-stt

then you can change the speed of the serial port by adding the following command to "/etc/rc.local" just before the "exit 0" line:

/usr/bin/stty -F /dev/ttyATH0 9600 clocal cread cs8 -cstopb -parenb

to check that the speed has been correctly set at 9600 baud, use the following comand:

/usr/bin/stty -F /dev/ttyATH0

(Last edited by pilovis on 29 Dec 2016, 04:19)

where to find the internal connections for the serial port of our Internet Radio (TP-Link TL-WR 710):

TP_IN = Rx (NOTconnected)
TP_OUT= Tx to be connected to Rx pin of the display
GND = USB metal case (big solder pad under USB port)
5 Vcc to power out the external LCD display = square solder pad under C209 (see picture)

Note that the internal serial is 3.3V-logic, so we need a serial display that has the same 3.3 V signal voltage.

http://www.lovisolo.com/asterisk/software/openwrt/tl-wr710n_1.jpg

(Last edited by pilovis on 29 Dec 2016, 06:23)

http://i.ebayimg.com/00/s/NjAwWDYwMA==/z/22UAAOSw44BYUAWl/$_57.JPG?set_id=8800005007

http://i.ebayimg.com/00/s/NjAwWDYwMA==/z/KnAAAOSwJ7RYUAWh/$_57.JPG?set_id=8800005007

how cheap is this?

because I can built something similar with this without too much hassle using a old generation raspberry pi, all I did is install apps, plug things, on its builtin 4 port USB hub (in my case all I got plugged on it is USB WiFi).

after that I sit it at the back of my receiver (amplifier) and connected via HDMI. I can play music on it with my own music library on my NAS via DLNA server/Plex. Or stream a internet radio (shoutcast stream) via DLNA Renderer.

Total cost for all of this is only just $18, with class 10 4gb SDHC card and WiFi dongle a rpi case and the rpi itself. powering the rpi is not a issue since my receiver got a USB port at the back for firmware updates.

I did the same thing using Raspberry 2, but the problem with this raspberry board is the terrible audio output  quality , very bad if you use analog audio output.
Also, Raspberry consumes more electrical power than a router and sometime (not so infrequently) filesystem get corrupted by power outages.

Anyway, I don't think the Raspberry solution is cheaper, my openwrt solution costs the following:

Euro 25 for a new router (with power supply and wifi interface integrated)
Euro 5 for the USB audio adapter
Euro 5 for the USB Hub (not needed if you control MPD by your Smartphone or by web browser)
Euro 7 for the USB keypad  (not needed if you control MPD by your Smartphone or by web browser)

Obviously you can use an old router and old parts that you might have in a drawer and spend nothing wink

(Last edited by pilovis on 29 Dec 2016, 11:17)

Also, my goal was to obtain a very reliable WiFi Digital Internet Radio by using the minimum possible resources, in fact everything works well with 32 Mbytes of RAM and 8 Mbytes of flash storage and no more than 5 W of power supply consumption.

(Last edited by pilovis on 29 Dec 2016, 11:33)

You'll find all files for configuring my Internet Radio (as described above @ page 5) here:

http://www.lovisolo.com/asterisk/softwa … -Internet/

The above configuration files work for A.A., B.B. and C.C. OpenWRT releases, just overwrite the original ones (if present) and copy all the other files in the same directories of your router.
To move the files to your router install vsftpd, start it then connect it with your preferred FTP client (use the router's root credentials), or else use wget from inside the router.
You'll also find the modified firmware for the TP-Link TL-WR710n router, but you can use any model of OpenWRT compatible router to make this radio.


my Triggerhappy configuration file is programmed to work with this type of USB keypad:

http://www.lindy.co.uk/images/usb-numeric-keypad-p763-1172_zoom.jpg

Key Enter = start playing MPD (first station listed in /etc/rc.local)
Key Slash (/) = next station  (there are 42 stations already listed)
Key Asterisk (*) = prev station
Key + = Volume up: +2% for each press
Key - = Volume down: -2% for each press
Key Backspace (<-) = mute: lower the volume at minimum audible level
Ket dot/Del (.) = stop playing

Keys 0 to 9 = 10 preset stations (my 10 preferred stations wink )

and also to work with with this infrared remote command (optional):
Note: it is better to fisically remove (or cut it at the top) the red power key because it crashes triggerhappy when pressed sad

http://img.dxcdn.com/productimages/sku_26368_1.jpg

Press once "NumLook" key to enable 0-9 keys (preset stations),
blue keys "page up" and "page down" = mpd "next" and "prev" station,
key ||> (above fullscreen key) = mpd "play first station",
key "square" (next to play key) = "stop" playing.


This is the best sounding USB audio adapter I found:

http://i00.i.aliimg.com/img/pb/053/104/874/874104053_565.jpg

but you can also use one of those two:

http://www.music4company.com/images/Products/0-5ce1deb0-500.jpg

http://g04.a.alicdn.com/kf/HTB1IBg1KVXXXXaeXVXXq6xXFXXXy/For-Win-XP-7-8-10-font-b-Android-b-font-Linux-MacOS-External-USB-to.jpg


This is the web interface you see when you connect to http://router-ip-address/music
by this interface you can play/stop and change radio stations, also you can see the station, the artist and song that is currently playing.

https://camo.githubusercontent.com/4bdec174b19a659485dfb3f64207a4ed1b0fa0b8/68747470733a2f2f646c2e64726f70626f7875736572636f6e74656e742e636f6d2f752f313031353730322f6c696e6b65645f746f2f6d70642d7765622d636c69656e742e6a7067


This is the vacuum tubes Hi-Fi amplifier I designed and built specifically for this internet radio (the router is located inside),
I think it is probably the only one Brand New Vacuum Tubes Hi-Fi Stereo Internet Radio in the whole world big_smile

http://www.lovisolo.com/valvole/ampli5.jpg

in case you want to build it wink this is the schematic I designed (one channel) [be careful!! HIGH VOLTAGE 500 Vac max]:

http://www.lovisolo.com/valvole/per-cuffia.jpg

Happy listening smile

(Last edited by pilovis on 30 Dec 2016, 21:25)

Router says local and public IP addresses through the speakers of our Internet Radio

Since my router is without any display, I was wondering how I could find the WAN IP address (dhcp) of the router.
The answer was to use a text to speech engine and let the router to say the ip address through the speakers. smile
By googling I found a very good and light TTS (text to speech) for Openwrt, so I created two scripts to have the router to say the current IP addresses (local and public), at startup or at request by pressing a button.
Svox (pico2wave) is an offline text-to-speech engine with good voices in many languages, you can simply change language by using the -l parameter, example: "-l de-DE" speaks German, "-l fr-FR" speaks French, "-l es-ES" speaks Spanish, "-l it-IT" speaks Italian, and so on, default langage is English: "-l en-US".
Svox unfortunately is only available on Chaos Calmer, so if you have installed A.A or B.B. OpenWRT releases, you can't use it without upgrading to C.C.

Quick How-To:

You just need to install svox and some other packages (you probably have already installed) on the OpenWRT router.
Note: svox needs a lot of space, so if you don't have at least 5 megabytes of free space, you need to use an external USB overlay.

opkg update
opkg install svox
opkg install kmod-sound-core
opkg install kmod-usb-audio
opkg install alsa-utils

Note: to install svox on Barrier Breaker you need to install it manually by grabbing it from the Chaos Calmer 15.01  packages, example for AR71XX:

opkg install http://archive.openwrt.org/chaos_calmer/15.05.1/ar71xx/generic/packages/packages/sox_14.4.1-3_ar71xx.ipk 

then create the following two scripts:

vi say-local-ip.sh

#!/bin/sh
IP=$(/sbin/ifconfig br-lan | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
cadena=$(echo $IP | sed 's/\.1\./\.one\./g')
cadena=$(echo $cadena | sed 's/\./point/g')
pico2wave -l en-US -w /tmp/text.wav "the Local IP address is "$cadena
aplay -f S16_LE -D plughw:0,0 /tmp/text.wav

note: eventually change "br-lan" with your LAN interface name, discover it with "ifconfig" command.

vi say-public-ip.sh

#!/bin/sh
IP=$(wget http://ipecho.net/plain -O - -q ; echo)
cadena=$(echo $IP | sed 's/\.1\./\.one\./g')
cadena=$(echo $cadena | sed 's/\./point/g')
pico2wave -l en-US -w /tmp/text.wav "the Public IP address is "$cadena
aplay -f S16_LE -D plughw:0,0 /tmp/text.wav

save and give them the right permissions:

chmod 755 say-local-ip.sh
chmod 755 say-public-ip.sh

then you can test both scripts:

/bin/sh /root/say-local-ip.sh
/bin/sh /root/say-public-ip.sh

you shoud hear a female voice saying your local and public IP addresses through the speakers.

--------------------------------------------------------------------------------

Scripts in Italian:

ip-pubblico.sh:

#!/bin/sh
IP=$(wget http://ipecho.net/plain -O - -q ; echo)
cadena=$(echo $IP | sed 's/\.1\./\.uno\./g')
cadena=$(echo $cadena | sed 's/\./punto/g')
pico2wave -l it-IT -w /tmp/text.wav "il tuo indirizzo IP pubblico e' '"$cadena
aplay -f S16_LE -D plughw:0,0 /tmp/text.wav

ip-locale.sh:

#!/bin/sh
IP=$(/sbin/ifconfig br-lan | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
cadena=$(echo $IP | sed 's/\.1\./\.uno\./g')
cadena=$(echo $cadena | sed 's/\./punto/g')
pico2wave -l it-IT -w /tmp/text.wav "il tuo indirizzo IP privato e' '"$cadena
aplay -f S16_LE -D plughw:0,0 /tmp/text.wav

--------------------------------------------------------------------------

Ref.: http://openwrt.tuinstituto.es/script-pa … ip-publica (in Spanish)

(Last edited by pilovis on 18 Jan 2018, 18:50)

Following the previous post I've created an hotplug trigger that, when an hardware key is pressed on the router, it says the local and the public IP addresses through the speakers.
This is an example how to attach to the WiFi button of the router Huawei EchoLife HG553 (Vodafone Station) the above function, if the button is pressed for less than 1 second, the router says the local (LAN) IP address, if the button is pressed for more than two seconds, the router says the public (WAN) IP address.

I've just edited the "/etc/rc.button/rfkill" file in this way:

#!/bin/sh

[ "${ACTION}" = "released" ] || exit 0

. /lib/functions.sh

logger "$BUTTON pressed for $SEEN seconds"

if [ "$SEEN" -lt 1 ]
then
        /root/say-local-ip.sh

elif [ "$SEEN" -gt 2 ]
then
        /root/say-public-ip.sh
fi

return 0

(Last edited by pilovis on 3 Jan 2017, 20:44)

How to remove the stupid "vi" as a default editor and use nano instead:

opkg update
opkg install nano
mv /bin/vi /bin/vi.stupid
ln -s /usr/bin/nano /bin/vi

wink

(Last edited by pilovis on 8 Jan 2017, 14:17)

more radio stations to add to our internet radio:

/usr/bin/mpc add http://144.76.106.52:7000/chillout.mp3
/usr/bin/mpc add http://205.164.62.15:9010/
/usr/bin/mpc add http://streaming.radionomy.com/PassionLoveRadio
/usr/bin/mpc add http://176.31.240.87:8025
/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://streaming.radionomy.com/CristalRelax
/usr/bin/mpc add http://streaming.radionomy.com/Radio-Quelit
/usr/bin/mpc add http://streaming.radionomy.com/R-E-T-R-OF-M
/usr/bin/mpc add http://streaming.radionomy.com/radio-accordeon
/usr/bin/mpc add http://streaming.radionomy.com/100-HIT-ra
/usr/bin/mpc add http://streaming.radionomy.com/colombiaromantica
/usr/bin/mpc add http://streaming.radionomy.com/GOLDEN-SIXTIES-SEVENTIES-EIGHTIES-RADIO
/usr/bin/mpc add http://streaming.radionomy.com/radio-oldies-and-rock--n--roll
/usr/bin/mpc add http://hr-mp3-m-h3.akacast.akamaistream.net/7/785/142133/v1/gnl.akacast.akamaistream.net/hr-mp3-m-h3
/usr/bin/mpc add http://streaming.hotmix-radio.net/hotmixradio-lounge-128.mp3
/usr/bin/mpc add http://streaming.radionomy.com/Ambiance-Reggae
/usr/bin/mpc add http://streaming.radionomy.com/always-80s
/usr/bin/mpc add http://streaming.radionomy.com/Hit-s-My-Music-Pop-Rock
/usr/bin/mpc add http://streaming.radionomy.com/Cafe-Romantico-Radio
/usr/bin/mpc add http://streaming.radionomy.com/1000-HITS-Sweet-Radio
/usr/bin/mpc add http://46.37.20.205:8000/rdsmp3
/usr/bin/mpc add http://89.16.185.174:8003/stream
/usr/bin/mpc add http://89.16.185.174:8000/stream
/usr/bin/mpc add http://89.16.185.174:8004/stream
/usr/bin/mpc add http://streaming.radionomy.com/Fm-Tropical-Shad-972
/usr/bin/mpc add http://streaming.radionomy.com/NashvilleEdge
/usr/bin/mpc add http://streaming.radionomy.com/Abacusfm-Nature
/usr/bin/mpc add http://streaming.radionomy.com/chd--radio-country
/usr/bin/mpc add http://streaming.radionomy.com/1-Radio-Dance
/usr/bin/mpc add http://streaming.radionomy.com/Acoustic-FM
/usr/bin/mpc add http://streaming.radionomy.com/ABC-Love
/usr/bin/mpc add http://streaming.radionomy.com/Radio-Nostalgia
/usr/bin/mpc add http://andromeda.shoutca.st:8634/stream
/usr/bin/mpc add http://streaming.radionomy.com/Tsjechische-Blaasmuziek
/usr/bin/mpc add http://streaming.radionomy.com/DanceRO
/usr/bin/mpc add http://streaming.radionomy.com/BobFamilyandfriends
/usr/bin/mpc add http://streaming.radionomy.com/The-Buffalo
/usr/bin/mpc add http://streaming.radionomy.com/VWClassicRock
/usr/bin/mpc add http://icecast2.rte.ie/ieradio1
/usr/bin/mpc add http://listen.radionomy.com/the-smooth-lounge
#
/usr/bin/mpc add http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1_mf_p
/usr/bin/mpc add http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1xtra_mf_p
/usr/bin/mpc add http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio2_mf_p
/usr/bin/mpc add http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio3_mf_p
/usr/bin/mpc add http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4fm_mf_p
/usr/bin/mpc add http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4lw_mf_p
/usr/bin/mpc add http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4extra_mf_p
/usr/bin/mpc add http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio5live_mf_p
/usr/bin/mpc add http://bbcmedia.ic.llnwd.net/stream/bbcmedia_6music_mf_p
/usr/bin/mpc add http://bbcmedia.ic.llnwd.net/stream/bbcmedia_asianet_mf_p
/usr/bin/mpc add http://bbcmedia.ic.llnwd.net/stream/bbcmedia_nangaidheal_mf_p
#

(Last edited by pilovis on 8 Jan 2017, 14:36)

I'm used to listen to my Internet Radio until late at night and often I fall asleep listening some ambient music.
The problem is that the radio needs to be switched off to not to bother my neighbors

so I created a series of cron jobs to gradually reduce the audio volume during the night and then stop playing music:

vi /etc/crontabs/root

0 22 * * * /usr/bin/mpc volume 85 #volume 85-100
30 22 * * * /usr/bin/mpc volume 83 #volume 83-100
0 23 * * * /usr/bin/mpc volume 80 #volume 80-100
30 23 * * * /usr/bin/mpc volume 77 #volume 77-100
0 0 * * * /usr/bin/mpc volume 75 #volume 75-100
0 1 * * * /usr/bin/mpc volume 73 #volume 73-100
30 1 * * *  /usr/bin/mpc stop # stop playing

note: you may change the volume values to adapt them to your radio configuration.

If you use madplay or if you have a broken MPD version (barrier breaker), you may use the following command:

/usr/bin/amixer -q set Speaker X%-

(instead of using "/usr/bin/mpc volume X")

something like this:

0 22 * * * /usr/bin/amixer -q set Speaker 15%-
30 22 * * * /usr/bin/amixer -q set Speaker 10%-
0 23 * * * /usr/bin/amixer -q set Speaker 10%-
30 23 * * * /usr/bin/amixer -q set Speaker 10%-
0 0 * * * /usr/bin/amixer -q set Speaker 10%-
0 1 * * * /usr/bin/amixer -q set Speaker 10%-

the only difference is that in this case we are specifying the amount of volume in percentage to be decrease, instead of specifying the absolute value, as the above example.

P.S.: remember to re-enable "ntp" if you have disabled it to save some RAM usage.
If you don't have luci and want to set up the correct date/time, getting the values from internet, put the following lines in your /etc/rc.local:

# get date-time
/bin/echo GMT-1 > /etc/TZ
/usr/sbin/ntpd -q -p ntp1.ien.it

note: change GMT-1 with your local timezone

(Last edited by pilovis on 24 Jan 2017, 23:30)

Just getting into this project. I've seem posts that say bad USB sound adapters pop & click. Anyone have a recommendation. I already have a router coming.  Thanks for any advice.

My TL-WDR4300 has 3 buttons - WPS, WiFi on/off, Power button.
I am not really familiar with all this electronic stuff but I have a feeling that WiFi and Power are not those buttons which could be programmed.
Have you had any similar experience with built-in buttons?

I need to clarify this before kill-reincarnate activities.

Which version of mpd are your running.  I built my off the info on mightyohm and can't get any stream that uses AAC to play audio since it runs mpd ver 0.13. Other streams seem to work.
My Asus WL-520gu seems like it might be too limited in memory to upgrade the o/s to a later version with a newer mpd version.

thanks for any advice

Just ordered a TP-Link TL-WDR3600 to replace the ASUS WL-520GU. Hopefully I can get this one working with a current version MPD that can handle decoding AAC. The asus had limited ram so I couldn't update it. At least not that I know of.

Did I also see someone mention running a web page on the router that allows you to change the channel on the MPD?
If anyone has a link for this, let me know.

(Last edited by cgchris99 on 20 Apr 2017, 17:36)

pilovis, did you think the Raspberry Pi is a better option now?

sqr wrote:

My TL-WDR4300 has 3 buttons - WPS, WiFi on/off, Power button.
I am not really familiar with all this electronic stuff but I have a feeling that WiFi and Power are not those buttons which could be programmed.
Have you had any similar experience with built-in buttons?

I need to clarify this before kill-reincarnate activities.

For wifi button edit "/etc/rc.button/rfkill"
for power button edit "/etc/rc.button/power"