www.flickr.com
This is a Flickr badge showing items in a set called Gadgets and stuff. Make your own badge here.

Watchport/T Temperature sensor on Linux

This script will get temperature from Watchport/T and Watchport/H sensors and write it to /var/log/watchport1.log file.

#!/bin/bash
# # 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

<span id="more-808"></span>

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&gt;$t_file1 2&gt;/dev/null
t_temperature=`cat -A $t_file1 | grep ^+|sed -e 's/\^.*//'`
echo "$t_name;$t_date;$t_time;$t_temperature"&gt;&gt;$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:

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/script.sh
  • Twitter
  • Digg
  • Facebook
  • del.icio.us
  • LinkedIn
  • Slashdot
  • Google Bookmarks
  • HackerNews
  • Reddit
  • StumbleUpon
  • FriendFeed
  • PDF
  • email
  • Haohao
  • Identi.ca
  • Live
  • MSN Reporter
  • 豆瓣
  • 豆瓣九点
  • MySpace
  • Netvibes

2 comments to Watchport/T Temperature sensor on Linux

  • Ernst NETHERLANDS Mozilla Firefox Windows

    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!

    ReplyReply

    Like or Dislike: Thumb up 1 Thumb down 0

  • Robnhood UNITED STATES Mozilla Firefox SuSE Linux

    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

    ReplyReply

    Like or Dislike: Thumb up 1 Thumb down 0

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Comment validation by @

CommentLuv Enabled