I am using a OrangePI board to log data from an arduino which gives a line by serial output every 10 secs.
20.0 / 12.0 V
Which is loggig the Temperature measured by a temperature sensor attached to the arduino and the voltage which is for battery saving purposes.
I have managed to build a script from snippets and suggestions collected around the web which does exactly what I need.
#!/bin/bash
# Script will run at reboot.
echo "Beginning Temperature Log!"
NOW=$(date +"%Y-%m-%d")
LOGFILE="log-$NOW"
name=$LOGFILE
if [[ -e $name ]] ; then
i=2
while [[ -e $name-$i ]] ; do
let i++
done
name=$name-$i
fi
ts </dev/ttyUSB0>$name
The script runs everytime I boot the machine by setting a cron @reboot, which works pretty well.
Now I plan to extend the arduino code with a "battery guard" which sends a warning to the serial output when the voltage goes below certain level
20.0 / 9.0 V / BAT!
At this point the OrangePI should halt/shutdown and send a specific letter to the arduino when its "safe to shutdown", so that the arduino can deactivate a relay and switch off the whole system. (and itself)
So I assume the OrangePI should always watch the last line in the arduino output for the string "BAT!" and then trigger the shutdown.
I have a concept for the harware part of this project Also a concept for the arduino code
But no idea for how to code this on Linux. Maybe the approach is wrong as it is right now and the whole thing should be coded in python or something?
Thanks for any suggestions.