Tag Archives: OpenWRT

Building a Wifi Radio – Part 5, Let’s Make Some Noise!

This is the fifth part of an ongoing series at mightyOhm about building a low cost, open source streaming internet radio.  If you haven’t already, check out the previous parts below for some background about the project.

Building a Wifi Radio – Part 1, Introduction

Building a Wifi Radio – Part 2, Choosing an Embedded Platform

Building a Wifi Radio – Part 3, Hacking the Asus WL-520GU

Building a Wifi Radio – Part 4, Installing OpenWrt

Note:

The instructions that follow assume that you have an Asus WL-520GU wireless router with the following modifications: an externally accessible serial port, OpenWrt installed and working, and a configured network connection on the router.  If not, check out the previous parts of the series to learn more.

Using opkg to customize OpenWrt:

OpenWrt includes a utility called opkg that allows the end user to easily add and remove optional software packages.  These packages include functionality that is not a part of the OpenWrt base image, such as hardware drivers (including USB), optional software, and utilities.  Most packages are not installed by default (after all, the router only contains 4MB of flash storage).  The OpenWrt Community Wiki includes a very helpful page about Packages that contains a lot of useful information about configuring and using opkg.

Before we can use opkg we need to configure it.  The file /etc/opkg.conf contains a few options, including the URL of the server opkg uses to find and download packages.  We need to change this server from the default by modifying the config file:

root@OpenWrt:~# vi /etc/opkg.conf

Modify the first line to look like this:

src/gz snapshots http://mightyohm.com/files/kamikaze-2.4/packages/mipsel 
dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists

You can also download the complete set of packages and set up a server of your own for opkg to access.  I have had great success using the apache server included with OS X, but I won’t cover the setup here.

The following command tells opkg to fetch a list of available packages from the server:

root@OpenWrt:~# opkg update

You should see the following response:

Downloading http://mightyohm.com/files/kamikaze-2.4/packages/mipsel/Packages.gz
Connecting to mightyohm.com (72.32.209.132:80)
Packages.gz          100% |*******************************|  8326  --:--:-- ETA
Inflating http://mightyohm.com/files/kamikaze-2.4/packages/mipsel/Packages.gz
Updated list of available packages in /var/opkg-lists/snapshots
Signiture check for snapshots skipped because GPG support was not enabled in this build

Now we can start installing packages.  To access our USB-audio converter, we need to install USB 1.1 (OHCI) support and some sound drivers:

root@OpenWrt:~# opkg install kmod-usb-audio kmod-usb-ohci

This should automatically install kmod-usb-core and kmod-sound-core, but if not you can also install them manually with the opkg install command.

At this point you should insert the USB-audio converter if you haven’t already.  Then reboot the router:

root@OpenWrt:~# reboot

As the router is booting again, watch for new status messages like these:

...
usb-ohci.c: USB OHCI at membase 0xb8003000, IRQ 6
usb-ohci.c: usb-00:03.0, PCI device 14e4:471a
usb.c: new USB bus registered, assigned bus number 1
usb.c: registered new driver audio
audio.c: v1.0.0:USB Audio Class driver
usbaudio: device 2 audiocontrol interface 0 has 1 input and 1 output AudioStreaming interfaces
usbaudio: device 2 interface 2 altsetting 1 channels 1 framesize 2 configured
usbaudio: valid input sample rate 48000
usbaudio: valid input sample rate 44100
usbaudio: device 2 interface 2 altsetting 1: format 0x00000010 sratelo 44100 sratehi 48000 attributes 0x01
...
usbaudio: registered dsp 14,3
usbaudio: constructing mixer for Terminal 6 type 0x0301
...

If you see this, the USB-audio converter is most likely working and the correct drivers have been loaded.  At this point the green LED inside the USB-audio converter should be lit, another sign that everything is working correctly.

Installing mpd:

To actually play some tunes we need to install some additional software.  We can use opkg to do this, as follows:

root@OpenWrt:~# opkg update

root@OpenWrt:~# opkg install mpd mpc

This command installs mpd, the music player daemon.  mpd is an open source music server that can be accessed locally or across a network by using a variety of clients, which are available for many different platforms.  This includes the command line client mpc which is also now installed on the router.

mpd requires some setup before we can use it:

root@OpenWrt:~# cd ~
root@OpenWrt:~# mkdir .mpd
root@OpenWrt:~# mkdir music
root@OpenWrt:~# mkdir .mpd/playlists
root@OpenWrt:~# vi /etc/mpd.conf

