« Count Down Timer | Main | Installing Snort and Barnyard2 in Ubuntu 9.10: Part 1 »

Monday, March 15, 2010

Software to support the TEMPer USB thermistor

The TEMPer USB thermistor is a small unit you can buy online. The short version is that this is a cheap solution to having a computer record temperatures, but there are some issues. First of all, the company that makes these has used a variety of internals--early versions were straight serial devices converted to usb. Sometime in the last year or two, they switched to unit that use the HID interface, so you may need to search around to find code that will work with your unit. Also the software that comes with it is really bad, and support is almost non-existant, and the language barrier for english speakers is pretty severe. But the good news is the net being what it is, there are a lot of folks working on these things, and now there are some pretty good options.

Some links for background:

The last link is the one that was most useful to me, especially the part down in the comments--Magnus Sulland wrote a perl module that leverages libusb to read the device (many thanks to him!).

This document outlines installing his code on Unbuntu 9.10 (Karmic). I also tried this on Redhat and OSX, but no joy--the perl used on those systems is different (5.8.x) and this requires 5.10. Also, I think that using libusb might be tricky on OSX, since Apple handles some things very differently. If anyone out there has good installation for a TEMPer unit for OSX or Redhat, drop me a line.

First thing to do is install libusb's headers:

sudo apt-get install libusb-dev

Then we'll install some perl modules:

sudo cpan -fi Bundle::CPAN

If this is the first time you've run cpan, it will walk you through a series of configuration questions. I just took all the defaults and choose some local repositories when prompted. I'm sure that there's some way to tell cpan to not ask questions and just use defaults, but I don't know how (love to learn how tho).

Next, install the MakeMaker util:

sudo cpan -fi ExtUtils::MakeMaker

You may see some warnings that there are dependencies that have to be satisfied, just say yes. They'll look something like this:

---- Unsatisfied dependencies detected during [S/SI/SISYPHUS/Inline-0.46.tar.gz] -----

Parse::RecDescent Shall I follow them and prepend them to the queue

of modules we are processing right now? [yes]

I just hit return to accept the yes.

Once that's all done run these commands:

sudo cpan -fi Inline::MakeMaker 
sudo cpan -fi Device::USB

Now, install Magnus's module for the TEMPer device:

sudo cpan -fi Device::USB::PCSensor::HidTEMPer

The source for this is up at: http://search.cpan.org/dist/Device-USB-PCSensor-HidTEMPer/

Now, you need a file that will call the perl module, mine is named temper_mon.pl
cd ..
wget -O temper_mon.pl http://www.cs.unc.edu/~hays/dev/bash/temper/temper_mon.pl
chmod a+x temper_mon.pl
The file contains this code from Magnus Sulland into the file:
#! /usr/bin/perl

use 5.010;
use strict;
use warnings;
use Carp;
use Device::USB;
use Device::USB::PCSensor::HidTEMPer::Device;
use Device::USB::PCSensor::HidTEMPer::NTC;
use Device::USB::PCSensor::HidTEMPer::TEMPer; 
use lib;
use Device::USB::PCSensor::HidTEMPer;

my $pcsensor  = Device::USB::PCSensor::HidTEMPer->new();
my @devices   = $pcsensor->list_devices();
foreach my $device ( @devices )
   say $device->internal()->celsius();

Now, try to run it:

sudo ./temper_mon.pl

At first mine didn't respond. On one machine it started working on the third try. Another required a reboot. But in general, so far so good.

Note: After doing some installs, I started running into problems getting a segmentation fault when running the temper_mon.pl script. I got some advice from Magnus, and it turns out that the upgrade from Device::USB version 0.31 to 0.32 or 0.32 breaks this. To get around this issue in the short term, I downloaded version 0.31, built and installed that from source. I've put a copy of device-usb0.31.tgz up in case you need it. To use this, run the following commands:

wget -O device-usb0.31.tgz \
tar -xvzf device-usb0.31.tgz 
cd Device-USB-0.31/
perl Makefile.PL
make test
sudo make install

There's also a README file in the package with some information.

I've also written a short shell script to use with this as a nagios plugin and also a php program to use as a web logging tool, see Service Monitoring with the TEMPer USB thermistor for details.

