Connect serial to a usb port and open it
Connect to Wifi and use ssh to connect over wifi:
ssh [email protected] (password root)
To write to the serial port (will be shown on the Laptop on the serial monitor):
root@g20-demo:/# echo -e "Hello, me!\n" > /dev/ttyATH0
To read from the serial port, run:
root@g20-demo:/# cat /dev/ttyATH0
i wrote bla
and foo bar
Then, type something on the serial console, which will then be seen on the ssh connection
In order to stop the console on the serial port and show less messages, do (see https://wiki.openwrt.org/doc/recipes/terminate.console.on.serial) and http://www.8devices.com/community/viewtopic.php?f=5&t=557 http://www.8devices.com/community/viewtopic.php?f=13&t=723
root@g20-demo:~# cat /etc/sysctl.conf
kernel.ptintk = 0 4 1 7
kernel.panic=3
# changed to
kernel.printk = 0 4 1 7
root@g20-demo:~# cat /etc/sysctl.conf
::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K shutdown
::askconsole:/bin/ash --login
# changed last line to (disables console on serial!)
#::askconsole:/bin/ash --login
Connect over Wifi using ssh to the Carambola2.
Store the script below as test-serial.php
and run it using /usr/bin/php-cli ./test-serial.php
:
<?php
$h = fopen('/dev/ttyATH0', 'rwb+');
stream_set_blocking($h, false);
echo "start reading\n";
while(True) {
echo "read now\n";
$buffer = fread($h, 4096);
echo "buffer is".$buffer."\n";
fwrite($h, "hello-serial\n");
usleep(1000000);
}
Connet another terminal to the Serial port of the Carambola2. The serial port should output hello-serial
every second.
If you now send something to the serial and then press enter, e.g. echo -e "test2\n" > /dev/myserial
then the php script on the ssh console will read it and echo it to the ssh console.
Note: This is only working, if the console is disabled on ttyATH0
by commenting it out in the /etc/inittab
file as described above.
/dev/ttyATH0 is first serial console, as it is not named /dev/ttyS0...9 in ARM based systems, only in x86 etc..
run the following to get infos on command line:
cat /proc/cmdline
port /dev/ttyATH0
can already be owned by both kernel (console=ttyATH0,115200
) and init processes (see /etc/inittab
), that means, that even if can use the port, kernel messages can interfere with your data.