Tuesday 27 December 2011

TP-Link WR703N, OpenWRT, MPD et al

Finally, a post....
I bought a TP-Link WR703N [1], it's a little router meant to be used in conjunction with a 3G Modem, it works as an access point broadcasting a wireless connection allowing multiple devices to utilize the modem at once (quite a clever idea, however, not one I'm interested in using), hence I decided to flash it with OpenWRT [2]

Specs:

RAM - 32Mb
ROM - 4Mb
USB port (USB2)
CPU - Atheros AR7240 - 400Mhz
Wireless - Atheros AR9331 - b/g/n

Powered by a micro usb port, 5.7cm x 5.7cm, serial interface.
(These are just the basics, more here [3])

OpenWRT Install:
The device comes preinstalled with Chinese firmware, I connected the router via ethernet and configured Arch to have the IP 192.168.1.2 (in /etc/rc.conf) but you could also easily use wifi to upload the new firmware.

After connecting to the router, keep hovering over the menu items, the page file names are in English, keep expanding the drop down menus until you find one with a page name similar to 'software upgrade', something along those lines (I do believe it's in one of the last sections). Go to the OpenWRT wiki and download the 'vanilla' firmware for the router, upload this, once the router has upgraded the firmware, it should reboot.

Having now installed the OpenWRT firmware, you can connect to the router via the ethernet port if you configure your computer's IP to be 192.168.1.2, telnet into the router using:
telnet 192.168.1.1
There you are presented with the CLI of the router where you can start manipulating things. Use opkg update to update the packages list and opkg install *package name* to install applications

These are simply the basics and much more informative instructions can be found on the OpenWRT forums and wiki.

OpenWRT Configuration:
I wanted to use the router as a wireless client (i.e. similar to a computer), I used the following network configurations

/etc/config/network

config 'interface' 'loopback'
option 'ifname' 'lo'
option 'proto' 'static'
option 'ipaddr' '127.0.0.1'
option 'netmask' '255.0.0.0'


config 'interface' 'lan'
option 'ifname' 'eth0'
option 'type' 'bridge'
option 'proto' 'static'
option 'ipaddr' '192.168.1.1'
option 'netmask' '255.255.255.0'


config 'interface' 'wan'
 option 'proto' 'dhcp'

/etc/config/wireless
config 'wifi-device' 'radio0'
option 'type' 'mac80211'
option 'channel' '11'
option 'macaddr' '38:83:45:a2:14:18'
option 'hwmode' '11ng'
option 'htmode' 'HT20'
list 'ht_capab' 'SHORT-GI-20'
list 'ht_capab' 'SHORT-GI-40'
list 'ht_capab' 'RX-STBC1'
list 'ht_capab' 'DSSS_CCK-40'

config 'wifi-iface'
option 'device' 'radio0'
option 'network' 'wan' #Set the adapter to act as a wide area network -- not sure why
option 'ssid' 'Price LAN'
option 'key' '*******'
option 'encryption' 'psk2' # My network uses psk2 security
option 'mode' 'sta' #Setup client mode

In the section 'config 'wifi-iface'' I've setup the router to act as a client by setting the 'mode' to 'sta' which sets the router to act as a client rather than an access point.

USB Support:
I needed USB support as the router only has a 4mb flash which isn't sufficient to install transmission, mpd, mpc etc. I updated
/etc/opkg.conf to remedy this (look at the wiki page on opkg, there is a section on how to do this).

Now I could install to my memory stick using the command
opkg -d usb install *package name*
This usually works fairly well, I had to update my PATH variable in /etc/profile to reflect the new install directories.

I've also played around in /etc/rc.local setting up some startup applications.
I've got mpd, transmission-daemon and mpc (adding playlists) on startup. 

Links:
[1] - $22/£15 - http://www.volumerates.com/product/genuine-tp-link-tl-wr703n-150m-11n-mini-wifi-wireless-router-for-instant-wifi-connection-99273
[2] - https://openwrt.org/
[3] - OpenWRT wiki page on WR703N - http://wiki.openwrt.org/toh/tp-link/tl-wr703n

I might continue to update this post as I progress with the project. I aim to use this router to act as a internet radio, I'll probably use an arduino to interface it with an LCD and rotary encoder.

5 comments:

  1. well, just wondering how you managed it, Mpd is already exploding my ram by itself.

    ReplyDelete
  2. RAM? It has plenty of RAM for running MPD, it just has squat all flash storage space, I installed it on an external memory stick (check out the OpenWRT opkg wiki page)

    ReplyDelete
  3. well, mpd mini doesn t come with alsa support, while mpd full which suck my ram dry has it. I use nfs for install which to my taste is a more elgant solution because i have more than wr703n, and i have something like less than 1mb or ram free

    top give :
    1154 1 root S 1500 5% 0% /usr/sbin/ntpd -n -p 0.openwrt.pool.n
    2125 2118 root R 1500 5% 0% top
    2117 1096 root S 1216 4% 0% /usr/sbin/dropbear -P /var/run/dropbe
    3 2 root SW 0 0% 0% [ksoftirqd/0]
    595 1 root S 1512 5% 0% /sbin/netifd
    579 1 root S 1508 5% 0% /sbin/syslogd -C16
    1 0 root S 1504 5% 0% init
    455 1 root S 1504 5% 0% init
    2118 2117 root S 1504 5% 0% -ash
    830 1 root S 1500 5% 0% /sbin/watchdog -t 5 /dev/watchdog
    581 1 root S 1488 5% 0% /sbin/klogd
    870 1 root S 1408 5% 0% hostapd -P /var/run/wifi-phy0.pid -B
    1096 1 root S 1152 4% 0% /usr/sbin/dropbear -P /var/run/dropbe
    1141 1 nobody S 936 3% 0% /usr/sbin/dnsmasq -C /var/etc/dnsmasq
    589 1 root S 860 3% 0% /sbin/ubusd
    583 1 root S 852 3% 0% /sbin/hotplug2 --override --persisten
    250 2 root SW 0 0% 0% [kworker/0:1]
    437 2 root SWN 0 0% 0% [jffs2_gcd_mtd3]
    7 2 root SW 0 0% 0% [kworker/u:1]
    194 2 root SW 0 0% 0% [mtdblock2]

    and only 11 mb of free ram at start.

    ReplyDelete
  4. I can't see any problems from your top output but 11mb free at startup seems a bit low as that means you're somehow using 21mb or RAM? Are you sure you're just misreading the output of 'free' and not factoring in the amount of memory that is cached (Linux puts aside a lot of memory in a cache/buffer for use when opening programs)

    I'll get my WR703N out at the weekend and play around

    ReplyDelete
  5. yeah lot is cached; but it surprise me to have stuff cached at startup^^, the reason was a bad rc.local on launch but it doesnt ponder my problem with mpd.
    mpd is still taking a whole 22 mb of ram on a clean launch. ( from reboot after rc.local load nfs and mpd , correctly this time)
    I m pretty sure the culprit is the mpd-full package but mpd mini doesnt have alsa, that is a total deal breaker for susb card while the full has a lot of useless stuff. I guess i m gonna need to crosscompile mpd, and I m not a big fan, especially with mpd and it s number of optional, not so optional dependencies. Thought for 10 euro the wr703N is an awesome deal.
    Tell me if you have a different result.
    I also have 3 dockstar to play with!

    ReplyDelete