A few months ago i installed a home server from an old laptop, with an external hard-drive hooked up to it. I use it as a remote desktop, and I run Ubuntu 11.04 Server virtually with Virtualbox.
These are situated in a small closet in my living room.
I googled around a bit for solutions, and I found this http://www.dealextreme.com/p/usb-digital-thermometer-dongle-software-displays-temperature-7003
So I thought, $8.8, free shipping, what the hell, I’m ordering it.
After about a month the TEMPer landed in my mailbox, and I figured I would get started right away. So I plugged it into my “server” laptop, and logged on the remote desktop.
My plan was to have it run on my virtual linux server, and in one way or the other spit output to my webserver for viewing on the web. Even though that was my plan, on the cd that came with the USB dongle, there was only windows software, so I decided to try it on windows first. I installed the software, tried to run it, but no luck. Noting happened. When i opened taskmanager though, the process was running.
I plugged it into my regular laptop, tried the software, and it worked. But having it work on my regular laptop was of no use, so i plugged it back into the “server” laptop again. I figured I might just was well just go straight for my linux challenge. Here, as always, google was my friend. I found this website, http://relavak.wordpress.com/2009/10/17/temper-temperature-sensor-linux-driver/, with a linux driver for my TEMPer unit. I downloaded it, unzipped the package and tried to run ./temper.
This gave me the output
error: Inappropriate ioctl for device
I figured this might mean something of the sort of wrong vendor/product id for the USB. I opened the code (temper.c) in pico, and saw the vendor/product id being defined pretty much at the top of the code.
With lsusb I got the proper vendor/product id for my device, and indeed, it was different from the one in the original source code. So I changed this and compiled.
By the way, Opensource is awesome.
Now, after compilation I got another error
TemperGetTemperatureInC: Broken pipe
This time I took a deeper look into the code before compilation. After reading a few functions it seems this code might be for a slightly different device, with a humidity sensor. Since my device doesn’t have that, that might be the reason for the error. I read through the comments once again, and found this link: http://www.isp-sl.com/pcsensor-0.0.1.tgz
So once again I downloaded, and tried to run the program. Same error as before. I had to change the vendor/product id here as-well, and compile again.
That did the trick, suddenly my terminal got filled with temperature readings!
So now at least it was working. My next challenge was to get this displayed on the web. I figured I could modify the code to output to a MySQL database as-well as to the screen.
So I added a few lines of code to the original one, witch is now running, outputting to screen and database ever 60 sec. Now, I can output it into tables/charts/whatever on the web.
You can download the sourcecode here: pcsensor
To compile you need to link to the mysql library, with something like: (This line was updated 12.06.2012 because newer versions of GCC require the linker flags to be placed after the objects to be linked)
gcc pcsensor.c -lmysqlclient -lusb
To make this program output to mysql, you have to run it with the -c flag for celsius, just because I’m lazy and will just make it work for me. You also have to change the host/username/password/database on line 395 of the program to correspond with your database settings.