How to use the serial ports on a Linksys WRT54GS with DD-WRT v24

By , January 17, 2010 7:51 pm


This is Andrew's Guide to DD-WRT network serial ports.

Part 1 - TCP Based Network Serial Port

A Linksys WRT54G / WRT54GS router makes a great wireless network serial port. In the following guide I will go over the techniques I use to allow TCP or UDP connections. This tutorial covers how to do this with the DD-WRT firmware. The WRT54GS has two serial ports. The first one is connected as a serial console at startup. The second one can be used easily for connecting GPS units, microcontrollers, weather stations or any other serial device.

DD-WRT Homepage
http://www.dd-wrt.com/site/index

Rod Whitby has an article that explains how to solder the required header pins onto your WRT54GS router.
http://www.rwhitby.net/projects/wrt54gs

Using the pinout from Ron Whitby's site you can either hook up a 3.3 Volt serial device directly to your WRT54GS router or, with additional work, you could make / get a voltage converter board to allow true rs-232 serial voltage levels to be converted to 3.3 Volt TTL levels. This type of converter board device would use a Maxim-IC MAX3233E chip. A 10 pin IDC connector ribbon cable can run from your voltage converter board to your header pins soldered onto the WRT54GS. The converter board can draw its power off the router terminal pins through the ICD connector.

Note: Crimping standard servo terminal type connectors onto your serial device's cable will make wiring up the serial port connections to the Linksys WRT54GS easy during prototyping. This type of connection is shown in the two pictures below:

Get the Required Parts

3.3 Volt Locosys GPS (NG Hobbies sells the Locosys LS20033 10 Hz model)
Locosys GPS cable with 5 position 0.1" connector (Also at NG Hobbies )
Linksys WRT54G / WRT54GS router
DD-WRT firmware (v24 suggested)
0.1” double row 2x5 pin header

2.54mm Pin Header Strip

2.54mm Pin Header Strip

The header pins are called either:

  • Double Row Male 2x40 Pin Header Strip 2.54mm ( eBay )
  • 0.1" Break Away Header Pins
  • CONN HDR BRKWAY .100 80POS VERT ( Digi-Key )

The 2x5 pin header was made by snapping off a piece from standard 0.1” (2.54mm) PCB Male Header Pins (2 row x 40). You can find these at Digi-Key, or on eBay.

SSH Client Software:
Putty or Terminal

Optional:

WinSCP

I have packaged up the utilities you require for this project into a ZIP archive:
http://www.andrewhazelden.com/files/2010/January/dd-wrt_serial_TCP.zip

This archive will allow you to set up a network TCP/IP connection on your DD-WRT router using the /dev/tts/1 serial port. The archive dd-wrt_serial_TCP.zip has the following programs:
libncurses_5.6-1_mipsel.ipk
netcat_0.7.1-1_mipsel.ipk
ser2net_2.3-1_mipsel.ipk

---------------------------------------------------------------------------------------------------------------------------------

Step 1. Solder on a 10 pin header

Follow Ron Whitby’s instructions and solder the 10 pin header onto your linksys router.

http://www.rwhitby.net/projects/wrt54gs

Step 2. Install the dd-wrt v24 firmware on your WRT54G / WRT54GS Linksys router.

Go to dd-wrt.com to download the latest firmware.

Step 3. Check your dd-wrt network settings

Set up your network and wireless settings. I recommend setting the router up with a fixed IP address. I use 192.168.1.80 for the wireless router. You will have to decide if you will use either client bridged or client routed modes for the Linksys router or you might even make it an access point.

Step 4. Enable JFFS2 Support on your router.

You must compete this step if you want the process to work!

To do this go to the Administration > management section in the dd-wrt user inteface.

Scroll down to the JFFS2 Support section. Enable the JFFS2 and Clean JFFS2 options.

Click Apply.

Now reboot the router.

