Been wanting to do this one since I got my first Pi!
In my old (now old-old-) job, I worked a lot with temperature monitoring (and various other metrics), which I loved because I'm a giant nerd and I love data! I've written a few posts about various logging projects that I've half-baked with Arduinos, but really wanted to take a step up with the Raspberry Pi.
I bought a USB temperature probe on eBay for about £8 (~$12). The software with it is a bit rubbish and I wanted to integrate it into something bigger. Finally I found a script which works in Linux, which made it perfect to attach to a Raspberry Pi!
The finished product is fully self-contained, featuring its own Web interface with purdy graphs. It's currently hooked up to a home beer making kit in my cupboard :)
Temperatures are really high in the graph above because I hooked the probe up to the central heating pipes
Installation - It's all packaged into a nice shell script so the intricate bits are all taken care of
NB: all of this can be done from the console - if you're like me, none of your Raspberry Pi projects will have screens attached so you should get comfortable with using the console instead of the graphical interface. This means you save on a lot of resources (processing power!!!) and you can remotely access the RPi over SSH. Anyhoo, on to the real stuff...
Start your RPi
If you're working from a fresh install of Raspbian: (if you've already done this, then skip to #3)
Start raspi-config (it may auto-start, if not type "sudo raspi-config" without quotes, then hit enter)
Note: You're going to get two identical graphs at the start - the left hand on displays the last 60 minutes, the right hand one displays the last 8 hours
Note 2: The web page is optimised for mobile phone viewing ;)
How does it work?
pcsensor.c / pcsensor
Someone (first link at the bottom) has very kindly written a small C program which simply reads the current temperature and outputs it to the console. I has to modify it slightly so that when you call it with an argument ("pcsensor -c"), it only outputs the temperature.
Now that we have a way to read the data, it's simply a case of sending this data to a database table every so often (I chose every 1 minute). The log_pcsensor.sh file is a shell script which takes the output from the pcsensor script and inserts a new record into the database every time the script is called
cron is a Linux background service which executes scripts according to a schedule. I just added a job to cron to call the log_pcsensor.sh script every 1 minute
temps.php and tempgraph.php
temps.php - Data isn't awesome unless we can read and interpret it! I started off with a very simple php page which displayed the latest temperature, and a table with the previous 25 readings. It was cool, but not cool enough!
tempgraph.php - Then I thought, "Why can't I graph it?" So I researched some graphing packages for PHP, found one I liked (JpGraph), and created a page which will read the database and display a graph of the data.
Finally, I knew I was going to have to blog about this (I feel better as a person when I see my page views go up!) so I decided to make it easy for people to install. It's probably not the most educational way to present the project (the RPi is, after all, an educational tool), but I prefer to learn by example rather than blindly follow a list of instructions.