Diary of a geek

May 2007
Mon Tue Wed Thu Fri Sat Sun
 
26
     

My ugly mug

Where's Andrew?

Categories

Other people's blogs

Subscribe

RSS feed

Contact me

JavaScript required


Saturday, 26 May 2007

Finding out just how hot the linen cupboard is...

I decided to move the old 1-RU Pentium III server (the thing providing all the storage for my MythTV box via ATAoE) from under the bed in the spare room to the linen cupboard. It had a brief stop in the wardrobe in the spare room, but it didn't really help with the noise.

Sarah was a concerned about the heat in the linen cupboard, as this is where the patch panel is, so caesar is already in here, along with an Ethernet switch, an ADSL modem, a wireless access point, and the Vonage ATA. There's a lot of DC plug packs generating heat, so it was a reasonable concern.

I figured in this day and age, someone must make some sort of USB temperature sensor, and after some searching around, I discovered the DLP-TEMP-G, which seemed to be about the right price, doing what I wanted.

I'm going to say the web page was a bit ambiguous, but it was probably just late at night, because I read the bottom as having the option to buy it from Mouser, or via PayPal directly with DLP Design. So I went down the latter path, because I generally prefer to deal directly with the manufacturer. Turns out what I was actually ordering was just a "Test Application", so that email I'd received the day after I placed my order for two units was all I was going to get. I figured this out after a week or so of wondering when it was going to arrive.

They were really good about it, and refunded me my $40, even though I'd received said software, and I placed a new order with Mouser for what I really wanted.

Now this time, I just didn't read things thoroughly enough, although I'll still say that things were a little ambiguously worded. The page I've linked to above does say "DLP-TEMP-G and 1 DS18B20 sensor $25.00", but when reading datasheet, it goes on about three sensors, and coming with one that isn't soldered on so that you can optionally run a cable between it and the board. I somehow interpreted this as meaning there were two sensors on the board, and one loose. Not the case. The board supports having up to three DS18B20 sensors attached to it, however you please. It comes with one unattached. In hindsight, why would you want two temperature sensors directly on the board?

So the moral of this story is I just can't read.

Anyway, I got home from Santa Monica last night, and the goods had finally turned up, so I had a play. The DS18B20 just looks like a transistor. I initially ignored it, and just shoved the USB board in caesar, and it happily recognised it

usb 1-1: new full speed USB device using uhci_hcd and address 8
usb 1-1: configuration #1 chosen from 1 choice
drivers/usb/serial/usb-serial.c: USB Serial support registered for FTDI USB Serial Device
ftdi_sio 1-1:1.0: FTDI USB Serial Device converter detected
drivers/usb/serial/ftdi_sio.c: Detected FT232BM
usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0
usbcore: registered new driver ftdi_sio
drivers/usb/serial/ftdi_sio.c: v1.4.3:USB FTDI Serial Converters Driver

I then fooled around with minicom, and discovered that the little transistor thing I'd been ignoring was indeed the temperature sensor, as I got a reading of zero back (when using this program I found on the 'net).

So I went to bed, and this morning did a bit of messing around with the sensor, and with a bit of creative bending, I've got it sitting in the S1 holes without requiring any soldering. It tells me the linen cupboard is about 44 degrees Celsius. Warm, but I don't think it's in any immediate danger of bursting into flames. Wouldn't surprise me if some of the gear in there isn't too keen about the temperature though. At least we won't have to worry about mold.

Next step is to convince cacti to graph it, and nagios to monitor it, and we're in business.

Here's a little Python program I knocked up to grab the temperature. pyserial is nice.

try:
  import serial
except ImportError:
  print "This program requires pyserial,", \
    "try checking the python-serial package is installed"

from optparse import OptionParser

SENSOR_QUERY_CMD = (None, 'S', 'T', 'U')
USAGE = "usage: %prog [options] [action]"

parser = OptionParser(USAGE)
parser.add_option("-F",
"--fahrenheit",
action="store_false", 
  dest="use_celsius",
  help="Output temperature in degrees Fahrenheit", 
  default=False)
parser.add_option("-C",
"--celsius",
action="store_true", 
  dest="use_celsius",
  help="Output temperature in degrees Celsius", 
  default=True)
parser.add_option("-d",
"--device",
action="store",
type="string",
  dest="device",
  help="device to communicate with", 
  default="/dev/ttyUSB0")
parser.add_option("-s",
"--sensor",
action="store",
type="int",
  dest="sensor",
  help="sensor to query",
  default="1")
parser.add_option("--mrtg", action="store_true",
  dest="output_mrtg",
  help="Output decimal value suitable for MRTG",
  default=False)
(options, args) = parser.parse_args()

if not(options.sensor > 0 and options.sensor <= len(SENSOR_QUERY_CMD) - 1):
  parser.error("Invalid sensor")

ser = serial.Serial(options.device, 9600, timeout=1)

ser.write(SENSOR_QUERY_CMD[options.sensor])
buf = ser.read(8)

temp = ord(buf[0]) | (ord(buf[1]) << 8)

degrees = temp / 16.0

if (options.use_celsius):
  if (options.output_mrtg):
    print "%.0f" % degrees
  else:
    print "%.4f degrees Celsius" % degrees
else:
  degrees = (9.0/5.0) * degrees + 32.0
  if (options.output_mrtg):
    print "%.0f" % degrees
  else:
    print "%.4f degrees Fahrenheit" % degrees

Update

The most up to date version of my script can be found in my Subversion repository.

[23:12] [tech] [permalink]