Using the Bifferboard serial port (ttyS0) for external device control
- removing "terminal chatter"
You can control ttyS0 from a web page |
In the default setting various terminal processes can send messages to any device connected to the rs232 port whenever they choose.
The objective here is to remove that freedom and allow scipts and programs (and web pages!) to control devices connected to the port.
Build a kernel in which the console is not connected to ttyS0, the rs232 port
These notes are my edited version of Bifferos' instructions for disconnecting the serial console from root processes.
NB - it is necessary to have a toolchain and then recompile and re-burn the kernel to the board.
After building from the source tarball:
cd openwrt
make kernel_menuconfig
uncheck:
Device Drivers -> Character devices -> Serial Drivers ->
Console on 8250/16550 and compatible serial port.
uncheck:
Kernel Hacking -> Early printk
Run 'make V=99' and flash the resultant kernel.
Make sure network access to your rootfs is working because you will
have no other way of logging in.
Backup of my "no chatter kernel" this is the Biff 1.3 default plus stty checked * in busybox
Result
After pressing 4 at the end of the burn process the dmesg boot report was not presented.
After a short time I pressed return and saw the Openwrt splash screen.
The terminal then remained silent and unresponsive as expected.
I could set up a ssh terminal on the network as usual.
Drive ttyS0 from a web page hosted on the Bifferboard
The webpage scripts are contained in the www folder in the Bifferboard route file system - they are like this
www/index.html
links to
www/cgi-bin/drive_ttyS0.cgi
and this displays
www/ttyS0_out.html
links in ttyS0_out.html send strings to
www/cg-bin/pg-string_to_ttyS0.sh
which uses an ash script to send strings to ttyS0
To force raw mode (one character at a time - no need for a 'return' at the end of a line of data) I added
stty raw ispeed 9600 ospeed 9600 -F /dev/ttyS0
to
pg-string_to_ttyS0.sh
The web page now displays characters sent back by the remote terminal during a 2 second time window
using stty
send "hello" out at 57600 baud -
root@Biff_09:~# stty ispeed 57600 ospeed 57600 -F /dev/ttyS0
root@Biff_09:~# stty speed -F /dev/ttyS0
57600
root@Biff_09:~# echo -n "hello">/dev/ttyS0
echo -n "hello">/dev/ttyS0
/etc/inittab is now
::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
- then a return character in the rs232 terminal now has no effect (it reset the speed before)
to receive characters one at a time with no need to send a return at the end of a line use raw
root@Biff_09:~# stty raw ispeed 9600 ospeed 9600 -F /dev/ttyS0
Talking to the port
After -
root@Biff_09:~# cat /dev/ttyS0
I could type in the serial terminal and instantly see the characters in the ssh session
In the ssh session I did
echo -n "Hello from router">/dev/ttyS0
and saw
Hello from router
on the ttyS0 terminal