I have an Arduino Uno running a little script that reads from the SHT-15 temp / humidity sensor, then ouputs the values via serial. The output looks great in the Arduino Serial monitor, and I can even cat the output. The output looks like this:
Code:
temp=68.04
humidity=54.47
temp=68.00
humidity=54.47
When this same Arduino was hooked up to an Eee PC, I would run this command to pull the data off of the serial port and into a txt file:
Code:
ttylog -b 38400 -d /dev/ttyUSB0 | tee /home/holotone/temphumidity/results.txt 2>&1
On the newer computer that the Arduino is connected to, this only produces garbage output, a couple weird characters repeated over and over really fast. The output looks fine via the Arduino serial monitor, and also looks fine when I use cat or picocom.
Ultimately, I want to somehow monitor the serial output of the Arduino and log the results somewhere they are easy to access. Email notification when temp / humidity thresholds are reached is a must. Data visualization (via Google Charts, maybe?) would be awesome.
A buddy helped me whip up a bash script (monitor.sh) to monitor the log file (results.txt) that's supposed to be generated by ttylog (which doesn't work on the new computer); Here is monitor.sh for reference:
Code:
#!/bin/bash
# define file vars
tempfile=/home/holotone/temphumidity/results.txt
logfile=/home/holotone/temphumidity/logfile.log
errorlog=/home/holotone/temphumidity/error.log
max_temp="85.00"
min_temp="63.00"
# extract $temp and $humidity
data=`tail -n 4 $tempfile`
eval $data
# generate timestamp
date=`date +%Y-%m-%d,%H:%M:%S`
# calculate alert threshhold
if [[ "$temp" > "$max_temp" ]]
then
# send email
echo "Currently: $temp / Max: $max_temp at $date" | mail -s "Temperature Exceeded!" "me@email.com"
echo "$date: $temp / $max_temp" >> $errorlog
echo "Too hot! Currently: $temp; Maximum of $max_temp exceeded!"
else
echo "Temp OK: Currently: $temp"
fi
# save to logfile
string="$date,$temp,$humidity"
echo $string >> $logfile
# erase existing temp file
echo "" > $tempfile
Basically I moved the setup from an Eee PC on which is was working to a new computer and now nothing works. Step 1 (serial > txt via ttylog) does not work correctly. Even if it did, the monitor.sh bash script doesn't work any more either, even when I manually enter values into the results.txt file that ttylog is not creating correctly. Here's the error I get when I try to run monitor.sh:
Code:
holotone@piff ~/temphumidity $ sh monitor.sh
monitor.sh: 18: monitor.sh: [[: not found
Temp OK: Currently:
As may be evidenced by my clear lack of understanding, I'm not much of a coder. I get the basics, but I never would have made it this far without the significant help of a friend.
What's going on here? Is there a better way to take the serial output from the Arduino and use it to log historical temp / humidity data and give me notifications when thresholds are reached?
Thanks in advance for the help!
Bookmarks