WiFi stereo Internet Digital Radio Player with web interface

sezione dedicata ai sistemi operativi alternativi Open Source

WiFi stereo Internet Digital Radio Player with web interface

Messaggio da leggereda root » 19/07/2016, 15:12

WiFi stereo Internet Digital Radio Player with embedded web interface, all in 8 Mbytes of Flash! :)

following the previous post, after some tries, I was finally able to install a fully LAN/Wi-FI Internet Radio Player into a cheap router with a single usb port, 32 Mbytes of ram and 8 Mbytes of Flash plus a cheap USB Audio card and ... nothing else :)

I choosed the TP-Link TL-WR710N router because of its integrated power supply, I don't want to have any power cord laying around!

Immagine Immagine

These are the instructions to configure and install it on a TP-Link TL-WR710N Router:

Install Barrier Breaker 14.04 firmware for TL-WR710N router:
https://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/openwrt-ar71xx-generic-tl-wr710n-v1-squashfs-factory.bin

configure your router as usual: system, ssh access, network, dhcp and WiFi (we'll keep these configurations),

test it but do not install any package.

Update the firmware with my custom firmware (see below) using Luci interface but do not forget to enable the option to keep settings! (current configuration files)

this is my custom firmware for TL-WR710N without luci, ppp and IPv6 to save precious space:
http://www.lovisolo.com/asterisk/software/openwrt/firmware/TP-Link_TL-WR710/Barrier_Breaker_14.07/ar71xx_senza_luci_ppp_ipv6/openwrt-ar71xx-generic-tl-wr710n-v1-squashfs-sysupgrade.bin
(you may also use it for any other project, if you want to use a different router you need to build your custom specific firmware)

After the firmware update (a few minutes) the router reboots
then you can access it as usual (by ssh access because there is no more luci interface)
then give the following commands:

opkg update
opkg install kmod-sound-core
opkg install kmod-usb-audio
opkg install alsa-utils
opkg install mpd-mini
opkg install mpc
mkdir /root/music
mkdir /root/playlist
touch /root/mpd.db


edit mpd configuration file to match the following

vi /etc/mpd.conf

#
music_directory "/root//music"
playlist_directory "/root/playlists"
db_file "/root/mpd.db"


bind_to_address "127.0.0.1"
port "6600"


input {
plugin "curl"
}


audio_output {
type "oss"
name "My OSS Device"
device "/dev/dsp" # optional
}


replaygain "album"
volume_normalization "yes"
samplerate_converter "internal"
audio_buffer_size "8192"
buffer_before_play "30%"


# eof

Note: vi commands
"I" to edit file
press "Esc" and ":" and "wq" to save

launch mpd for the first time (ignore errors)

mpd

then reboot

reboot

Install PHP support

opkg update
opkg install php5 php5-cgi


Configure uhttpd web server for PHP

vi /etc/config/uhttpd

config uhttpd 'main'
list listen_http '0.0.0.0:80'
list listen_http '[::]:80'
list listen_https '0.0.0.0:443'
list listen_https '[::]:443'
option home '/www'
option rfc1918_filter '1'
option max_requests '3'
option max_connections '100'
option cert '/etc/uhttpd.crt'
option key '/etc/uhttpd.key'
option cgi_prefix '/cgi-bin'
option script_timeout '60'
option network_timeout '30'
option http_keepalive '20'
option tcp_keepalive '1'
option ubus_prefix '/ubus'
option config '/etc/httpd.conf'

option interpreter '.php=/usr/bin/php-cgi'
option index_page 'index.php index.html'


config cert 'px5g'
option days '730'
option bits '1024'
option country 'DE'
option state 'Berlin'
option location 'Berlin'
option commonname 'OpenWrt'

create working directory

mkdir /www/music

install and launch ftp server to load files form your pc to the router

opkg install vsftpd
/etc/init.d/vsftpd start


transfer with a ftp client (user = root) from your pc all the files you'll find inside the "www" directory of the following zip file:
http://www.lovisolo.com/asterisk/software/openwrt/radio-mp3/www.zip
into the router "/www/music" directory

enable mpd to autostart at boot

/etc/init.d/mpd enable

then reboot

reboot

adding radio stations

To add internet radio stations use the following command:

mpc add
(sreaming-url)

some stations to add:
mpc add http://144.76.106.52:7000/chillout.mp3
mpc add http://icestreaming.rai.it/4.mp3
mpc add http://205.164.62.15:9010/
mpc add http://srv6.karadio.biz:20474/
mpc add http://streaming.radionomy.com/PassionLoveRadio
mpc add http://176.31.240.87:8025
mpc add http://stream.srg-ssr.ch/m/rsj/mp3_128
mpc add http://stream.srg-ssr.ch/m/rsc_it/mp3_128
mpc add http://stream.srg-ssr.ch/m/rsp/mp
mpc add http://streaming204.radionomy.com:80/100-CHILL
mpc add http://streaming.radionomy.com/CristalRelax
mpc add http://streaming.radionomy.com/Radio-Quelit
mpc add http://streaming.radionomy.com/GOLDEN-SIXTIES-SEVENTIES-EIGHTIES-RADIO
mpc add http://streaming.radionomy.com/R-E-T-R-OF-M
mpc add http://streaming.radionomy.com/radio-accordeon
mpc add http://streaming.radionomy.com/100-HIT-ra
mpc add http://streaming.radionomy.com/colombiaromantica
mpc add http://streaming.radionomy.com/Ambiance-Reggae
mpc add http://streaming.hotmix-radio.net/hotmixradio-lounge-128.mp3
mpc add http://streaming.radionomy.com/always-80s
mpc add http://streaming.radionomy.com/Hit-s-My-Music-Pop-Rock
mpc add http://streaming.radionomy.com/Cafe-Romantico-Radio
mpc add http://streaming.radionomy.com/1000-HITS-Sweet-Radio
mpc add http://46.37.20.205:8000/rdsmp3
ecc.

Now you can access the web interface from http://ip-of-your-router/music
example: http://192.168.1.1/music

NOTE: this interface needs Chrome browser to be correctly displayed.

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

Extra stuffs

To save anytime your current audio volume level, launch the following command:

/usr/sbin/alsactl -f /etc/alsa0.state store 0

and then to restore it on boot, insert the following line in "/etc/rc.local" file, right before the "exit 0" line

vi /etc/rc.local

/usr/sbin/alsactl -f /etc/alsa0.state restore 0

-------------------------------------------------------------
Web interface as seen from an Android/iPhone smartphone:

Immagine

NOTE: this interface needs Chrome browser to be correctly displayed.
Volume up and volume down do not seem to work
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: WiFi stereo Internet Digital Radio Player with web inter

Messaggio da leggereda root » 19/07/2016, 17:09

It seems there is a bug in mpd/mpc for OpenWRT:
the "mpc add" command does not update the database file, so at the reboot you won't find any station to play :(

but I found a workaround ;)
it is the following:

edit the "/etc/rc.local" file as the following:

vi /etc/rc.local


# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.


#
# restore audio volume
/usr/sbin/alsactl -f /etc/alsa0.state restore 0
#
# add new URLs starting from here:


/usr/bin/mpc add http://144.76.106.52:7000/chillout.mp3
/usr/bin/mpc add http://icestreaming.rai.it/4.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/GOLDEN-SIXTIES-SEVENTIES-EIGHTIES-RADIO
/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/Ambiance-Reggae
/usr/bin/mpc add http://streaming.hotmix-radio.net/hotmixradio-lounge-128.mp3
/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


# do not remove or modify the two lines below
/usr/bin/mpc repeat on
exit 0


with this workaround, at the startup, the radio stations will be added to the MPD daemon.
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: WiFi stereo Internet Digital Radio Player with web inter

Messaggio da leggereda root » 22/07/2016, 21:29

To use the led of the TL-WR710 as a WiFi indicator (wifi connection and network activity), this is the piece of configuration to put in the "/etc/config/system" file:

config led
option default '0'
option sysfs 'tp-link:blue:system'
option trigger 'netdev'
option dev 'wlan0'
option mode 'link tx rx'
option name 'WiFI
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: WiFi stereo Internet Digital Radio Player with web inter

Messaggio da leggereda root » 22/07/2016, 21:30