Scroll down and look for the audio_output section of the mpd configuration file, and change the reference to /dev/dsp to make it look like this:

# An example of an OSS output:
#
audio_output {
        type                    "oss"
        name                    "My OSS Device"
        device                  "/dev/sound/dsp"
        format                  "44100:16:2"
}

There are many other options you can play with; mpd is very powerful.  There is a list of features here and a lot more information on the mpd wiki.

Exit vi, saving the changes to mpd.conf.  Now launch mpd with the following command:

root@OpenWrt:~# mpd

The player should start silently, without errors.  Run mpc and verify that it can talk to the server:

root@OpenWrt:~# mpc
volume:100%   repeat: off   random: off

If you see this, good news, the server is running and we have the ability to control it with mpc!

Now would be a good time to connect speakers or headphones to the USB-audio adapter’s headphone output.  Warning – the initial volume can be VERY LOUD. Don’t wear headphones during testing!  PC speakers with a volume control are best.  Start at a low volume.  (My ears are still ringing!)

We can add a streaming radio server to the playlist by executing

root@OpenWrt:~# mpc add http://relay3.slayradio.org:8000/
adding: http://relay3.slayradio.org:8000/

And finally, the moment of truth:

root@OpenWrt:~# mpc play
http://relay3.slayradio.org:8000/
[playing] #1/1   0:00/0:00 (100%)
volume:100%   repeat: off   random: off
root@OpenWrt:~#

If all goes well, within a few seconds you should hear Slay Radio playing on your headphones or speakers.  The Air light on the router should flicker as traffic crosses the WiFi interface, and the green light on the USB-audio converter should flash repeatedly to indicate that audio is being sent to the device.

If you’ve made it this far, I recommend celebrating with your favorite beverage and enjoying some tunes!  Congratulations!

You can add other servers to the playlist by executing the mpc add command again, and then play them with the mpc play n command, where n is the position of the server in the playlist.  mpc playlist will display the current playlist. mpc help will give you a list of available commands.

One very powerful feature of mpd is that it operates as a server on port 6600 of the router, so it can be controlled from any other device on your local network.  If you download an mpd client such as Theramin, you can control the router remotely from your desktop computer.  There is an excellent client for the iPhone too.

That’s it for part five.  I hope you have enjoyed the series thus far.  In part six, we’ll start writing some scripts to control mpd and talk about options for a user interface.  If you are building a Wifi Radio of your own, I’d love to hear about it – leave a comment below!

Update: Part six is now available.

Building a Wifi Radio – Part 4, Installing OpenWrt

This is the fourth part of an ongoing series about building a low cost, open source streaming internet radio.  If you haven’t already, check out parts one, two, and three for some background about the project.

At this point you should have an Asus WL-520GU wireless router with a serial port header installed and some way of communicating with the serial port from your PC.  If not, go back to part three.

What is OpenWrt?

According to openwrt.org:

OpenWrt is described as a Linux distribution for embedded devices.

OpenWrt replaces the stock firmware on the WL-520GU with an open source Linux distribution that aims to be extremely powerful and flexible.  This is important for us because in turning a wireless router into a Wifi radio, we using the device in a way that the manufacturer never intended for it to be used.  In addition to including a stripped down version of the Linux operating system, drivers for wireless networking and all the basic functionality of a residential network gateway, a package manager called opkg allows you to install a wide variety of add-on modules to extend the functionality even further.

Setup:

To install OpenWrt on the WL-520GU you will need a few things:

  • Your Asus WL-520GU wireless router, modified to allow access to the internal serial port
  • A 3.3V USB-serial cable like the FTDI-232-3V3
  • A short ethernet cable (a crossover cable is not required)
  • A desktop or laptop computer with an open USB and ethernet port
  • A terminal program such as ZTerm or Hyperterminal
  • A TFTP client, (surprisingly) included with most operating systems.  I’ll be using the one included with OS X.
  • A WiFi network with a reasonably simple encryption scheme (ie. none, WEP, WPA)

If you want to compile your own OpenWrt image and optional packages, you’ll also need

  • A machine running Debian or similar Linux operating system, or if you are really ambitious, a Mac running OS X.  I won’t cover compiling OpenWrt using OS X here, but there are several issues that prevent it from being straightfoward, the first of which is that OS X does not use a case-sensitive filesystem by default.

Note: If for any reason you need to go back to the stock firmware, you can download it from Asus here (enter WL-520GU into the search field on the left).

Getting OpenWrt:

There are two ways to do this:

The hard way:

Visit the OpenWrt Wiki and read the instructions on Installation.  Follow these instructions to build Kamikaze (Kamikaze is the current OpenWrt distribution).  Download the source with subversion (svn), and compile it yourself.  This method requires a moderate level of skill with Linux, but if you can compile your own kernel you should be able to compile OpenWrt.  You will need to link to the feeds for madplay, mpc, and mpd (as well as any other 3rd party packages you want) before executing make menuconfig, by using the scripts/feeds command.  Here is the sequence of commands I used, yours may differ slightly:

svn co https://svn.openwrt.org/openwrt/trunk/ ~/kamikaze
cd ~/kamikaze
./scripts/feeds update -a
./scripts/feeds install madplay mpc mpd
make prereq

If make fails, you may need to install some optional Linux tools, such as gawk, bison, or gcc.  On Debian I used the apt-get command to do this

apt-get install gawk bison gcc

Once you have all necessary prerequisites installed, you can configure the build with

make menuconfig

You’ll need to set the following options:

  • Target System (Broadcom BCM947xx/953xx [2.4])
  • Target Profile (Generic, Broadcom WiFi (default))
  • Select all packages by default
  • Image configuration —>
    • Base system (Added 12/18/08 to support part six)
      • busybox (press enter to open hidden menu)
        • Configuration
          • Coreutils
            • stty
    • Kernel modules
      • Sound support
        • kmod-sound-core
      • USB support
        • kmod-usb-core
        • kmod-usb-ohci
        • kmod-usb-audio
    • Sound
      • mpd
      • mpc
      • madplay

Once you’re done, exit, saving the configuration.  Then execute

make world

This will take quite a while.  If the build fails, you will be prompted to run make again

make world V=99

and fix any problems that occur, based on the error messages.  The OpenWrt forums are a good place to get help, but do a quick search before you post to avoid asking a question that has already been answered.

If the build completes successfully, you should be left with a bunch of files in the kamikaze/bin directory, including openwrt-brcm-2.4-squashfs.trx, the main image file, and a bunch of packages in the bin/packages/mipsel directory.

The easy way:

I’ve already done the hard work for you.

Download my precompiled openwrt-brcm-2.4-squashfs.trx image.

Addon packages (you’ll need a few of these when we configure the router later) are located here.

Installing OpenWrt:

Connect your FTDI cable to the serial port on the router that you added in part three.  Launch your favorite terminal program and connect to the router at 115200 baud, 8N1.

Connect the LAN1 port of the router to your computer using a short ethernet cable.  The router is hardcoded to be 192.168.1.1 on boot, and we need to configure our computer to talk to that address.  I set my Macbook to use a static IP of 192.168.1.185.  You may need to set a gateway to 192.168.1.1.  If your home network is also on the 192.168.1.x subnet, you will need to disconnect/disable it.  On my Macbook, this meant disabling the internal wireless and losing internet access while the router was connected.  (Eventually I got tired of this and moved my home network to 192.168.24.x, but that is outside the scope of this tutorial.)

Press and hold the Restore button on the back of the router and plug in the power cable.  The Restore button is shown just to the right of the red EZSetup button here:

WL-520GU Restore Button Closeup

Continue holding the Restore button until the power LED starts flashing once a second.  Release the restore button.  In your terminal window, you should see some boot messages and then

Reading :: TFTP Server.
Failed.: Timeout occured
Reading :: TFTP Server.
Failed.: Timeout occured

and so on (the messages will repeat forever).

Now it’s time to transfer our .trx file to the router.  These instructions are for OS X.  Instructions for other operating systems are here.

cd ~/kamikaze/bin
tftp
trace
timeout 1
mode binary
connect 192.168.1.1
put openwrt-brcm-2.4-squashfs.trx

On the serial console you should see (exact numbers may vary):

Reading :: TFTP Server.
TFTP_BLKLEN!!
break!! last block!!
Done. 1918724 bytes read
Download of 0x1d4704 bytes completed
Write kernel and filesystem binary to FLASH (0xbfc20000)
Programming...
copysize=1918724, amtcopy=1918724

If you don’t see this, chances are your computer is not talking to the router.  Most likely this is a configuration problem with your ethernet port or you don’t have the cable connected to a LAN port of the router.

If it worked, wait a couple minutes (don’t touch anything, unplugging the router at this point could brick the router!)  Eventually you should see the message

done. 1918724 bytes written