This will allocate storage in the flash memory where you will save the programs on your router. I find you have to reboot your router once after enabling JFFS2 Support for it to work properly.

Step 5. SSH into the router. ( You could also use telnet.)

On Windows I recommend the PUTTY program as an SSH Client:
http://www.chiark.greenend.org.uk/~sgtatham/putty/

On Mac OS X I recommend using the Terminal application found in your
/Applications/Utilities folder.

Assuming your router’s IP address is 192.168.1.80 and your dd-wrt username is root, use the following command:

ssh -l root 192.168.1.80

The default password is admin

Step 6. Download the files to your dd-wrt.

The technique I use is to download the files using the wget command on the dd-wrt router.

On Mac OS X you can enable web sharing in your System Preferences Control Panel.

Click on the Sharing Option.

In the Sharing section enable Web Sharing.

This enables the Apache based HTTP web server built into your Mac. You can place files either in the computer's sharing folder or in your user account’s sharing folder.

If you type your computer's IP address in your favorite web browser you will see a directory listing. For example, my computer's local IP address is 192.168.1.8 so I would type the following in the address bar:
http://192.168.1.8

The local path to your computer’s web-sharing folder is:
/Library/WebServer/Documents/

Step 7. Installing dd-wrt TCP serial software using Mac OS X:

The local IP address of my desktop computer is 192.168.1.8 . You should substitute your IP address where you see 192.168.1.8 in the following examples.

Type the following into your ssh session window:

cd /jffs/tmp

If there is no /jffs/tmp directory that would likely indicate the you need to enable JFFS2 support. See Step 4.

To download the software to the dd-wrt:

wget http://192.168.1.8/libncurses_5.6-1_mipsel.ipk
wget http://192.168.1.8/netcat_0.7.1-1_mipsel.ipk
wget http://192.168.1.8/ser2net_2.3-1_mipsel.ipk

To install the software packages using the IPKG installer:

ipkg install libncurses_5.6-1_mipsel.ipk
ipkg install ser2net_2.3-1_mipsel.ipk
ipkg install netcat_0.7.1-1_mipsel.ipk

Step 7. Installing dd-wrt TCP serial software using Windows:

On Windows I recommend the PUTTY program as an SSH Client:
http://www.chiark.greenend.org.uk/~sgtatham/putty/

WinSCP is a great Windows program for copying files onto your dd-wrt router using the SCP protocol:
http://winscp.net/eng/download.php

Using WinSCP login to the router using SCP. The default username is root.

Using WinSCP login to the router using SCP. The default username is root.

Unzip the dd-wrt TCP serial software on your desktop and copy the .ipk fliles using WinSCP to the router's /jffs/tmp folder.

Unzip the dd-wrt TCP serial software on your desktop and copy the .ipk fliles using WinSCP to the router's /jffs/tmp folder.

Connect to the router using PuTTY and SSH.

Connect to the router using PuTTY and SSH.

Login to your dd-wrt router with SSH

Login to your dd-wrt router with SSH

Using SSH install the three .ipk files located at /jffs/tmp you copied via WinSCP.

Using SSH install the three .ipk files located at /jffs/tmp you copied via WinSCP.

To install the software packages using the IPKG installer:

ipkg install libncurses_5.6-1_mipsel.ipk
ipkg install ser2net_2.3-1_mipsel.ipk
ipkg install netcat_0.7.1-1_mipsel.ipk

 

Step 8. Test Ser2net

Connect your serial device to the dd-wrt. This example expects that your serial device is connected to TTS/1. I am using a Lococsys 10 Hz GPS connected at 38,400 baud. I set up the serial device to output data on TCP port 3001 but any other port number could be used. The ser2net program only allows a single TCP connection to the serial port at a time.

In the SSH session window type in:

ser2net -C "3001:raw:600:/dev/tts/1:38400 NONE 1STOPBIT 8DATABITS -XONXOFF -LOCAL -RTSCTS"

