Here’s how i managed to turn a wireless router into a remote controlled music streamer. I am showing how to do this so that people can do the same

What you need:

  • A Netgear WGT634U – £30 on ebay
  • USB 2.0 Hub (mains powered) – £5-10 on ebay
  • USB Audio Card (linux compatible) – £10 from aria
  • USB LCD compatible with lcdproc (see here). – £20 from BWCT plus a cheap £5-10 HD44780 LCD module from ebay
  • USB infrared reciever compatible with lirc – £5-10 from ebay
  • Siemens C25, C35, C45 Data Cable
  • A computer running linux with a few GB spare on the Hard Disk

If you’re lucky you may be able to make this for under £90. It may not be as cheap as a second hand Netgear MP101 but the knowledge you can gain from doing this is extremely valuable.

I started with the project after reading nate true’s Wireless Music Player. He has sucessfully turned a Netgear WGT634U into a wireless music streamer. However it is remotely managed, meaning that you have to control it from a PC over telnet/ssh. I wanted a music player that could be controlled using a remote so that a PC does not have to be on. The system is based on OpenWrt (a linux distribution for wireless routers).

Getting Started

The first thing to do is to build an image for the WGT634U by running the OpenWrt buildroot. See this page for more details

To do this you will need to run from a terminal window.root@robert-linux:~$ svn co https://svn.openwrt.org/openwrt/trunk/

then cd into the trunk directory and run

root@robert-linux:~/mydocs/trunk$ make menuconfig
this will give you a screen as opposite. Now make the correct alterations to the config to suit your needs. Make sure you select Broadcom BCMxxxx….. with the Linux 2.6 kernel. Also ensure you have selected the Atheros Wifi Profile. You will also need kmod-usb-core, kmod-usb-soundcore, kmod-usb-2.0, kmod-usb-ohci,for the usb facilities. Also select the nfs and cifs filesystems. You may also need zlib. When you have selected the correct modules, libraries etc. just type:

root@robert-linux:~/mydocs/trunk$ make

is will take a long time and it will take up a GB or so disk space. Once this is done you will get a wgt634u bin file in the /trunk/bin directory. This is the router’s image file which will be programmed into the flash

Modifying the Data Cable

In order to program the router you will need modify the Siemens Data Cable to fit the serial pins on the router board. To do this you simply take the small end apart. There should be 3 wires connected to three different pins. Here’s which pins to use, from left to right:

  • Pin # 1 – GND (Black)
  • Pin # 5 – TX (Blue)
  • Pin # 6 – RX (White)

Next you will need to connect these to the pins on your router. I chose to use a spare servo cable i had from a model airplane. These are pretty cheap – less than £2. The plastic end of the servo cable fits neatly on the pins of the router.

The pins on the router are as follows – from top to bottom:

– 3v
– TX
– RX
– GND

You only need the TX, RX and GND pins. I discovered how to build the serial console on the SarWiki site. See here for more details on how to contruct the data cable.

Programming the router

You will need to setup a tftp server to program the router since the data cannot be programmed entirely down the serial cable. Instead you have to connect the WAN port on the router to the LAN port on your linux box with an ethernet cable and the router will be programmed via the ethernet cable using the tftp server. I used the TFTP server available at http://sourceforge.net/projects/tftp-server. It is easy to use. Simply specify a folder to use as a server in the tftpserver.ini file and copy it to /etc. Then run something like:

root@robert-linux:~$ sudo /home/yourusername/tftpservermt/tftpserver -v

practice by getting and putting a test file to and from the tftp folder.

root@robert-linux:~$ tftp localhost
tftp> get test.txt

Now that you know your tftp server is working correctly copy the openwrt-wgt634u-2.6-squashfs.bin (or similar) file into the tftp folder. You can now start programming the router. Connect your modifyed serial cable into the serial port on the back of your linux box. Then connect the other end to the serial pins on your router as above. You cannot simply connect them directly because they work on different levels. The router works on ttl level serial where as the pc uses RS-232 level. Next connect an ethernet cable, which you should get supplied with the router, to the WAN port on the WGT634U and to the LAN port on your linux computer. I used minicom (a serial communication technology) to interface with the router. If your run debian or ubuntu, you can simply run apt-get install minicom

Run minicom from a terminal window and then hold down Ctrl + C at the same time as inserting power into the WGT634U. This will halt the bootup operation so that you can write a new image. IF this doesn’t work straight away, as it didn’t for me then it is likely that you have the wrong device configured in minicom. To change this just hold Crtl + A and then Z. A help window should appear. Press O to go to configuration and go to serial port setup. if it says device: /dev/ttyS1 try changing it to /dev/ttyS0. This worked for me. Now I followed the intructions in the official doc page. I decided to use a static address rather than using the dhcp server. I did something like the following:

