temper_device

Temperature measuring using Linux and Raspberry Pi

Temperature measuring using Linux and Raspberry Pi 3.50/5 (70.00%) 6 votes

The story

I have a small server room, with some rack servers, NAS’s, VMware ESXi’s and other fun stuff, but I had one problems.. in the summer it got really hot, and I had to open the window to let fresh air in, and the old out to lower the temperature again, but I never knew when it was too hot, so i had to drive by the server room once or twice a day to manually feel if it was too hot..

This was a problem, because sometimes I was not home, or sometimes I forgot, or just had no time to drive by to check the temp.
Having a temperature sensor in the room, from a freezer or something like that didn’t help me much, since I still had to drive by to check it manually.

So I had to make something I was able to get the room temperature from, over the internet/lan, and thats when I decided to make my network thermometer.

I looked for weeks on the internet for a good guide about this, but none of them worked. so I decided to write my own to help others with the same problem out.

This post will be about

How to make your own network thermometer, using open source software and a cheap USB temperature sensor!

What you will need

  • A raspberry Pi, or other small Linux computer that uses a small amount of power (this can be a laptop or normal computer too)
  • network cable to connect the Raspberry, laptop or computer to the network, the link is a 5 meter which is enough in most cases, there are other length on the same page if you need more.
  • USB temperature sensor, I used a “TEMPer v1.4

If you are planning on using a Raspberry Pi for the project, you will need these additional items:

How to put it all together

I will be making it using a Raspberry PI in this guide, but it should work with a normal computer or laptop too.

I use Raspbian on it, which is Debian Linux optimized for speed on the Raspberry Pi.

Step 1 – Install the OS on your raspberry

To install Raspian on your raspberry you have to do the following. (If you already have a running Raspberry, then you can skip to step 2):

  • Download the zip file containing the dd image from Raspberrypi.org (A little under 500MB)
  • Extract the zip file to your hard drive, giving you the dd image “2013-07-26-wheezy-raspbian.img”
  • Write this image to the target SD card.
    Linux

    1. Replacing sdX with the location of the SD card, run: dd bs=1M if=/path/to/2013-07-26-wheezy-raspbian.img of=/dev/sdX

    Windows

    1. Download and install Win32DiskImager
    2. Select the 2013-07-26-wheezy-raspbian.img image file, select your SD card drive letter, and click Write
  • Eject the card from your computer, insert into the Raspberry Pi, and power it on.
  • If your keyboard, mouse, or other USB device doesn’t appear to be working properly, try using it through a POWERED USB hub. The Raspberry Pi’s USB ports are limited to 140mA. This limitation has been fixed in newer boards; however, you may still run into power issues.
  • The default username is ‘pi’ with a password ‘raspberry’

Once you started up the device and is logged in, you will notice that there are no desktop. It’s all console based.
This entire guide will be done in the console only, and you should already know how to write commands and navigate around in the console to make this a lot more easy.

Step 2 – Install dependencies

When you have booted your Raspberry up, and it’s running you can change the password and other stuff you like, but I am going to skip this part for now and do it later. You can find guides to all the things like changing the keyboard layout, changing the timezone or language if you just google it. Maybe I will make small guides for each and every one, but for now I will skip it since it does not matter in this guide or device.

Now you need to install some dependencies that is needed to make the temperature reading software run.
Since i use Raspbian in this guide, the program used to install software from the repositories is called “apt-get”. Run the following command to install all the needed software (they are space seperated):

apt-get install libusb-dev libusb-1.0-0-dev

And press yes to everything it asks.

When done, you have to set some system variables, running the two following commands:

export LIBUSB_LIBDIR=/usr/lib/arm-linux-gnueabihf
export LIBUSB_INCDIR=/usr/include/libusb-1.0

Step 3 – compile the program and get the temperature