If you copy the above text, make sure your web browser didn't convert the quotes into smart quotes as this will give an error in your SSH terminal program.

To check if the program is installed properly and running, type in:

top

This shows the currently running programs on the dd-wrt router. In the right hand column labeled COMMAND you should see ser2net listed part way down. Press Control-C to quit top.

Step 9. Set up a new dd-wrt startup script.

To make the serial software ser2net start at boot time we will make it a startup script. Connect to the Linksys router. In my case, I will connect to http://192.168.1.80/Diagnostics.asp

This will load up the Administration / Commands section in the dd-wrt software.

Paste the following text into the Command Shell section of the web-gui of the dd-wrt router firmware control panel:

ser2net -C "3001:raw:600:/dev/tts/1:38400 NONE 1STOPBIT 8DATABITS -XONXOFF -LOCAL -RTSCTS"

If you copy the above text, make sure your web browser didn't convert the quotes into smart quotes as this will give an error in your SSH terminal program.

Click the Save Startup button.

Reboot the router.

Step 10. Let’s now test if everything is working!

Open a new terminal window.

On Mac OS X and Linux there is a handy Unix tool called Netcat. Netcat is also known as “nc” for short. It allows you to easily test UDP and TCP network connections. If you search on Google there are also pre-compiled versions of Netcat for windows.

Type the following into your terminal window:

nc 192.168.1.80 3001

This tells Netcat to connect to the Linksys router on port 3001 using the TCP protocol.
If your serial device is properly connected you should see data scrolling by in the terminal window.

Step 11. Conclusions

You can now access the serial port on a dd-wrt either through the Ethernet port on the router or wirelessly using WIFI.

On Mac OS X it is possible to use BSD Sockets to connect and transfer data between desktop software and the remote network serial port.

On Windows you can either use a TCP socket and connect directly or you can use virtual serial port software that will make the network TCP data look like it is coming in on a Windows COM port.

A free program for Windows that maps the TCP serial data to a virtual serial port is:
HW VSP3 - Virtual Serial Port
http://www.hw-group.com/products/hw_vsp/index_en.html

Some people like to use Python scripting for its easy network socket programming.
http://www.python.org/

Another way to access the network TCP serial data is to use the Simple Directmedia Layer "SDL" with the SDL_net cross-platform networking library. This works equally well on Mac / Windows / Linux platforms.

http://www.libsdl.org/

http://www.libsdl.org/projects/SDL_net/

Step 12. Let's add a wireless repeater mode to the router.

And additional step is that you could setup your serial port enhanced dd-wrt router to be a wireless repeater. Wireless repeater bridge mode allows your dd-wrt router to connect to a wireless access point for internet access and also allows clients to connect directly to your dd-wrt. Another handy thing about this mode is that you can place this router a long way away from your access point and you don't have to run any Ethernet cable to hook it up. With a properly setup grid or patch antenna the dd-wrt wireless repeater router could even be a kilometer or more away. As well you can connect to the dd-wrt with an device like an iPod to check the settings. I have a Terminal app on my iPod so I can even log in to the router with SSH and change settings.

You might find that enabling the dd-wrt repeater bridge mode is just what your project needs.

You might find that enabling the dd-wrt repeater bridge mode is just what your project needs.

You can define two separate wireless security passwords for your router. One for the physical interface and one for the virtual interface.

You can define two separate wireless security passwords for your router. One for the physical interface and one for the virtual interface.

You have now completed part 1 of this tutorial on setting up network serial ports using a Linksys router. Part 2 of this tutorial covers setting up a UDP based network serial port on your Linksys WRT54G router using a custom build of busybox and netcat.

Installing Ser2net Without JFFS2 Support

A blog reader named Matt sent me a tip from the DD-WRT forums on how you can install ser2net on routers without JFFS2 support. The technique uses an http server to host a gzipped copy of ser2net. The file is downloaded using wget, expanded with tar xzf, and then ser2net is run from the command line with the appropriate arguments.

