I2CChip.com: WiFi & Ethernet Access

Converting a $60 router for wireless / ethernet remote access and datalogging

Contents The Linksys WRT54G is one of several similar 802.11B/G Wifi routers using a Broadcom chipset.

These run Linux, and (with an easy firmware change)and can be used to give remote access to the I2C-2-PC or BL233 chips, or as stand alone dataloggers or controllers with remote access.

While they are WiFi devices, they are just as useful from the ethernet port ignoring the wireless bit.

Our I2C-2-PC can also be used as an RS232 adaptor to connect the Linksys to a PC's serial or USB ports for testing serial comms.

What follows is a work in progess so come back and see how we get along with it....

What type of WRT54G to get?

The current versions WRT54G v2.0 and WRT54GS have built in serial ports. There were old (V1) units which required fitting a uart chip to the pcb.

WRT54G: 4MB Flash, 32M Ram, but 16M Ram is available, and 4M is free. (ie 16M sees to be unusable)

WRT54GS: 8M Flash, 32M Ram, 20M is free.

GS version has more flash and far more free ram, and so is a better choice if you expect to get it run stand-alone programs, or collect large data files. The WRT54G is fine for simple jobs. Note that there seem to be many devices based on the Broadcom chipset and Linux, but not all have serial ports or firmware that is as developed as the WRT54

Preparing the I2C-2-PC adaptor:

On the Linksys Router

Now I assume that you do have the serial comms tested and working. To understand the I2C-2-PC commands below you need to read the BL233 datasheet.

Setup the Linksys Serial Port

First you need to change the serial port setups. Turn off the echo and change the baud rate.

stty -F /dev/tts/1 -echo 57600

stty -F /dev/tts/1 -a will show the current port settings. Note the odd port numbering compared to most Linux boxes. Also we are using port1 not port0, as port 0 is used as a console by default and will send messages at startup.

Talk to the I2C Bus

To understand the I2C commands that follow, see the BL233 datasheet.....

To send 0x5A (ie binary 01011010) to a PCF8574 8 bit I/O chip at I2C address 0x40:

echo S405AP > /dev/tts/1

To send any other byte change the 5A to the desired hex number, or a string of hex bytes if you want to toggle pins.

To see what is returned to the Linksys. (^C will kill the cat)

cat /dev/tts/1

To capture it to a file (far more useful). The "&" makes the cat command run in the background. Note that the "cat" command will keep running until it receives char 4 (^D) or you kill it. The received chars will be written to the file when the end of line is received

cat /dev/tts/1 > /tmp/play.txt &

then to read 1 byte from the PCF8574 send "S4101P"

echo S4101P >/dev/tts/1

Now the returned data is being captured to /tmp/play.txt. To see what is in the file:

more /tmp/play.txt

Data Logging

Now all you have to do is write a script to periodically issue commands to the I2C-2-PC with echo, and pause with sleep and the results will be stored in a file. In the BL233 datasheet you will find about storing commands inside the BL233 so it just sends data autonomously.

The "cat" command will keep running until an EOT character (^d or ox04) is received. You can examine the file with "more" or use ???TFTP??? to download it to a PC through the wireless lan or ethernet.

OK so lets make a simple data logger to record temperature with a TMP100 and record 8 switch inputs connected to a PCF8574. Use cat > /tmp/logit to type in a simple logging script, and ^D to end it.

stty -F /dev/tts/1 -echo 57600    #set baud rate and echo off
cat /dev/tts/1 > /tmp/play.txt &  #start collecting to file in background
echo S900160W00P > /dev/tts/1     #initialise TMP100 temperature sensor
while true                        #do forever
  echo S4101P > /dev/tts/1        #read 1 byte from a PCF8574
  echo S9102P > /dev/tts/1        #read temperature from TMP100
  sleep 10                        #and wait 10 seconds before doing it again

Now make it executable and run it in the background

chmod 755 /tmp/logit

/tmp/play &

Now the port is read and stored in play.txt every 10 seconds. You can use tail to put a limit on how long the file gets. The file is just full of hex so its easy to process.

One advantage of this approach to datalogging is that it is a lot easier to put a 12V battery or UPS on the Linksys router, than on a PC. A gelcell will keep the data collection going until the power comes up and the PC can downlaod the files again.

If you just want to capture a single lot of data and have "cat" quit, you can use the T command in the BL233 to return char 4 at the end. For example this is ideal for dumping the contents of an eeprom to disk.

echo T04 >/dev/tts/1

Time-Stamping the files

Of course for datalogging it is useful to store the date/time in the datafile. Handily the Linksys is able to get its time direct from an NNTP server, so the time should always be just perfect! Personally I prefer to not use english date/times but rather use the unix numeric time in seconds since 1970. It is easier to read, sort and plot. To append the date number to a file:

date +%s >> play.txt

To set the time in the router it is best to configure it to autonmatically use a NTP timeserver. If this isn't possible use the date command. The format for stting the data is: date -s [MMDDhhmm[[CC]YY] eg: Jul 1 23:13 2004 is

date -s 070123132004


Download and install the following:

Install the Sveasoft firmware from the routers webpage. See http://docs.sveasoft.com/SV-UpgradingFirmware.html

Enable SSHD on the administration page and save. Until you save the dialog for the key does not appear.

Run Puttygen and make an SSH2 key according to, and copy the public key into the SSH part on the admin page. Save

Now you should be able to connect using putty and login as root.

WinSCP should be able to connect using the same key file and transfer files both ways. Note that most dirs are read only. /tmp is writeable

Upload files

Try the logging script.

When you are happy it works, run log_setup to setup the nvram. Check the nvram, then "nvram commit" to write the changes. Now the logger should run on boot.


Copy Logger script to NVRam

