Temperature measuring using Linux and Raspberry Pi

Temperature measuring using Linux and Raspberry Pi 3.38/5 (67.69%) 13 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

38 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.

      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.

        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.

          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.

    2. John Halford

      For some time I have had a TEMPer1 unit for some time to play with on my windows notebook.
      I works well there on their latest software I downloaded.
      I have one with a sensor on the end of a lead plugged into a powered USB hub.
      Getting my Raspberry Pi B up and running I thought I would give it a go there

      I am running Raspian from the latest version of NOOBS. I am also running SSH from my Notebook as I am able to cut and paste from the web page into the SSH window (I discovered right click pastes the instruction).

      Following the instructions at http://dev-random.net/temperature-measuring-using-linux-and-raspberry-pi/
      Some instructions seemed not to have permission so I prefixed them with sudo if they failed at first but I tried to muddle through.

      I now get
      pi@raspberrypi ~/temperv14 $ temperv14
      Could not set configuration 1
      or 2.
      pi@raspberrypi ~/temperv14 $ temperv14
      Couldn’t find the USB device, Exiting
      [I am mildly confused as the hub has on/off switches that do not seem to always work the same way, 1 with the switch seemingly off and 2 for the switch seemingly on]

      It may be because I have the early version of the hardware – any suggestions

      1. Steffan Post author

        You need to run all commands as root (or with sudo in front) including the “./temperv14″ because you need more privileges than the “pi” user has to read from the usb device.
        There might be some permission tweaks you could make to allow the pi user to read from the device, but i never needed it since i just run it with sudo (in /etc/sudoers you can specify a command that pi can run with sudo without having to type the password)

  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

          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.

    Tom Stephenson

  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!

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

  5. Holger Ernst

    #! /bin/bash

    # alarm temp (Centigrade, no decimal)

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

    # logfile

    # 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
    while [ ! "$OK" = "yes" ]
    result=`./temperv14` && OK=”yes”
    echo $result >> $log

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

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

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

  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?

    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.

        1. Chris R.

          This may or may not be helpful to anyone, but I came up with a script to use the two scripts (because scripts like scripts) for those of you having issues with
          USB interrupt read: Resource temporarily unavailable
          Fatal error> USB read failed

          This script assumes that you have the temperv14 and the usbreset binary (from the above comment and link) in /usr/bin.


          DEVICE=$(echo /dev/bus/usb/`lsusb | grep -i Microdia |sed -e 's/\//g' -e 's/\//g' -e 's/\:.*$//'| awk '{$1 = sprintf("%03d", $1); print}'` | tr " " "/")

          /usr/bin/temperv14 #add whatever options you want such as -c

          /usr/bin/usbreset $DEVICE

          This script will parse the output from lsusb into the format that the usbreset binary wants (/dev/bus/usb/XXX/XXX). I have tested this on a server running Debian Jessie and it works just fine. I wouldn’t suggest it for use in a script that is called often (more than once every minute) because of the constant resetting of the usb device.

          To the author: It would seem that for some reason the usb_release_interface call is not working on full-version Debian (read: those of us using this with a full Debian install as opposed to Raspbian) systems for some (myself included). I think it comes from the fact that the function usb_detach_kernel_driver_np has no usb_attach_kernel_driver_np, unless you get a patched version of libusb that has it. That might be the issue.

  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.

  8. George

    When I connect the USB device it always works perfectly the first time. However, the second time I run the script I get:

    $ sudo ./temperv14 -c
    Fatal error> USB read failed

    Do you know what the problem might be?

  9. Lauri

    I’m getting weird values when temperature is below 0 celsius.

    Something like this:

    2014/10/16 20:48:13 Temperature 491.00F 255.00C

    Any idea why it behaves like this?

  10. Manuele

    [15127.934352] usb 1-1.3: Product: TEMPerV1.4
    [15127.934363] usb 1-1.3: Manufacturer: RDing
    [15127.947134] input: RDing TEMPerV1.4 as /devices/platform/bcm2708_usb/usb1/1-1
    [15127.948890] hid-generic 0003:0C45:7401.0003: input,hidraw0: USB HID v1.10 Key
    board [RDing TEMPerV1.4] on usb-bcm2708_usb-1.3/input0
    [15127.963058] hid-generic 0003:0C45:7401.0004: hiddev0,hidraw1: USB HID v1.10 D
    evice [RDing TEMPerV1.4] on usb-bcm2708_usb-1.3/input1

    xbian@xbian ~/temperv14 $ make
    cc -DUNIT_TEST -o temperv14 temperv14.c -lusb
    make: cc: Command not found
    make: *** [temperv14] Error 127

    Any ideas??

  11. Andy Ormsby

    Worked perfectly, just as described. I went from powering up the Raspberry Pi to having this working in about 5 minutes. Thanks!

  12. Mattijs Vantorre


    It works perfect. I want to get the result of the command ‘temperv14 -c’ in a variabele throught a script. Sombody how can help me.


    1. Steffan Post author

      Bash? VAR=`temperv14 -c` or VAR=$(temperv14 -c)
      $VAR will then contain the returned temperature

      php? exec(“temperv15 -c”, $output, $returnvar);
      $output will then contain the returned temperature

  13. Derek

    Hi, just curious as to why you didn’t plug the USB extender/hub into your server and serve the temperature from one of those machines instead of adding a Pi to the mix.

    1. Steffan Post author

      Because I am one of those who likes to have a separate server for each service. Example, a webserserver is for serving webpages, not hosting the sql too, that’s what the sql server does.
      and because a raspberry is easy to move around. Also my other servers are running ESXi or freenas, which is a bitch to install stuff on, don’t really want to bother with it (hard to do an upgrade in the future if i do system changes on those)

  14. Dick Quaif

    Very nice code. Thanks.

    I solved the rights problem by having temperv14 run as root and allow anyone to run it. That seemed the simplest solution.
    sudo chown root temperv14
    sudo chmod +s temperv14

    On the Raspberry PI 2, you can set the max USB current up to 1.2 amps by adding max_usb_current=1 to the Config.txt file in /boot. (Provided your power supply will handle it.
    It have no trouble with the TEMPer I have when connected to the PI 2.

    I suspect it is a voltage problem you are having and not a current problem. The older Raspberry PI B I have, has a rather low VBus. I boosted the power supply a bit to 5.2 Volts to compensate. That makes other things work better although I have not tried the TEMPer on it.

    Keep up the good work and thanks.

  15. Jussi

    Thanks for tips, it was very easy to get it up and running! My sensor was accurate so adjusting was not necessary.

    However, I was able to find one bug. I’m not sure if it’s temperv14 program or sensor itself, but below-zero temperatures are reported as values starting from 256 C. E.g. 0 C is 256 C, -1 C is 255 C etc. I know most of you don’t care about this, but I purchased this sensor to make sure I don’t run my Raspberry with batteries in temperatures below -20 C as this is considered dangerous (my raspbi is located in a car and we are used to quite cold winters).

    Fortunately it is easy to calculate correct figures as I don’t expect over 150 C temperatures, but I just wanted to let you know. :)


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>