cd /tmp
wget http://[your-webserver-ip/folder-name]/ser2net-2.5-mips.tar.gz
tar xzf ser2net-2.5-mips.tar.gz
cd ser2net-2.5
./ser2net -C "1024:raw:600:/dev/tts/1:38400 NONE 1STOPBIT 8DATABITS -XONXOFF -LOCAL -RTSCTS"

Note: If you make this a startup script on the router the HTTP webserver URL has to be accessible from the router at boot time for this to work. This means you might have to store the file on your local LAN. You can download a copy of the file ser2net-2.4-mips.tar.gz here.

Further Reading:
Read Part 2 - Setting up a UDP based network serial port on a Linksys WRT54g

Print Friendly

34 Responses to “How to use the serial ports on a Linksys WRT54GS with DD-WRT v24”

  1. Master Chi says:

    I like to made an fast same project(from your tutorial)... dd-wrt to fonera 2100 like use as wi232 - wibox (serial on wlan)...
    I made steps what are in tutoral but (after tftp files) when i like to "ipkg install libncurses_5.6-1_mipsel.ipk " get an error message... can't continue...
    Please help!

  2. Sejio says:

    Look, I have a script which runs smoothly on my macosx box. It has the following line:
    exec 3/dev/tcp/$host/$port
    when I try executing this line on a dd-wrt box it says
    -sh: cannot create /dev/tts/1/pop3.bk.ru/110: Directory nonexistent
    what's wrong?

  3. Andrew says:

    Sejio,

    I got the same error on the dd-wrt when I ran:
    exec 3 <>/dev/tcp/www.google.com/80
    -sh: cannot create /dev/tcp/www.google.com/80: nonexistent directory

    Your best bet for an answer as to why this is happening with the dd-wrt BusyBox built-in shell (ash) is to ask your question on the dd-wrt forum:
    http://www.dd-wrt.com/phpBB2/

    Regards,

    Andrew Hazelden

  4. Matt says:

    Hey Andrew can you tell me where I can find the 3.3v gps, the 10 pin header and the wires you used to connect?

    Thanks a bunch

  5. nick says:

    i get an error saying cant find /whiterussian and a couple others any suggestions im running the v24 -sp2 witch is a bit different i guess what one did you use?

  6. Andrew says:

    I have used serial ports with both DD-WRT V24 SP1 and RC7.

  7. nick says:

    what build? micro, mini, standard std, standard usb? i cant seem to get it to work. thanks for the quick reply. the tutorial is great

  8. Andrew says:

    My current network serial port setup is a Linksys router with DD-WRT V24 Rc7 with the "dd-wrt.v24_std_generic.bin" firmware.

  9. zspzs says:

    Hello Andrew,
    I have WRT54G v5 with dd-wrt v24 micro, which does not support JFFS2. Can I install ser2net on this configuration anyway?
    Thanks
    Peter

  10. Andrew says:

    Hi Peter.

    It is unfortunate that the WRT54G V5 router has such little memory that you need to install the v24 micro firmware. You need JFFS2 support to have persistent storage on the Linksys router. JFFS2 allows your data to exist beyond a reboot so when you install ser2net it will stay installed when the power is reset. You would probably be happiest in the long-term if you got a router with more memory so you can install a full featured version of dd-wrt v24 with JFFS2 and many other features.

    It might be technically possible to install ser2net in the temporary ram memory on your router but it would probably be more trouble than it is worth. You could then (theoretically) setup a startup script to install ser2net every time the router boots.

    You might be able to use the SD memory card mod to install ser2net.

    You can check how much storage space is available on your router by using ssh to connect from your desktop to the router, then run df to check the free memory on the router.

    Regards,
    Andrew

  11. Griz says:

    Hi Andrew,

    I have been trying to accomplish a similar task, unsuccessfully. The overall goal is to control an arduino over the web. I have been trying to start small and just connect and send data to the serial port on a wrt54g on the local network via UDP. Unfortunately, I dont know too much about socket programming. I am able to echo commands to the serial port when I'm ssh'd in but i would like to simply connect to the local network, specify wrt54g ip and port, and send data(osc commands, for starters) without telnet or ssh.

    Do you have any suggestions? Or maybe you can point me in the right direction.

    Thanks,
    Ryan

  12. Andrew says:

    The free windows program HW VSP (Virtual Serial Port) might be useful for your project Ryan. It lets you connect to a network serial device like a wrt54g from Windows as if it was directly connected to a traditional Window COM port.

  13. Tim Smith says:

    Andrew,

    Is there a Windows method for transferring the files to the router? I have a 54G v2. I cannot get files on the router, is there something I am missing? Thanks for the great how to.

  14. Andrew says:

    Hi Tim.
    Once you have JFFS2 support enabled, you could use winSCP to copy files from your desktop to your router.

  15. Jean Collin says:

    HARDWARE : 2x WRT54GL , ARDUINO
    OS : WinXP

    hi Andrew,

    Have been looking at your tutorial looks great , I'm close to getting the Arduino sent to me and want to monitor/implement a solar Differential controller in Costa Rica where I live.

    I have a 2 linksys router which already has DD-WRT V24 on it from previous use so its perfect for the job of going wireless with my Arduino.

    Questions are :

    1) Can I use one of the router as a Repeater and serial Client so that I dont touch my main router and just make them talk to each other or do I have to hack my main router where the incoming ADSL is ?

    2) Will the GL version of the router handle the above instructions that you give.

    3) I would like to eventually use Pachube to log my data but would be happy to start with a simple protocol to view temperatures from sensors using simple solution any recommendations ?

    Thank you for your time

    Jean

  16. Andrew says:

    Hi Jean,

    Your main router / access point can be left setup how it is. You only need to change the settings on the WRT54GL router that has the serial port to make it a repeater. I use several of my dd-wrt routers as wireless repeaters.You might find that enabling the dd-wrt repeater bridge mode is just what your project needs. As well you can also define two separate wireless security passwords for your router. One for the physical interface and one for the virtual interface.

    I checked the dd-wrt router database for the WRT54GL and your router has 16 MB ram and 4 MB Flash which is enough ram to run the standard generic version of dd-wrt that has JFFS2 support.

    A simple protocol to send your data from your micro-controller would be as ASCII data with comma separated values and a newline character. You could then use netcat remotely to access the data and pipe it to a .CSV file that could then be viewed and charted in EXCEL.

    Regards,
    Andrew

  17. SYL20 says:

    Hello,

    Great tutorial.

    Is it possible to use the serial port in 2 directions?

    I can send but I get nothing ...

    PC1 hyperterminal1 MAX232 DD-WRT WiFi PC2 hyperterminal2

    when I want to send with hyperterminal1 he asks login.

    Do you have a solution?

    Thank you

  18. Andrew says:

    Hi Syl,

    What that sounds like is that you connected to the first serial port(TTS0) on the router which is connected to the serial console by default. You should try connecting to the 2nd serial port (TTS1) and you will be able to send data in both directions.

  19. SYL20 says:

    Thank you for the prompt response.

    I have a single port on my router ... ASUS WL-330GE

    Another solution exists?

    thank you

  20. Andrew says:

    Hi Syl,

    I don't have experience detaching the serial console on dd-wrt, so that is something you would have to research. You might be able to run a command as a startup script that could do that. Another option would be to recompile dd-wrt with the build toolchain and then permanently disable the serial console that way. Awhile ago there was a thread on the dd-wrt forums that discussed this topic.

    Good Luck!

    Regards,
    Andrew

  21. amit says:

    hi andrew,
    I want to run a application on my wrt310n router that requires serial comunication.My router has 4 mb flash so i can only instal mini version.When i try to run app i get this error " can't resolve symbol 'cfsetspeed'".But if i run that app on different router with mega ddwrt,it runs fine.So could you please suggest me what package could be needed to get serial comunication on mini ddwrt.Thanks

  22. Andrew says:

    Amit,

    In the long term you will be a lot happier if you get a router with more ram. You **could** play with the dd-wrt build toolchain to package your own custom version that has just the features you want but it probably isn't worth the effort. You can view the dd-wrt development page wiki here.

  23. amit says:

    Thanks Andrew for your quick response. I will look into it. Thanks

  24. hossam says:

    hi i try to use linksys router wrt45g v2 using dd wrt
    to i can connect to micro control what software or commend i need to enable serial port in my router tnx in advebce

  25. [...] is part 2 of a tutorial I wrote on using network serial ports on a Linksys router. In part 2 of this tutorial I am going to show how to get a UDP based network serial port running [...]

  26. yarek says:

    First of all its great article ! You did a lot of good job. I would like to ask You - youre experienced, so probably You could give me some important clues. I would like to do sth like that:
    _________________________________________________________

    PIC microcontroller -- rs232/rx/tx-->WRT54GS ---ETH--- WRT54GS --- rs232/rx/tx PIC microcontroller .
    _________________________________________________________
    I would like those two PIC`s exchange the data over eth. Question is if I need sth more then : ser2net.ipk running on that WRT ? Should I know about some important things ? Is it possible ? Would be very greatful for any comment, I dont want complex answer, but do You think I should remember about some something special or will I need something special ?

    Best Regards !!

    GOOD JOB !

  27. Andrew says:

    Hi Yarek.

    If I was going to connect two PIC microcontrollers together using WRT54GS routers as serial to ethernet bridges I would set up ser2net on the "server" router and use a bash script with netcat in a while[] loop on the "client" router to connect to the server.

    The client router would need to use setserial to define the serial port's IRQ address:

    setserial /dev/tts/1 irq 3

    And stty to set the port speed:

    /jffs/usr/bin/busybox stty -F /dev/tts/1 raw speed 38400

    I wrote another blog post on setting up a UDP based network serial port on a Linksys WRT54GS. You can get a copy of setserial and a build of busybox with stty from the included zip package:
    dd-wrt_serial_UDP.zip

    Regards,
    Andrew

  28. Andy v/d Enden says:

    Hello,

    My /usr/bin directory is read only. So that I can't install "netcat_0.7.1-1_mipsel.ipk" ! How can I fix this?

  29. Andrew says:

    Hi Andy.

    Have you created a JFFS2 file system on the router? Open up the dd-wrt web UI and go to Administration < Management section and enable JFFS2 Support.

    If you don't have a lot of ram on your router you could look into the Linksys WRT54g SD memory card mod.

    Regards,
    Andrew Hazelden

  30. Andy v/d Enden says:

    Hi Andrew,

    I have not enough ram on my router.
    How can I do the install on my sd card?
    Is that the same way as in the jffs map?

  31. Andrew says:

    Hi Andy v/d Enden.

    The dd-wrt website has a page on how to do the Linksys WRT54G SD/MMC mod.

    Good Luck with your project.

    Regards,
    Andrew Hazelden

  32. nubie says:

    why i cant create /jffs/tmp

  33. Andrew says:

    Hi Nubie.

    You have to enable JFFS Support in the DD-WRT Web-Gui for the /jffs/tmp directory to exist on the router. (Also, make sure your router has the correct build of dd-wrt that includes the JFFS driver.)

    If you need more details about using JFFS check out the dd-wrt wiki.

  34. [...] opted to void the war­ranty, installed dd-wrt and a small TTL-RS232 board. Using this How to use the ser­ial ports on a Linksys WRT54GS with DD-WRT v24 guide, I found a power con­nec­tion, sol­dered in RX/TX con­nec­tion header for ttyS02 and [...]