Posted by bil at 8:07 PM
Edited on: Sunday, April 04, 2010 12:24 PM
Categories: My Software, Other Software, Work
Comment by internet - Sunday 09th May 2010 06:49:34 PM

I ran into this problem as well..
WARNING: Ignoring corrupt/ truncated waldofile '/ var/ log/ snort/ barnyard.waldo'
Opened spool file '/ var/ log/ snort/ snort.log.1271249772'
ERROR: Unknown record type read: 2148576734
Fatal Error, Quitting..
The fix was to configure bardyard as indicated on this site:
http: / / www.securixlive.com/ barnyard2/ faq.php

I also had a problem where Base-1.4.4 only displayed the main screen, none of the sub pages showed up. After turning on debugging in the php.ini i found the error Fatal error: Call to undefined method ProtocolFieldCriteria: : ProtocolFieldCriteria() in / var/ www/ base-1.4.4/ includes/ base_state_citems.inc.php on line 1113 I traced the problem back to something that was resolved in the Base-1.4.5 release Using 1.4.5 resolved the problem. http: / / sourceforge.net/ projects/ secureideas/ files/
Comment by Aaron - Thursday 26th August 2010 11:33:10 PM

I was able to get the TEMPer to work on ubuntu 10.04, the first try, using your instructions. Thank you very much for the work you've put into this howto.
Comment by jnihil - Thursday 02nd September 2010 08:24:44 PM

Likewise, no issues. Thanks a lot for the great article.
Comment by Jack Myers - Monday 13th September 2010 10:22:29 PM

When I reach the step:
sudo cpan -fi Device: : USB
and it hits the tests, it maxes out 7 gb ram and 7gb swap, thrashes my drive badly, kills Firefox & any other programs running and fails just about all the tests. It eventually finishes but leave the OS in such a sad state that I have to reboot.
Not sure what is going on here.
I'm on Ubuntu 10.04 64 bit, AMD quad w/ 7gb ram. I see that others have been successful on 10.04 so I'm confused.

Any suggestions on how I can track down the problem? (I'm pretty new to PERL but have been programming in a couple of dozen languages for a living for the last 30 years. Generally, adding a new language comes easy to me though I'm just starting reading the O'Reilly Perl nutshell book).

Thanks for any suggestions you may have (and for the work you've done on this).

Comment by eclyptox - Wednesday 15th September 2010 06:36:32 PM

Hi! Yesterday I worked out to make it run as you say. But since today in the internal in celcius I only read 0.99609375.

I read the temperature several times, but the internal one only shows that number.

Comment by bil - Thursday 16th September 2010 01:46:17 PM

Sorry, these last two I can't be of much help with. You might want to check out this like:
There's an extended discussion there, and Magnus Sulland has updated the perl code, but I haven't tried that or gone to ubuntu 10. I'll post a note when I do about my results, should be doing that in a couple of weeks. Also, 0.99609375 I think represents a limit of some kind being exceeded.
Comment by Baskin Tapkan - Saturday 05th February 2011 06:48:12 PM

Thanks for the great post. Worked out great. I am in the process of brushing up with Perl and write the results to a file using perhaps Cron. Any other automated ideas? : )


Comment by Torsten - Monday 02nd May 2011 07:27:20 AM


i tried the TEMPer stick for a few days with good results.
But today i can only read out 0.99609375 as 2 comments above.
Some one known this problem ?

BR/ Torsten
Comment by bil - Monday 02nd May 2011 09:02:38 AM

Yes, I see similar behavior from time to time, usually just reseating the Temper USB device clears it.
Comment by zelotoh - Wednesday 01st June 2011 05:33:26 PM


Do you know how can I execute temper_mon.pl without sudo rights?

Thanks in advance
Comment by bil - Wednesday 01st June 2011 07:34:08 PM

No, I don't, since it needs privs to access the temper device. But if you add your user id, or if you want to allow anyone on your server to use it without admin rights, you can edit the sudoers file with visudo to grant users the ability to run this or any other command without typing a password. If you check out the followup to this article, there's some discussion of how to allow a user npre to run plugins without a password, and an example. Feel free to email me if you have questions,