Make an OpenWRT WebRadio with Wr703n

From lechacal
Jump to: navigation, search

Overview

This will build a small webradio that plays a radio from the web as soon as powered up.

We will play this radio below for the example.

http://media-ice.musicradio.com:80/ClassicFM

More radios addresses can be obtained from these sites below.
http://www.listenlive.eu/
https://www.internet-radio.com/

Hardware

1 WR703N Note the unit must have 16MB flash. Default factory units won't work.
1 USB to audio adaptor UsbaudioAdaptor.jpg

Operating System

We will use OpenWRT LEDE 17.01.

Network setup will not be covered here. We assume the unit has access to the internet.

Install Packages

First run

$ opkg update 

Then install packages

$ opkg install kmod-usb-audio mpc mpd

Note: Some websites mention installs of kmod-sound-core kmod-usb-ohci alsa-utils. We did not find these to be needed for our purpose.

Setup Mpd

Edit the /etc/mpd.conf file. (Sound quality will be poor if not using alsa)

$ vi /etc/mpd.conf

Uncomment the lines to use alsa. These can be found from line 208. The text should look as this below:

# Audio Output ################################################################
#                                        
# MPD supports various audio output types, as well as playing through multiple
# audio outputs at the same time, through multiple audio_output settings    
# blocks. Setting this block is optional, though the server will only attempt
# autodetection for one sound card.                                       
#                                                                 
# An example of an ALSA output:
#                                                 
audio_output {
        type            "alsa"                                            
        name            "My ALSA Device"                               
        device          "hw:0,0"        # optional                    
##      mixer_type      "hardware"      # optional                         
##      mixer_device    "default"       # optional
##      mixer_control   "PCM"           # optional
##      mixer_index     "0"             # optional
}
#

Now restart mpd

$ /etc/init.d/mpd restart

Play the stream

Make sure the usb-audio dongle is connected.

DO NOT TEST THIS WITH EARPLUGS. Volume is 100%. Use speakers with volume control at minimum first.

Then run these two commands below:

$ mpc add http://media-ice.musicradio.com:80/ClassicFM 
$ mpc play

Once this works you can stop it with

$ mpc stop

Start playing at boot time

Edit the /etc/rc.local.

$ vi /etc/rc.local

We will now need to add the 2 lines and a small loop to make sure internet is on. The file should look like so below.

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

# Wait until we have internet connection.
while true; do
  ping -c1 google.com && break
  sleep 1
done

# Add the radio stream and play it
mpc add http://media-ice.musicradio.com:80/ClassicFM
mpc play

exit 0

Reboot the device to make sure it plays when booted.

$ reboot & exit

Other resources

A good and simple client player from a web browser: https://github.com/sn0opy/MPD-Webinterface