You now have to download, compile and try out the software you have to use for reading the temperature of your TEMPer device. follow the step below.

  1. Download the zip from here: temperv14
    This can be done using the following command on you Raspberry:

    wget http://dev-random.net/wp-content/uploads/2013/08/temperv14.zip
  2. Extract the zip file on your Raspberry, to do this you first have to install the Unzip program on your Raspberry using the following command
    apt-get install unzip

    When installed, you can unzip the archive using the following command

    unzip temperv14.zip
  3. Change directory to the new unzipped folder using the command
    cd temperv14/
  4. Now compile the program using the following command:
    make

    It should output something like what you see in the picture below
    temper_make

  5. Test the newly compiled program using this command
    ./temperv14

    If you have your TEMPer device connected, it should output a timestamp and a temperature, if not it will output an error that the device was not found.

  6. Move the newly compiled program to a special directory so that can be accessed from everywhere in your system using the command
    mv temperv14 /usr/bin/

    Now if your type “temperv14″ anywhere in your system, it will run the program and output the temperature!

If you want to output only the temperature in Celsius (handy for implementing this in programs or monitoring systems like Nagios), you can run the command

temperv14 -c

Or for the temperature in Fahrenheit only

temperv14 -f

Step 4 – Manually adjust the thermometer

Some TEMPer devices show the temperature a little off, like mine for example, it show 6 degrees Celsius too much, every single time!! This was an issue for me since it was not the correct temperature I got from the device.
I was just about to send it back, but then I decided I did not want to wait the 2-3 weeks for a new to arrive, so I just made the program subtract 6 degrees every time before outputting the temperature.

I made a static variable in the code of the program that you can change. so you should do the following

  1. Find a manual temperature sensor, like from a fridge, and put it in the same room, right besides the TEMPer device, leave it there for an hour until it shows the correct temperature.
  2. Run the command, and note how many degrees the output is at.
  3. Compare it to the degrees on the manual thermometer.
  4. If it’s more, then do the following
    1. Edit the file temperv14.c with Nano or Vi
    2. Change line number 80 from “static int substract = 0″ to the number of degrees in CELSIUS the TEMPer device is showing too much.
    3. Save it, and repeat step 2 starting from substep number 4 (Where you run “make”)

Done, that’s it.. you now are able to monitor your temperature remote using SSH, or by implementing this to Nagios or other Monitoring software just by running the command “temperv14″ on the device.

You should know, that I had problems with my TEMPer device, when I did not attach it to a powered USB hub. when attached directly to the Raspberry it got hot, and showed way too much when running the command. so I recommend attaching it to a powered USB hub that is attached to the Raspberry’s USB ports if this happens to you as well, it fixed the heating issue for me.

temper_setup_final

Share this:FacebookGoogle+TwitterReddit

