Menu
Index

Contact
Atom Feed
Comments Atom Feed

Similar Articles

2011-12-22 09:30
Peak Network Bandwidth for Cacti
2011-11-16 20:12
OpenVz User Beancounters (UBC) on Cacti via SNMP
2009-10-31 14:46
SMART stats on Cacti (via SNMP)
2011-06-25 12:33
Dovecot stats on Cacti (via SNMP)
2009-10-31 11:03
Linux (Debian, Ubuntu) SNMP basics

Recent Articles

2019-07-28 16:35
git http with Nginx via Flask wsgi application (git4nginx)
2018-05-15 16:48
Raspberry Pi Camera, IR Lights and more
2017-04-23 14:21
Raspberry Pi SD Card Test
2017-04-07 10:54
DNS Firewall (blackhole malicious, like Pi-hole) with bind9
2017-03-28 13:07
Kubernetes to learn Part 4

Glen Pitt-Pladdy :: Blog

TEMPer under Linux (perl) with Cacti

I was looking for a cheap way to log temperatures, I hunted for a USB thermometer that could be used and came across the cheap and widely available "TEMPer" USB thermometers. These can be bought on eBay for under a tenner inclusive of shipping and are available in a number of variants - in my case TEMPer1 which has the probe on a lead so it can be placed away from the (hot) machine which the USB connects to and head generated in the USB bit doesn't affect the readings.

These are ideal for so many things:

  • machine room / rack temperatures
  • home / freezing warning while you are away
  • knowing the optimum times of day to open / close the windows to maintain a comfortable indoor temperature
  • all sorts of things that get hot or cold round the house / office like: fridges, freezers, boilers, heating, air conditioning etc.

TEMPer1 USB Temperature Probe Thermometer

A bit of scripting and you could use these to email / SMS warnings very easily. In my case I plumb them into Cacti from where you can use any of it's monitoring / warning plugins to do whatever you want with it.

TEMPer with Linux / Perl

The TEMPer devices behave as HID devices and there are a load of simple userspace programs to use them. In my case I noticed libdevice-usb-pcsensor-hidtemper-perl which is a Perl module for accessing them and available under recent Ubuntu and Debian (from wheezy). If you are not running a Ubuntu or Debian with them then grab the source package and build your own. I've successfully built the packages for Lucid and Squeeze and only had to edit debian/compat and change it to "7" to build libdevice-usb-perl on the older distros which is also needed.

Other than that once all the build dependencies are in a simple fakeroot dpkg-buildpackage produces ready to install packages. I am successfully using this under Ubuntu Lucid and Debian Squeeze with packages build like this.

The example code in the man pages is about all you need. The module is trivial to use - a quick bit of code and I had a snmpd extension script to pick the temperatures up. One catch is that they do sometimes produce false readings on the first read but that is easily solved by doing a dummy read first and then the real one.

The simple Perl script I to read all the TEMPer1 devices I have connected: readTEMPer

Make this executable and make sure you have privilege to read devices when you run it.

Calibration

The TEMPer doesn't seem to be particularly accurate so the script has the option to add basic (scale & offset) calibration in. This can be done by measuring 2 known temperatures.

In my case I got a jug of hot water and the TEMPer said 76.5 while an accurate thermometer said 79.7 - then in room temperature water TEMPer said 17 and the accurate thermometer said 18.5.

Then we do some maths to work out the scale:

  • The range of the TEMPer measurements is 76.5 - 17 = 59.5
  • The range of the accurate thermometer is 79.7 - 18.5 = 61.2
  • The scale needed for TEMPer is 61.2 / 59.5 = 1.029

Now we need to work out the offset:

  • In the hot water TEMPer with scaling will read 76.5 * 1.029 = 78.7
  • The offset needed is 79.7 - 78.7 = 1

Let's verify those at the cold temperature: 17 * 1.029 + 1 = 18.5

So that's the calibration that you can add into the script:

my @CAL = (    # calibration list for each sensor
    { 'scale' => 1.029, 'offset' => 1 },
);

Be aware that if you have multiple devices, these seem to be ordered as they are detected which depends both on the bus (hub) and order of connection (or detection at boot). There is no serial number or anything about each TEMPer to tell them apart so you will have to experient and check how things get ordered depending on their connection.

TEMPer via SNMP

I have previously described SNMP basics and this script can be used as an snmpd extension script. Add the lines to snmpd.conf:

extend temper /etc/snmp/readTEMPer

.... or wherever you put the script, and restart snmpd.

The script will be run by snmpd as it's user. On Debian based systems that's the snmp user and group which doesn't have access to the device by default. To give access you can add the following into a rules file in /etc/udev/rules.d - in my case I called it 000-local.rules and it contains all my local modifications:

# TEMPer1 USB thermometer
ATTR{idVendor}=="1130", ATTR{idProduct}=="660c", OWNER="root", GROUP="snmp", MODE="0640"

Re-plug the device and that should be sufficient for it to be readable via snmpd. If you have other compatible devices you can use lsusb to check the vendor and product codes and add additional config as needed.

Graphing with Cacti

First off, as this template use MIN and MAX you need to makes sure that the right Consolidation Functions are set - under "Data Sources" select RRAs and for each RRA ensure that the AVERAGE, MIN and MAX are selected - I just selected the lot. Otherwise you will need to remove the traces from the graph template that don't have a matching Consolidation Function selected.

Cacti RRA CF

Download the TEMPer Cacti template and add the graph(s) of your choice from template and it should end up looking something like this depending on which graph you choose:

TEMPer temperature graph on Cacti

The basic template gives graphs for single sensors as well as 2 and 3 sensors on a graph, but it's easy to duplicate and make whatever variants suits you from the templates provided. For the averaged graphs there are min/max lines which should show the range in the averaging period - this is why we need the MIN and MAX CFs above. Again, if you don't want them then you can change the template to suit.

Cacti snag

Often things work perfectly for one or sometimes two sensors, but more than that and it's likely that you will start ending up with missing data in Cacti. When you check via SNMP everything is fine and the data is there.

The problem I have discovered is the device timeout setting for SNMP in Cacti. It is often set to something like 500ms which is plenty for most things. TEMPer can however take a second or more to read all the devices so if you have this problem then it's likely that you will need increase the SNMP timeout for the host in Cacti.