CFE> ifconfig eth0 -addr=192.168.1.10 -mask=255.255.255.0

Next is the command to write the image to the flash. Note, replace 192.168.1.4 with the ip address of the linux box with your tftp server. To find out simply type ifconfig eth0 from a blank terminal window.

CFE> flash -noheader 192.168.1.4:openwrt-wgt634u-2.6-squashfs.bin flash0.os

Once this is done boot into OpenWrt with reboot.

CFE> reboot

.Configuration

You cannot have the serial cable connected to the router the whole time so you need a way of communicating with the router wirelessly. This can be done via ssh. Before you can do that, you need to configure the router’s with network settings. First of all set a password for the root user to keep it secure.

root@OpenWrt:~# passwd

Next the WGT634U needs to be setup for use in Client Mode rather than as a router. http://openwrt.pbwiki.com and http://madwifi.org/wiki/UserDocs/FirstTimeHowTo are good resources for setting up the router in client mode. This is how i did it:

root@OpenWrt:~# wlanconfig ath0 destroy
root@OpenWrt:~# wlanconfig ath0 create wlandev wifi0 wlanmode sta
root@OpenWrt:~# iwconfig ath0 essid <your essid>
root@OpenWrt:~# iwconfig ath0 key <your wep key>
root@OpenWrt:~# ifconfig ath0 192.168.1.10 netmask 255.255.255.0 up
root@OpenWrt:~# route add default gw 192.168.1.1

To search for available networks to connect to use the following command:

root@OpenWrt:~# iwlist ath0 scan

I created a script in /etc/rc.d which runs every time OpenWrt boots up. Note it must start with S followed by a number. I called it S70wifi. You will need to use the legendary vim editor. Use the command vi /etc/rc.d/S70wifi. Commands for the vim editor are “i” to start writing “q” to quit and “wq” to save and quit. You need to press Esc before issuing these commands.

#!/bin/sh
wlanconfig ath0 destroy
wlanconfig ath0 create wlandev wifi0 wlanmode sta
iwconfig ath0 essid <your essid>
iwconfig ath0 key <your wep key>
ifconfig ath0 192.168.1.10 netmask 255.255.255.0 up
route add default gw 192.168.1.1

Also you may need to edit the /etc/config/network file so that it is similar to mine. The main alterations are that the lan interface sgould be only “ath0″ and so should the wan interface. Then fill in the network settings as required.

#### VLAN configuration
config switch eth0
option vlan0 “0 1 2 3 5*”
option vlan1 “4 5″

#### Loopback configuration
config interface loopback
option ifname “lo”
option proto static
option ipaddr 127.0.0.1
option netmask 255.0.0.0

#### LAN configuration
config interface lan
option ifname “ath0″
option proto static
option ipaddr 192.168.1.10
option netmask 255.255.255.0
option dns 192.168.1.1
option gateway 192.168.1.1

#### WAN configuration
config interface wan
option ifname “ath0″
option proto dhcp

Finally you can test whether everything works:

root@OpenWrt:~# ping google.co.uk

Just play around with this and read the madwifi wiki until you have it working. SSH uses port 22 so you need to open this port in the firewall. Edit the /etc/config/firewall file and add this line to it.

accept:proto=tcp dport=22

There is also another firewall file /etc/firewall.user which i also edited with the following: This should enable ssh to work correctly. Install putty and try accessing the router via ssh.

Installing the Packages

This is perhaps the most difficult and time consuming part of the whole project. The router works on the mipsel architechture so the software needs to be cross-compiled. This can be done with the OpenWrt SDK or using the buildroot environment. Personally I prefer to use the buildroot environment that was created when you make the wgt634u image. Each package needs a Makefile which tells the software which configuration options to use and it tells the buildroot which files should be included in the ipk. Some official Makefiles are available at svn.openwrt.org but i had to write my own for irmp3 and i used third party Makefiles for lcdproc and lirc. I have included a package repository (Not Complete Yet) of all my packages but you can compile your own for some of the packages using the Makefiles i have published as well. To compile a package make sure the makefile is located in the trunk/packages/<package_name>/ directory and any patches are in the trunk/packages/<package_name>/patches directory. Then cd into the trunk directory and issue the following command:

root@robert-linux:~/mydocs/trunk$ make package/<package_name>-install V=99

for example to install libusb issue the following command:

root@robert-linux:~/mydocs/trunk$ make package/libusb-install V=99

The OpenWrt forum page is a good information resource for the buildroot environment. To remove all assosciated files from the build_dir and staging_dir_mipsel directories.

root@robert-linux:~/mydocs/trunk$ make package/<package_name>-clean V=99

*Note, the irmp3 Makefile will not compile correctly since argv.h is not present in the buildroot. Use my edited build directory. When the error message is shown copy the contents of irmp3-build-dir.tar.gz into trunk/build_dir/irmp3-v0.5.7-pre2 and recompile it. All i have done is remove the 2 references to argv.h in the sources. This does not effect irmp3’s operation. NOT UPLOADED YET.

Extra packages that need to be installed are:

kmod-alsa,lcdproc,libid3tag,libmad,libmagic,libncurses,libusb,lirc, mpg123 (from http://sokrates.mimuw.edu.pl/~sebek/openwrt/packages/ – Note that the version here is 0.61 and i had some buffering issues with this so i copied the /usr/bin/mpg123 file from http://ipkg.nslu2-linux.org/feeds/unslung/wl500g/

To install the packages on your pc either edit the /etc/ipkg.conf to read http://www.robhardwick.co.uk/packages and then go:

root@robert-linux:~$ipkg install lirc

or you can do each one individually like:

root@robert-linux:~$ipkg install http://www.robhardwick.co.uk/packages/lirc-0.8.1-1_mipsel.ipk

Mounting your Windows Share

My mp3s were located on shared documents on a windows pc. I decided to create an nfs server on my windows machine which linux can easily read provided it has kmod-fs-nfs installed. Follow the instructions at http://www.csparks.com/CygwinNFS/index.xhtml to setup an nfs server on a windows machine. It should be possible to mount a windows share using the cifs filesystem or smbfs but share but I got errors when trying to do it using cifs. The nfs server is failsafe. When your nfs server is setup you can mount the share to a mount point on your router. A sensible place is /mnt/shared. This is done using the following command:

root@OpenWrt:~# mount -t nfs <ip address of server>:<location/of/share/in/cygwin> /mnt/shared -o nolock, nfsvers=2

For me the actual command was:

root@OpenWrt:~# mount -t nfs 192.168.1.2:/mnt/shared /mnt/shared -o nolock, nfsvers=2

When this is done check that you can see your share by issuing something like:

root@OpenWrt:~# ls /mnt/shared

Configuring the Packages

Before you can staret using pacakages you need to configure them according to your hardware and system setup. There are 4 important config files which need to be edited.

LCDd

Edit the /etc/LCDd.conf file to suit your lcd

root@OpenWrt:~# LCDd

Lirc

For lirc i have a Packard Bell X10 RF remote with a USB reciever for which i used the atilibusb driver. This was simple simple because i didn’t have to use any kernel modules. When compiling edit the Makefile to use your driver. I reccommend an X10/ATI RF remote as they can be used without kernel modules. You can get one for as little as £6 on ebay. Yuu can skip this step if there is already a lircd.conf file published on lirc website. You will need to create a lircd.conf file for your remote. First of all run the lircd daemon. Then run irw to see if you get any response when pressing a button. If all of this works then you can use the following to create a new lircd.conf file:

root@OpenWrt:~# irrecord /etc/lircd.conf

Irmp3

The irmp3d.conf file determines all the settings regarding the music player. Most importantly where the music files are located. There is also the lircirmp3.conf file which should be called lircrc.conf but i followed angerman’s instructions. This conf file maps buttons on your remote to functions of irmp3. Edit the file to suit your liking and then aknowlege it in irmp3d.conf Once done you can run irmp3 by running:

root@OpenWrt:~# irmp3d

Here are my conf files:

LCDd.conf
lircd.conf
irmp3d.conf (Watch this space)
lircirmp3.conf (Watch this space)

Finally you will need to add some lines to the /etc/rc.d/S70wifi init script you made earlier so that irmp3, lirc and LCDd start up when the box is rebooted. Your final S70wifi file should look like this:

#!/bin/sh
wlanconfig ath0 destroy
wlanconfig ath0 create wlandev wifi0 wlanmode sta
iwconfig ath0 essid xxxx
iwconfig ath0 key xxxxxxxx
ifconfig ath0 192.168.1.10 netmask 255.255.255.0 up
route add default gw 192.168.1.1
mkdir tmp
mount -t nfs 192.168.1.2:/mnt/shared /mnt/shared -o nolock,nfsvers=2
lircd
LCDd -w 9999
irmp3d

That’s it, you should now have a working wireless music streamer.