20 thoughts on “Temperature measuring using Linux and Raspberry Pi

    1. Norman

      You should be able to use a USB extension cable instead of a powered hub. Much less expensive.

      Reply
      1. Steffan Post author

        I don’t think you have read the entire page..
        i use a powered USB hub because the Raspberry can’t deliver enough power to the TEMPer device, it somehow gets really hot if you plug it directly into the raspberry. so a USB extension cable here would just make things worse.
        If you are using a normal computer, with lots of power in the usb port however, then yes. you can get the TEMPer device further away from the computer itself place it somewhere you can’t put the computer using an USB extension cable.

        Reply
        1. Norman

          I did read the entire page. Consider editing it so this point is clear.

          From the article, it can be construed that the problem was heat from the Pi causes temperature readings to be high due to proximity. Now it seems you’re saying the main problem is the Pi overheats due to power drawn by the device. For the former case an extension cable would be a solution. For the latter, a powered hub is required.

          By the way, how much power does the TEMPer pull? That information is listed in the device’s USB descriptors. You can get it using the “lsusb -v” command.

          Reply
          1. Steffan Post author

            Nope. I think you have totally misunderstood what i mean.

            The TEMPer device itself get’s hot if connected to the pi directly. The pi keeps its temperature as it should.
            I tried unplugging the TEMPer device multiple times but every time i plugged it into the pi directly it (the TEMPer device) turned hot.
            As soon as i plugged it into a powered USB hub, the TEMPer device did not get hot.
            I’m sure if you plug it into a normal computer, and not a pi. It won’t get hot and the usb hub will not be needed.

        2. Shawn

          Perhaps, when the TEMPer is connected directly to the RaspPi, it gets hot because the TEMPer is acting as heat-sink for the RaspPi. If so, a long USB extension would solve the problem.

          What is the amperage rating of your power supply? If you’re using a 1.0 or 1.5 amp power supply, the RaspPi should easily be able to power the TEMPer since 500 mA is the maximum for any bus powered device.

          Reply
  1. George

    Hey!
    Thanks a lot!
    I am using Debian Squeeze on the RSPI but weren’t able to get the program to work.

    #~/temperv14 $ ./temperv14
    Could not set configuration 1

    I also checked using
    # lsusb

    and it seems like the pi found my TEMPer (Bus 001 Device 005: ID 0c45:7401 Microdia ).

    I’m quite new to Linux and Raspberry Pi, so I might have overseen something.

    Thanks for helping!

    Reply
    1. Steffan Post author

      Hello, sorry for the late reply, was at work.

      If you get the configuration error that you pasted in your comment, it it because you don’t have enough rights to read/write to the Temper device.
      Run the program as root, and everything should work perfectly.
      In Debian, you can do this by typing:

      sudo ./temperv14

      and then your password.

      Reply
        1. crg

          Worked perfectly on raspbian.

          To fix the permissions problem (so everyone can read temps off the USB) you need to:

          $ lsusb | grep -i Microdia
          Bus 001 Device 010: ID 0c45:7401 Microdia
          $ chmod a+rw /dev/bus/usb/001/010

          Reply
          1. David

            Hello all,
            I am running into a similar problem. I noticed that after I run the program 15 times, it throws the same “Could not set configuration 1″ error because the device number increments by one. I have to fix the permissions each time. Any thoughts/suggestions?

            I am trying to write a script to poll the device for temp regularly, so this is an annoying problem. If it helps, I am prototyping in Ubuntu for an eventual pi device.

            Thanks for the handy program and instructions.

          2. Steffan Post author

            Are you running your script as root ?
            I do, and have no problems with “configuration 1″ error, I have only seen those appear if you do not have enough permissions

  2. Tom Stephenson

    Thanks so much for your excellent instruction. I bought one of these TEMPer devices to see if I could use it at work for thermal monitoring in a room full of hardware. I have 60 chassis running in a unattended room with 4 servers controlling hardware testing in each of the chassis. I wish to monitor thermals in each of the chassis. I think I can do that very well to detect failing fans etc in any of the chassis.

    The instructions you provided were professional quality. Very well done.

    Thanks,
    Tom Stephenson

    Reply
  3. Lauri

    Thanks a LOT for great instructions. Got this working on my debian server in no time :)

    Can’t wait to graph with RRD!

    Reply
  4. Pingback: Temperature measuring using Linux and Raspberry...

  5. Holger Ernst

    #! /bin/bash

    # alarm temp (Centigrade, no decimal)
    threshold=25

    # email addresses to send alerts to:
    alert=”reporting@someone.com another@someone.com
    mailheader=”Temperature alert on `hostname`!”

    # logfile
    log=”/var/log/temp.log”

    # Here we go:

    # Get the full reading
    # On my test system sometimes i get an error:
    # “Resource temporarily unavailable”
    # So i check and try again
    OK=”no”
    while [ ! "$OK" = "yes" ]
    do
    result=`./temperv14` && OK=”yes”
    done
    echo $result >> $log

    # Just the temperature reading
    OK=”no”
    while [ ! "$OK" = "yes" ]
    do
    temp=`./temperv14 -c` && OK=”yes”
    done

    # change temp to type integer
    i=`echo “($temp)/1″ | bc`

    # Test and send emails
    if [ $i -gt $threshold ]; then
    for dest in $alert
    do
    # Make sure your mail agent is working propperly.
    echo $result | mail -s “$mailheader” $dest
    done
    fi

    Reply
  6. chris

    First of all: thank you for coding :-)

    I ran this on Debian Wheezy 64bit with kernel 3.10 and get _one_ measurement right
    and any subsequent ones fail (at least until the device is re-plugged):


    USB interrupt read: Resource temporarily unavailable
    Fatal error> USB read failed

    any idea?

    Reply
    1. Steffan Post author

      I have never seen that error before..
      It might be your Temper device that’s broken.
      I run mine of a raspberry pi with Rasbian using kernel 3.10.25
      If I was your, I would try on another install of Debian, maybe an older version just because you can.

      Reply
  7. Keith

    Followed your instructions and it worked. I seem to get some errors from the program every once in a while, so I am tracking that down.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>