I'm trying to save the input from the USB port on an Arduino Yun (running openWRT) to a file so it can be ready from a PHP page hosted on the Yun and accessed via a browser.
The idea is the Yun acts as a web interface to the boiler, via the RS485, logging all data, and generating graphs of various temperatures fed from the boiler and saved to file.
The data comes from an RS485 feed (from a boiler), via an FTDI cable.
The data is fed through every second in the form...
DAT,39665,8,0.00,-273.15,-273.15,-273.15,0,0.00,0.60,0.00,0.00,-6.25,0.00,0.00,60.00,60.00,225,-273.15,0.00
STAT,39666,0.00,0,19,924,2,0,0,0,0,2,2,2,0,0
I have had some luck using the following tip... Linux shell: save input line from Serial Port each minute and send to remote server
This last article provides the code:
#!/bin/bash
while read line; do
if [ "$line" != "EOF" ]; then
echo "$line" >> file.txt
else
break
fi
done < /dev/ttyUSB0
However it raises an error line 8: syntax error: unexpected "done" (expecting then)
but I can't figure why, so have simplified to:
#!/bin/bash
while read line; do
echo "$line" >> hsffile.txt
done < /dev/ttyUSB0
Actions so far:
Install FTDI driver
opkg install kmod-usb-serial-ftdi
Created a script called boiler2text.sh in a folder /bin/ihiu based on simplified version of above.
Given the file permission to run
chmod u+x boiler2text.sh
Executed the script from within Putty SSH window.
sh /bin/ihiu/boiler2text.sh
So far, it works nice, but I've hit some problems:
- I need to have the script run 24/7 without having to SSH into the system. I can execute a system command from within a PHP page, but it just hangs when it runs the script, and nothing appears to be output to file.
- As the file starts getting quite large, I need to ideally delete a line from the start of the file each time one is added - once the file reaches a maximum file size. Or have it save to a file name based on the date and hour of the day, so filename changes every hour.
I'm new to Linux, and any pointers would be very much appreciated.