We need the logger script to be non-volatile so it can start automatically. So I copy it to an NVRam variable.

nvram set logscript="`cat /tmp/logscript`" #save to nvram

nvram show #shows space and vars in nvram

nvram commit #write to flash (ie make non-volatile). This takes a couple of seconds

nvram get logscript > /tmp/logscript #restore to file

NVRam seems to be a 32k space, so the room is limited and it might be an idea to remove comments before saving scripts. "sed" can do this.

sed -e '2,$s/#.*//' -e 's/[ ^I]*$//' -e '/^$/ d' big_script > small_script #remove comments and spaces except for first line comment (#!/bin/sh)

Keeping Data from getting too big

The ram space is limited, so it is better for the data size to be capped. Tail can be used to limit the number of lines in the log file. Since the length of each line is constant, the max file size should be predicted.

cat /tmp/logfile.dat | tail -n-10000 > /tmp/logfile.dat #trim file to 10k lines

10800 lines is 1 minute datapoints for 7 days.

Note that when you try to reflash the rom you need enough free ram to hold the whole flash image. You may have to delete all your logger files before trying to reflash.


Transferring Files

File transfers can be view by which end the command is executed on.

From Windows PC end

For GUI file transfers WinSCP is recommended.

The PSCP program can be used for automated commandline transfers. Presently the 2004-06-19 development snapshot must be used with the -scp option

pscp -i putty_~3.ppk -scp root@ c:\temp

Note that Putty, pscp, WinSCP all use the same key file.

Presently HTTPD on the WRT requires a login password, and will only return files with ".asp" extension.

TFTPD on WRT appears only able to upload the bin file to /tmp.

From WRT command line.

scp, tftp, wget, and soon ftp are available.


Current Issues

  1. Most up-to-date firmware lacks STTY command
  2. How do I make it run at power on?

Wiring the I2C-2-PC to Linksys WRT54G


Into the Linksys socket fit two 1k resistors and connect to a 6 way cable with a micromatch 6 male on one end. Connect pins 1 and 5 of the ribbon. DO NOT connect pin1 of the ribbon (+5 from I2C-2-PC) to pin 1 of the Linksys (+3.3 of Linksys)

Fit 2 micromatch females into the empty holes on the I2C-2-PC. The connector closest to the FTDI is used when you are connecting the Linksys to the BL233 for an I2C adaptor. The connector next to the BL233 is used when you want to connect the Linksys to a PC's serial port for testing.(remove the BL233 when doing this)

Function Direction Linksys Pin# I2C-2-PC Pin#
3.3V   1 n/c
TXD Out Linksys 3 4
RXD In Linksys 5 3
n/c   7  
GND   9 6

Test the Linksys Serial Interface:

Back to Top
Back to Home


How to setup SSH

Over to Zak McRofl....

Ok it took me some time to figure it out so here's how you can get public-key based ssh access to your WRT54G:

1) Get PuTTY: http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe
2) Get PuTTYgen: http://the.earth.li/~sgtatham/putty/latest/x86/puttygen.exe
3) Run PuTTYgen, select SSH2 RSA at parameters, 1024 bits. Press generate, it will create a public/private key pair from your mouse movements.
4) Change comment to username@hostname, this step is not necessary but I believe it simplifies the login because putty will use username as default login. I put root@unknown.
4) Save both keys to files but DON'T close PuTTYgen yet. Select everything in the field Public key for pasting into OpenSSH authorized_keys2 file and copy it into clipboard.
5) Open WRT54G management page, enable SSHD and paste the key into the Authorized Keys-field.
Note: You can enable pwd login at this point if you like, it does not appear to interfere with public key login and gives you the possibility to login with a password from unknown hosts.
6) Time to run PuTTY! Enter IP adress of your router under host name, switch Protocol to SSH, under Connection->Auto-login username to root and MOST IMPORTANT: point Connection->SSH->Auth->Private key file for authentication to the file you saved your private key in.
Since you don't want PuTTY to forget all this stuff you finally put some profile name (e.g. WRT54G) below Session->Saved Sessions and press Save.
7) The moment of truth: press Open in PuTTY and cross your fingers. If you did everything right and I didn't explain it wrong, you should get directly to a shell after getting the message
Using username "root".
Authenticating with public key "root@unknown"

followed by a MOTD.

Other SSH stuff I found in the forum:

If you want to connect from the WAN interface, i.e. from the Internet, you need to map any port to router-ip:22 . Some people suggested turning off the firewall in order to get it working, however for me it only worked after adding that portmapping.

If you use SSH password auth you need to login with root/routerpwd. Note that a router password change will only affect the SSH password after a reboot.

Well that's it, I hope anyone can need this since it was quite some typing for me Drop me a reply if you want add or correct anything or if this was of any use for you. It might encourage me and others to write more tutorials for the less intuitive tasks...

Regards, Zak

On Linux

Faxmodem writes....

In order to use unixish command line:

1) ssh root@
2) on key prompt choose "yes"
3) enter any passwd, you can't get in yet
4) display your .ssh/known_hosts
5) copy/paste the key corresponding to into the web interface under "Administration/Management/sshd/authorized keys"

6) ssh root@
7) on passwd prompt enter your web interface passwd

Hi again

I found the solution: When copy pasting the public key into the interface, it doesn't work.

I only managed to get it working this way:

generate a key as yourself on your linux box using ssh-keygen -t rsa
activate the telnet interface on the router
put your .ssh/id_rsa.pub onto a folder on your linux box's website or sftp server
telnet onto the router
cd /tmp/.ssh
get the file id_rsa.pub using wget or sftp
rename it authorized_keys
ssh root@

Contact Information

Phone +64 21 623-402

Back to Top

Comments and Suggestions

Please send us mail telling us what you think about this page and how we might improve it.

Back to Top