Temperature measuring using Linux and Raspberry Pi

Temperature measuring using Linux and Raspberry Pi 3.75/5 (75.00%) 4 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.

    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


    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:

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

  5. Test the newly compiled program using this command

    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.


Share this:FacebookGoogle+TwitterReddit

7 thoughts on “Temperature measuring using Linux and Raspberry Pi

  1. George

    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!

    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.

        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

  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.

    Tom Stephenson


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>