This article will describe setting up a system that will utilize a lightweight command line (CLI) install of Linux (Ubuntu in this example) to capture RS232 (serial) information, capture it and upload it to an ftp server.
This is useful for applications including data collection from sensors or other serial devices such as amateur packet radio – and will utilize the data on a web site or other remote machine.
The process will involve starting the program ‘screen’ and ‘minicom’ when the machine starts up. The ‘screen’ output will be captured to text file. This text file will be sent up to an ftp server using ‘lftp’, scheduled via a ‘cron’ job.
This article will not cover installing a command line Linux such as Ubuntu minimal – it is assumed you have a functional system. When the machine starts up, it should start a detached ‘screen’ session, starting minicom (terminal program) within – logging the screen output to file.
To install screen and minicom, use: sudo apt-get install screen minicom
Verify your minicom settings
Run: sudo minicom -r, and set the default port and clear out the init strings since the startup script runs as root. Ctrl-A o, set to ttyS0, 1200 (or the appropriate other baud rate). Note that I also had to edit sudo nano /etc/minicom/minirc.dfl to get it working properly — even though I did sudo minicom -r — contents of my file:
# Machine-generated file – use “minicom -s” to change parameters.
pu baudrate 1200
pu bits 8
pu parity N
pu stopbits 1
pr port /dev/ttyS0
Get screen to auto-start at boot and run minicom:
In /etc/init.d, create a startup script: sudo nano /etc/init.d/startHAM
/usr/bin/screen -d -m -L /usr/bin/minicom
modify the file so it will run at startup:
sudo chmod +x /etc/init.d/startHAM
sudo update-rc.d startHAM defaults 80
I could not get logging to work by passing “-L”, so edit the file: sudo nano /etc/screenrc
add the lines:
It is recommended your reboot after editing these files. After you reboot you can see if it is working by typing sudo screen -r to resume the screen session – you should be in minicom and should be able to see/type to your TNC (or device).
If that works, you can check the log file – mine is saved to the root. nano /screenlog.0
You can tail it to watch in real time anything written to the log: tail -f /screenlog.0
You may want to sudo screen -r, press return / mheard, etc. (for a packet modem) to generate some text, then ctrl-a d (detach) and then nano /screenlog.0 and go to the end – sometimes the control characters may hide output, but it is really there.
Now you have screen and minicom starting at startup and all the screen output is being save to the screenlog.0 file.
Uploading the screenlog.0 file to your web site ftp server:
The program lftp can be used to synchronize files to an ftp server (your web host). To install lftp, type: sudo apt-get install lftp
Create an lftp script file “SyncHAM.txt” in your home directory: sudo nano SyncHAM.txt
open ftp: //username:firstname.lastname@example.org
set ftp:ssl-allow no
mput -O /public_html/myhostbasepath /screenlog.0
-O is the base path on the web host, after that is the path to the file to be sent (screenlog).
note the ssl-allow no is optional if you host does not support ssl, the -R means reverse – send the file UP to ftp.
To test it, type sudo lftp SyncHAM.txt
Setup Cron Job
edit the file: sudo nano /etc/cron.daily/hamsync
lftp -f /home/cmate/SyncHAM.txt
echo “done with SyncHAM.txt”
make it executable:
sudo chmod +x hamsync
Be sure to reboot the machine. You should now have a functional system to capture the serial data and upload it daily to the ftp server.