Watchport/T Temperature and humidity sensor on Linux

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 

if [ ! -f ${logfile} ]; then
 echo "Sensor;Date;Time;Temperature">$logfile

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

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:

cu –parity=none -l /dev/ttyUSB0

and just got this kind of error:

cu: open (/dev/ttyUSB0): Permission denied 
cu: /dev/ttyUSB0: Line in use

Only way that I found to fix this was change ownership of /dev/ttyUSB0 to uucp

chown uucp /dev/ttyUSB0

after that script started to work perfectly. If you want to run this script example every 5 minute just write to /etc/crontab:

*/5 * * * * /where/is/your/

    Leave a Reply

    Your email address will not be published. Required fields are marked *