Building a Wifi Radio – Part 9, A Few Odds and Ends

This is the ninth part of an ongoing series about building a low cost, open source streaming internet radio based on the ASUS WL-520gU Wireless Router.  If you haven’t already, check out the previous parts (see the links at the end of this article) for some background about the project.

In part eight, we added a tuning control for the radio.  Now we can change to any of ten preset stations on the radio by adjusting the position of a potentiometer connected to our AVR microcontroller.   The LCD display we built in part seven lets us know what stream we’re listening to and the artist and title of the current song.  This project is coming together very nicely!

Before we put the final touches on this project in part ten, there are a few miscellaneous chores to take care of:

Fixing /etc/config/wireless:

Last time, we tweaked /etc/config/network to assign a static IP address to the LAN (ethernet) ports of the router.  This allowed us to directly connect a computer to the router via an ethernet cable and get a shell prompt, regardless of the state of the serial console or the wireless connection of the router.  Unfortunately, I made an omission in the setup instructions which may prevent this from working correctly.

To fix this, modify /etc/config/wireless as follows (changes are in bold, use your wireless network information in place of my example):

config wifi-device  wl0
    option type     broadcom
    option channel  3

    # REMOVE THIS LINE TO ENABLE WIFI:
    # option disabled 1

config wifi-iface
    option device   wl0
    option network  wan
    option mode     sta  # configures the router to connect to your network
    option ssid     MyNetwork # the SSID of your network
    option encryption wep  # the encryption mode of your network
    option key	XXXXXXXXXX  # add this line with your WEP key in place of X...X

The only change is to set “option network” to “wan” instead of “lan”.  This minor change tells the router to separate the wireless interface of the router from the LAN/ethernet interface and allows the router to acquire two separate IP addresses, one for each interface.

Launching mpd automatically at startup:

Manually launching mpd every time the router boots is a drag.  You can automate this by creating a symbolic link to /etc/init.d/mpd from the /etc/rc.d directory, as follows:

root@OpenWrt:~# ln -s /etc/init.d/mpd /etc/rc.d/S93mpd

Now every time the router boots, mpd will be started automatically as part of the boot process.  (That was easy!)

Boot script for the user interface:

Assuming we want a dedicated internet radio that doesn’t require user intervention to operate, the scripts for the LCD display and tuning control should also be launched at startup.  This will ensure that upon applying power, the radio will boot into a state where a stream is playing and the user interface is active.

First, we need to create a simple boot script.  Create the file /etc/init.d/AVR with the following contents:

#!/bin/sh /etc/rc.common
# Copyright (C) 2008 OpenWrt.org
START=99
start() {
sleep 5    # make sure boot process is done, no more console messages
/root/interface.sh
}

To launch the script at boot, create a symbolic link as follows:

root@OpenWrt:~# ln -s /etc/init.d/AVR /etc/rc.d/S99AVR

Every time the router boots, the user interface will automatically start, mpd will start playing the selected stream based on the tuner position, and the AVR microcontroller (assuming it is still connected to the serial port) will update the LCD display and watch the potentiometer for any changes in position.

Tweaking the firewall configuration:

This is actually optional, but it can be pretty useful while hacking on the router.  As presently configured, the router blocks incoming requests on the WAN, which now includes the wireless interface.  This prevents us from using ssh or telnet to log into the router over our wireless network.  While we can still get a shell by connecting an ethernet cable to one of the LAN ports on the router, it is often more convenient to access the router across your wireless network.

The file /etc/config/firewall controls the firewall settings.  We’ll be modifying this file.

Open the file in vi and scroll down to this section:

config zone
    option name        wan
    option input    REJECT
    option output    ACCEPT
    option forward    REJECT
    option masq        1

Edit the “option input” line so that it looks like this:

config zone
    option name        wan
    option input    ACCEPT
    option output    ACCEPT
    option forward    REJECT
    option masq        1

Now restart the firewall (or just reboot the router):

root@OpenWrt:~# /etc/init.d/firewall restart

You should now be able to ssh or telnet into the router over your wireless network.

Enable SSH:

By the way, if you want to access the router with ssh instead of telnet, just set a root password.  The telnet daemon will be disabled (for security reasons) and replaced with an SSH daemon instead.  You can do this with the “passwd” command.

root@OpenWrt:~# passwd
Changing password for root
New password: *****
Retype password: *****
Password for root changed by root
root@OpenWrt:~#

Log out of your telnet session and use ssh to log back in with your favorite ssh client (don’t forget to tell the client to use the username “root”).

Stay tuned!

Wifi Radio Enclosure - Google Sketchup Model

That’s it for now.  Stay tuned for the final part in this series, part ten, in which I’ll talk about what it took to turn this Sketchup model into a real wooden case for the radio!

Update: Part ten (the final part in the series) is now online.

2 thoughts on “Building a Wifi Radio – Part 9, A Few Odds and Ends”

  1. Oh yeah . . . one problem I see is that to drive the LCD via the DLP-IO8, one
    would probably want to be able to write a proper program, in C or Perl, to
    run on the openwrt platform. This would have to “bit-bang” the DLP-IO8
    interface in order to drive the typical 44780 interface on an Optrex LCD.
    Does openwrt have Perl or Python or something available?

  2. Jeff, this is impressive. . . but it seems overkill to use another micro to supply
    the user interface. I may try to build an internet radio, but replace the Atmega
    business with this DLP-IO8
    USB to 8 i/o
    interface. This would allow the openwrt Linux to directly
    drive an LCD, plus with an analog input, it should be able to read the “tuning”
    potentiometer directly. The DLP-IO8 is made by dlpdesign.com, available from
    Digikey.com for about $30.

Leave a Reply to Bill DudleyCancel reply