This script will get temperature from Watchport/T and Watchport/H sensors and write it to /var/log/watchport1.log file.
# # This script reads the temparature value from Watchport/T Temperature sensor
# which is connected to the USB port.
# Working on Centos 5 Linux, run by crontab
# Change '\rT\r' (Celcius) to '\rTF\r' to get Fahrenheit
t_name=T1 # Sensor name
t_timesec=5
t_parity=none
t_speed=115200
t_file1=/var/log/watchport1.tmp
logfile=/var/log/watchport1.log
t_USBport=/dev/ttyUSB0
if [ ! -f ${logfile} ]; then
echo "Sensor;Date;Time;Temperature">$logfile
fi
t_time=`date +%H:%M`
t_date=`date +%d:%m:%Y`
# Remark file is Binary !
(echo -e '\rT\r' ; sleep $t_timesec; ) |cu --parity=$t_parity -l $t_USBport -s $t_speed dir>$t_file1 2>/dev/null
t_temperature=`cat -A $t_file1 | grep ^+|sed -e 's/\^.*//'`
echo "$t_name;$t_date;$t_time;$t_temperature">>$logfile
exit 0
Thanks about this script to Timo Unkuri.
If you don’t get temperature to your log file you might have same problem which I had. I tried to talk directly to sensor with cu:
and just got this kind of error:
cu: /dev/ttyUSB0: Line in use
Only way that I found to fix this was change ownership of /dev/ttyUSB0 to uucp:
after that script started to work perfectly.
If you want to run this script example every 5 minute just write to /etc/crontab:
Amazon.Com:
Digi Intl. WATCHPORT/T TEMPERATURE SENSOR ( 301-1144-01 )
Digi Intl. WATCHPORT/H HUMIDITY & ( 301-1141-01 )
Linux Command Line and Shell Scripting Bible






Works great but in the code above all the instances of ‘>’ should be replaced by ‘>’. Somehow your text got mangled when you posted it.
I also had to compile the io_ti.ko module to get usbserial to recognize my Watchport/H.
And ofcourse a
while true
do
.
sleep 60
done
around your code and starting it in de background:
./get-data.sh &
will log the temperature every minute.
Thanks!
I didn’t really need to log to a file or schedule it. I basically just wanted to create a nagios checks. I used the script above, and modified it to create nagios scripts for checking temperature & humidity, and it really didn’t take much.
Basically, I made the following modifications
-check permissions on /dev/ttyUSB0, since this seemed to be an issue on my system
If [ -w "/dev/ttyUSB0"]…then….fi
-check to see if the script was already running, and wait until the previous check completed.
SERVICE=`ps ax | grep -v grep | grep $t_USBport`
while [ "$SERVICE" ]
do
sleep
done
-check to see if output temperature or humidity was within a range.
if test $t_temperature -gt $HWARN -o $t_temperature -lt $LWARN
then
if test $t_temperature -gt $HCRIT -o $t_temperature -lt $LCRIT
Great blog!! You should start many more. I love all the info provided. I will stay tuned :)