After this message appears (it typically takes 3-5 minutes for the whole process) unplug the router, wait a few seconds, and then plug it back in again.  In your serial terminal window, you should see the Linux boot messages again, but the process will pause briefly while the jffs file system is created.  Once the router has finished booting, you’ll see a couple messages like this

mini_fo: using base directory: /
mini_fo: using storage directory: /jffs

Press enter and you should now see the OpenWrt banner and a shell prompt

BusyBox v1.11.2 (2008-10-02 20:59:06 PDT) built-in shell (ash)
Enter 'help' for a list of built-in commands.
  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 KAMIKAZE (bleeding edge, r12831) -------------------
  * 10 oz Vodka       Shake well with ice and strain
  * 10 oz Triple sec  mixture into 10 shot glasses.
  * 10 oz lime juice  Salute!
 ---------------------------------------------------
root@OpenWrt:/#

Congratulations!  You have successfully installed OpenWrt!

A complete log of the first boot is available here.

Configuring OpenWRT:

There is a lot of information on the OpenWRT Wiki with regard to Configuring Kamikaze, but I will walk through the fairly basic configuration I am using here.  To follow along, you will need to be comfortable using vi (if not, check out this quick reference card.)

You should be able to use your serial terminal to execute the following commands.  I had issues using the arrow keys to navigate in vi and had to use the basic movement keys instead (h=left, l=right, k=up, j=down).

Before we can get the router on a WiFi network we need to modify a couple files.

root@OpenWrt:~# vi /etc/config/wireless

You should edit this file to look like this (changes are in bold)

config wifi-device  wl0
	option type     broadcom
	option channel  2  # the channel your wireless network is on

	# REMOVE THIS LINE TO ENABLE WIFI:
	# option disabled 1 (comment out or remove this line entirely)

config wifi-iface
	option device   wl0
	option network	lan
	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

Now we need to modify the networking configuration to use DHCP (this should apply for most people):

root@OpenWrt:~# vi /etc/config/network

Scroll down and look for the LAN configuration section, and edit it to look like this (note the dhcp option in bold, also comment out the last two lines as shown):

#### LAN configuration
config interface lan
      option type     bridge
      option ifname   "eth0.0"
      option proto    dhcp
      #option ipaddr   192.168.1.1
      #option netmask  255.255.255.0

Lastly, verify that resolv.conf is set correctly.

root@OpenWrt:~# vi /etc/resolv.conf

You should see the following line (this assumes the router will get a valid DNS server address via DHCP, if not, you can set it manually here):

nameserver 127.0.0.1

Then execute the following command:

root@OpenWrt:/# /etc/init.d/network restart

After a moment, if everything is working, the AIR light on the router should turn on and you should be able to ping some servers by name.

root@OpenWrt:/# ping www.google.com
PING www.google.com (74.125.19.104): 56 data bytes
64 bytes from 74.125.19.104: seq=0 ttl=240 time=20.113 ms

If you made it this far, congratulations!  You now have a working embedded Linux device on your WiFi network!

That concludes part four of this series.  In part five, I’ll cover installing addon packages using opkg.  If we’re lucky, we’ll get the router to play some tunes!

Update: Part five is now available.

Update 2: There is a new Wifi Radio Discussion Forum, hop over there to ask questions about the project or see what other people are working on!  (4/12/09)

Old Dell + Debian Etch = Instant Development Server

Earlier this year I replaced my desktop PC, a Dell Dimension 4700, with a Mac Mini as part of my effort go 100% Mac for my home computing.  OS X is a terrific platform for the desktop power user because it looks great, feels great, is well supported by open source projects.  It also runs on a variant of Unix giving you full shell access and lots of other great stuff.

Since then, the Dell has been sitting by my desk, waiting for a good use.  I already have a Linkstation Live that I use for a low power home server (print server, mt-daapd, subversion, samba, etc.) so I didn’t have an immediate need for another PC around the house.

Last week I started playing with OpenWRT as part of a neat new project that will be an upcoming feature on this blog.  I suddenly needed a Linux environment and some extra computing power to help build custom OpenWRT images.  Debian to the rescue!

Before anyone says anything, I don’t really have anything against the incredibly popular desktop Linux distro Ubuntu.  The real reason I choose Debian is that I know Debian, and Debian just works.  My new server runs headless and I use ssh to login and compile from my Mac, so the advanced graphical features of Ubuntu would be lost on me.

Installing Debian is a breeze.  Within 30 minutes of burning the Debian quick start CD, I was up and running.  After installing a few addon packages, I was compiling OpenWRT images.

Instant development server.  Awesome.