RIHLA - Serial port on the router

exposing the serial port:

opened up the router (from the bottom, 2 screws visible, 2 screws under the rubber foot pads. located the serial port on the board (see http://www.gumbolabs.org/2009/10/08/hacking-the-asus-wl-520gu-w-openwrt/). desoldered it (tried to use braid, could not do a good job, so heated the solder with iron and blew out the solder, to clear the holes). soldered a header and took out the points to 4 wires (3.3V red, Rx green, Tx white, GND black)

the boot log is streamed out to the serial port, so wanted to see if that could be read. so connected a FTDI basic USB/serial board from Sparkfun. the board was prewired for 5V serial, but the WL520 uses 3.3V serial. so the 5V trace was cut, and the 3.3V pads were jumpered with solder, on the FTDI board. then connected the router to the FTDI board as follows:

FTDI board      WL520GU
---------       -------
RX <----------- TX (white)
TX              RX (green)
3.3V            3.3V (red)
GND ----------- GND (black)

note: did not have to connect the 3.3V from the FTDI board to the router, because the router has it's own power. also was not necessary to connect TX from the FTDI board to RX from the router, because we were only interested in listening to what the router had to say (and not send stuff to the router). connected the FTDI board to the laptop. then did a

dmesg | grep -i tty
in the output, saw "FTDI USB Serial Device converter now attached to ttyUSB0"
fired up cutecom on the laptop, set it to 115200 8 N 1, and set the serial port to ttyUSB0. was able to see the boot log in the output window. (there was a message saying "press Enter to use this terminal", so when an Enter is sent, the console gets activated and am able to run commands on the router and get the results, over serial)

configuring the serial port:

the router’s serial port provides a login shell by default, which we need to disable if we want to recv data from it (or it will interpret incoming data as commands)

$ vi /etc/inittab
::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K stop
#tts/0::askfirst:/bin/ash --login
#ttyS0::askfirst:/bin/ash --login
tty1::askfirst:/bin/ash --login

sysrq is a debugging feature of the kernel, usually invoked with a magic key combination. but it might accidentally trip over the serial port when we are using it. so to disable,

$ vi /etc/sysctl.conf file and adding these lines:
# add this line to disable the magic sysrq key
Looks like the serial port runs at 115200. Looks like this might be too fast, when communicating with the microcontroller. So reduced the baud rate to 9600 (probably could have tried higher speeds, but didn't bother)
$ stty 9600 < /dev/ttyS0
(remember, we included stty in the custom build we did for the router).(now need to find a way to run this command automatically at startup).

ser2net setup:

$ vi /etc/ser2net.conf
9876:raw:0:/dev/ttyS0:9600 NONE 1STOPBIT 8DATABITS LOCAL -RTSCTS
to make ser2net startup automatically on boot
$ vi /etc/init.d/ser2net
#!/bin/sh /etc/rc.common
start() {
stop() {
  killall ser2net
to make executable
$ chmod 755 /etc/init.d/ser2net
to enable service autostart
$ /etc/init.d/ser2net enable

communicating with the WL520 over the serial port

connected laptop <==> 3.3V FTDI board <==> router
                       RX<--------------TX (white)
                       TX-------------->RX (green)
                       GND--------------GND (black)
the router was running openWRT. did a
dmesg | grep -i tty
saw ...console ttyS0,115200 console [ttyS0] enabled, so figured could use /dev/ttyS0. sent messages from the command line using
echo "message to laptop" > /dev/ttyS0
was able to recv messages from the router command line using
cat /dev/ttyS0
from cutecom on the laptop (set to 115200 8 N 1, serial port to ttyUSB0), was able to read and send messages to the router. note: when the router was not running cat to listen to messages, after an Enter is sent, the console gets activated, and then any input sent from laptop was being interpreted as a console shell command.