I put this OpenWRT Digital Internet Radio inside an old and beautiful stereo radio receiver from 1964 (all with vacuum tubes).
The original FM section is defective (I'm able but too lazy to repair it) but the stereo amplifier is still superb with strong bass and brilliant high frequencies.

Now I have one of the very few (maybe the only one) "Vacuum Tubes WiFi Digital Stereo Internet Radio" :D

Immagine
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

addendum

Messaggio da leggereda root » 22/07/2016, 21:31

there is enough remaining space on the OpenWRT Radio described above to also install Triggerhappy to use the buttons (if any) on your USB audio device to control MPD: play, next radio station, prev radio station, volume up, volume down and mute.

Install triggerhappy:

opkg update
opkg install kmod-usb-hid
opkg install kmod-hid kmod-hid-generic
opkg install kmod-hid kmod-hid-generic
opkg install kmod-usb-uhci
opkg install kmod-button-hotplug
opkg install kmod-gpio-button-hotplug
opkg install kmod-usb-ohci
opkg install triggerhappy


edit the config file of triggerhappy "/etc/triggerhappy/triggers.d/example.conf":

vi /etc/triggerhappy/triggers.d/example.conf


#
# To view a list of supported event codes, use "thd --listevents" or
# "thd --dump /dev/input/event*"
#
# Format:
# <eventcode> <value> <command>
#
# values for key events are 1 (pressed), 0 (released) or 2 (held)
#
## control mpd
# start playing
KEY_PLAYPAUSE 1 /usr/bin/mpc play
# next station
KEY_NEXTSONG 1 /usr/bin/mpc next
# prev station
KEY_PREVIOUSSONG 1 /usr/bin/mpc prev
#
## control audio volume
# increase volume +2%:
KEY_VOLUMEUP 1 /usr/bin/amixer -q set Speaker 2%+
# set the volume at the minimum audible level (MUTE mode)
KEY_MIN_INTERESTING 1 amixer -q set Speaker 4
# decrease volume -2%:
KEY_VOLUMEDOWN 1 /usr/bin/amixer -q set Speaker 2%-
#
# 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* "


then enable triggerhappy to be launched at the startup:

/etc/init.d/triggerhappy enable

reboot and enjoy :)

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

This is the one i used:

Immagine
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

and some tweakings to improve radio functionality

Messaggio da leggereda root » 22/07/2016, 21:31

32 Megabytes of Ram are just the bare minimum for this internet radio to run, every extra kilobyte available is important.

Here are some tips to stop some useless (for this application) services to save some RAM and CPU usage:

Stop ntpd service by editing "/etc/config/system" and disable it:

config timeserver 'ntp'
option enabled '0'


Disable console on serial port (UART) by editing "/etc/inittab" and comment out the line like the following:

#::askconsole:/bin/ash --login

edit "/etc/php.ini" and change the memory limit = 8 Mbytes to 4 Mbytes

Disable logging:

/etc/init.d/log disable

Disable sysfixtime:

/etc/init.d/sysfixtime disable

Disable dnsmasq:

/etc/init.d/dnsmasq disable

then reboot to apply.

Now if you run the top command you should see something like this:

Mem: 26016K used, 2844K free, 0K shrd, 468K buff, 2172K cached
CPU: 19% usr 4% sys 0% nic 75% idle 0% io 0% irq 0% sirq
Load average: 0.23 0.22 0.11 1/37 1547
PID PPID USER STAT VSZ %VSZ %CPU COMMAND
990 1 root S 20976 73% 21% /usr/bin/mpd
945 1 root S 1552 5% 2% /usr/sbin/wpa_supplicant -B -P /var/r
1449 1284 root R 1364 5% 1% top
6 2 root SW 0 0% 0% [kworker/u2:0]
341 2 root SW 0 0% 0% [kworker/u2:2]
678 1 root S 1544 5% 0% /sbin/netifd
786 1 root S 1512 5% 0% /usr/sbin/uhttpd -f -h /www -r OpenWr
1 0 root S 1388 5% 0% /sbin/procd
1284 1274 root S 1364 5% 0% -ash
1134 678 root S 1360 5% 0% udhcpc -p /var/run/udhcpc-eth0.pid -s
1274 732 root S 1220 4% 0% /usr/sbin/dropbear -F -P /var/run/dro
732 1 root S 1152 4% 0% /usr/sbin/dropbear -F -P /var/run/dro
464 1 root S 884 3% 0% /sbin/ubusd
996 1 root S 804 3% 0% /usr/sbin/thd --socket /tmp/triggerha
8 2 root SW 0 0% 0% [kworker/u2:1]
4 2 root SW 0 0% 0% [kworker/0:0]
257 2 root SW 0 0% 0% [kworker/0:2]
338 2 root SWN 0 0% 0% [jffs2_gcd_mtd3]
3 2 root SW 0 0% 0% [ksoftirqd/0]
97 2 root SW 0 0% 0% [kswapd0]


Without the "top" process we have just 3 megabytes of Ram available, not too much but enough :)

If you want to use a MPD client instead of the integrated web page, disable uhttpd (/etc/init.d/uhttpd disable), this will save other 2 megabytes of Ram.
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: WiFi stereo Internet Digital Radio Player with web inter

Messaggio da leggereda root » 22/07/2016, 21:32

By using a USB headset instead of the USB audio adapter, and four AAA rechargeable batteries or a small 5v power bank (to be connected inside the router) you can use this as a portable WiFi Digital Internet Radio ;)
[the main power socket of this router is detachable]
When connected to the main supply voltage the batteries or power bank are recharged (a recharging circuit is needed).
You may also use a traditional stereo headset (3.5 mm jack), but in this case you have to use the USB audio adapter, it might be fitted inside the router case as well.

It could be also solar powered since the total power consumption is no more than 5W.

Immagine

Immagine
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: WiFi stereo Internet Digital Radio Player + web interfac

Messaggio da leggereda root » 22/07/2016, 21:32

