Flickr Photos

Young Red Fox
Red Fox eating rowan berries
Roe Deer
Leopard in the rain
Lion mum taking care of cubs
Male Lion
Lion Cubs Playing
Lazy Spotted Hyena
Female Lion
Golden Jackal

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.

<br />
#!/bin/bash<br />
# # This script reads the temparature value from Watchport/T Temperature sensor<br />
# which is connected to the USB port.</p>
<p># Working on Centos 5 Linux, run by crontab<br />
# Change '\rT\r' (Celcius) to '\rTF\r' to get Fahrenheit<br />
t_name=T1 # Sensor name<br />
t_timesec=5<br />
t_parity=none<br />
t_speed=115200<br />
t_file1=/var/log/watchport1.tmp<br />
logfile=/var/log/watchport1.log<br />
<p>if [ ! -f ${logfile} ]; then<br />
 echo &quot;Sensor;Date;Time;Temperature&quot;&gt;$logfile<br />
<p>t_time=`date +%H:%M`<br />
t_date=`date +%d:%m:%Y`</p>
<p># Remark file is Binary !<br />
(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<br />
t_temperature=`cat -A $t_file1 | grep ^+|sed -e 's/\^.*//'`<br />
echo &quot;$t_name;$t_date;$t_time;$t_temperature&quot;&gt;&gt;$logfile<br />
exit 0<br />

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:
<br />
 cu: open (/dev/ttyUSB0): Permission denied<br />
 cu: /dev/ttyUSB0: Line in use<br />

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/

8 comments to Watchport/T Temperature sensor on Linux

  • Ernst

    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
    sleep 60

    around your code and starting it in de background:

    ./ &

    will log the temperature every minute.


  • Robnhood

    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” ]

    -check to see if output temperature or humidity was within a range.

    if test $t_temperature -gt $HWARN -o $t_temperature -lt $LWARN
    if test $t_temperature -gt $HCRIT -o $t_temperature -lt $LCRIT

  • Buy Backlinks

    Great blog!! You should start many more. I love all the info provided. I will stay tuned :)

  • Thanks for this script. I couldn’t get it to work properly, but it was the main basis for my own script. I have a Digi Watchport /H that does both temp and humidity. My problem was the output from the Watchport terminated with a CTRL+G (ASCII “bell”) and CTRL+M (DOS/Win newline) characters. When I used Linux “cat” command, the ^G was killing the temp and humid readings on a line-by-line basis. I ultimately piped the output to “tr -d ‘[:cntrl:]'” and that got rid of the control characters.

    I added some further refinements so I could use MRTG to graph T/H in my apartment. It’s working really well thanks to your help!

  • Szabolcs Hodosi


    This seems not working at all. I tried it out on Raspbian and I got this:

    root@teardrop:/var/log# cat watchport1.log
    root@teardrop:/var/log# cat watchport1.tmp


    No real temperature values returned.

    root@teardrop:/var/log# ls -la /dev/ttyUSB*
    lrwxrwxrwx 1 root root 7 Jan 1 1970 /dev/ttyUSB.Ebedlo -> ttyUSB1
    lrwxrwxrwx 1 root root 7 Jan 1 1970 /dev/ttyUSB.Haloszoba -> ttyUSB0
    lrwxrwxrwx 1 root root 7 Jan 1 1970 /dev/ttyUSB.Nappali -> ttyUSB2
    crw-rw—- 1 uucp dialout 188, 0 Jan 18 00:48 /dev/ttyUSB0
    crw-rw—- 1 uucp dialout 188, 1 Jan 18 00:46 /dev/ttyUSB1
    crw-rw—- 1 uucp dialout 188, 2 Jan 18 00:22 /dev/ttyUSB2

    Could you please help me with this issue?

    • I have had some problems with Raspberry Pi and watchport too :-/ same script seems to work on desktop/laptop PC but when I try it on raspberry pi it does something weird.

  • nipple

    Hello mates, how is everything, and what you desire to say regarding this
    piece of writing, in my view its really amazing designed for me.

  • fwiffo

    this will give u the humidity too for those with the watchport/H

    i’ve also slightly improved the pattern matching in the script

    # # 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;Humidity”>$logfile

    t_time=`date +%H:%M`
    t_date=`date +%d:%m:%Y`

    # Remark file is Binary !
    (echo -e ‘\rTCH\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 -e ^+ -e ^- | sed -e ‘s/\^.*//’`
    h_humidity=`cat -A $t_file1 | grep -e ^+ -e ^- | sed -e ‘s/.*[C|F]?*\^M//’|sed -e ‘s/\^M.*//’`
    echo “$t_name;$t_date;$t_time;$t_temperature;$h_humidity”>>$logfile
    exit 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=""> <s> <strike> <strong>




This site uses Akismet to reduce spam. Learn how your comment data is processed.