I've just created a very simple and light web page to let control the radio by Firefox browser without using PHP (too much memory comsumption).
The page is configured to be easily used by a smartphone bowser, there are no frills, just the bare essentials :D
The audio volume control is not implemented yet, mostly because the "mpc volume" command does not function in this Openwrt version :(, anyway you can use other solutions to control the audio volume by a cgi script (eg. /usr/bin/amixer -q set device value)


The idea is to use cgi.

This is just an example of the /www/cgi-bin/play.cgi script:

#!/bin/ash
/usr/bin/mpc
play > /dev/null 2>&1
/bin/echo ""
/bin/echo '<FORM><INPUT Type="button" VALUE="buffering ... press to go back" onClick="history.go(-1);return true;" style="font-family: sans-serif; font-size: 60px;"></FORM>'


in the others scripts (called by the index.html) just change the mpc command: next, prev, stop, ecc


this is the /www/index.html example:

<html>
<head>
<title>Internet digital radio</title>
</head>
<body>
<meta http-equiv="refresh" content="5" >
<p>
<iframe
style="background: #AAFFFF"
src ="/cgi-bin/test.cgi"
width="640px"
height="80px">
</iframe>
<hr>
<FORM ACTION="/cgi-bin/next.cgi">
<INPUT TYPE=SUBMIT VALUE="Next >>" style="font-family: sans-serif; font-size: 90px;">
</FORM>
<FORM ACTION="/cgi-bin/play.cgi">
<INPUT TYPE=SUBMIT VALUE="Play >" style="font-family: sans-serif; font-size: 90px;">
</FORM>
<FORM ACTION="/cgi-bin/stop.cgi">
<INPUT TYPE=SUBMIT VALUE="Stop || " style="font-family: sans-serif; font-size: 90px;">
</FORM>
<FORM ACTION="/cgi-bin/prev.cgi">
<INPUT TYPE=SUBMIT VALUE="Prev <<" style="font-family: sans-serif; font-size: 90px;">
</FORM>
<hr>
by P.M. Lovisolo 2016 - parknat12@yahoo.com
</body>
</html>



This is the /www/cgi-bin/test.cgi called by index.html to display into the <iframe> the current song and other system informations:

#!/bin/ash
#
#now=$(date)
/bin/echo ''
#/bin/echo $now
cpu=$(grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}')
uptime=$(/usr/bin/uptime)
/bin/echo 'Uptime:' $uptime
/bin/echo "CPU usage:" $cpu
/bin/echo '---------------------------------------------------------------------------------'
song=$(/usr/bin/mpc current)
/bin/echo "Now playing:" $song
# eof



Note: don't forget to give "chmod 755" permisisons to all cgi scripts!
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: WiFi stereo Internet Digital Radio Player with web inter

Messaggio da leggereda root » 22/07/2016, 21:32

... a simple page to edit (add, modify or remove) the radio stations URLs (as per my workaround above) directly from the browser, it uses PHP but it consumes only a few kilobytes of RAM:

vi /www/addurl.php

<?php


// configuration
$url = 'addurl.php';
$file = '/etc/rc.local';


// check if form has been submitted
if (isset($_POST['text']))
{
// save the text contents
file_put_contents($file, $_POST['text']);


// redirect to form again
header(sprintf('Location: %s', $url));
printf('<a href="%s">Moved</a>.', htmlspecialchars($url));
exit();
}


// read the textfile
$text = file_get_contents($file);


?>
<body bgcolor="#84b0fd" text="#030303" link="#9abcde">
This form permits you to add/modify/remove radio stations to MPD,
<br>
don't forget to insert <b>"/usr/bin/mpc add "</b> before the streaming URL.
<br>
<b></b>
<p>
<i>Note: do not remove the "exit 0" line!</i>
<p>
<!-- HTML form -->
<form action="" method="post">
<textarea rows="22" cols="80" name="text">
<?php echo htmlspecialchars($text) ?></textarea>
<br>
<input type="submit" />
<input type="reset" />
<p>
<td>
<table border="0" cellspacing="0" cellpadding="3" width="100%" bgcolor="#ffffff" align="center">
<td bgcolor="#000000" align="left">
<a href="index.html">Return to the radio control page</a></td>
</td>
</form>


then add a link to this page into the index.html file by adding the following code at the end of the file just before </body> line:

<td>
<table border="0" cellspacing="0" cellpadding="3" width="100%" bgcolor="#ffffff" align="center">
<td bgcolor="#FFFFFF" align="left">
<a href="addurl.php">Add new radio stations</a></td>
</td>
</form>


or else:

<hr>
<button onclick="location.href = 'addurl.php';" id="myButton" class="float-left submit-button" >Add new Radio Stations</button>
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: WiFi stereo Internet Digital Radio Player with web inter

Messaggio da leggereda root » 26/07/2016, 16:25

in case something went wrong (eg. you have mistakenly edited the configuration files) and you cannot connect to your router, to gain access to it follow this procedure:

Disconnect WAN cable
Unplug power to router
Set your computers IP address to:
IPv4 Address: 192.168.1.2
Netmask: 255.255.255.0
Gateway: 192.168.1.1

Re-power your router, press the ‘reset’ button when the led begin blinking, then when you release the reset button the led should start blinking much faster.

Using PuTTY (or your favourite *TELNET* client), connect to 192.168.1.1 and you should see the OpenWrt prompt. Type the command below (in red) than you can edit the files on your router:

-----------------------------------------------------
root@(none):/# mount_root
jffs2 is ready
jffs2 is ready
switching to overlay


vi /etc/file ...
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Prossimo

Torna a OpenWRT e sistemi operativi vari

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite

cron