House Temperatures Project

Why?

This project was done so that I could keep a log of the temperature outside, inside, and in my attic. Why would I want to do this? Read below for details. Using the banner to the right, you can also compare my outside temperatures to those at Clover Field in Friendswood.

Here is a look at the current temperatures:

Fri Jun 1 07:09:36 2007

Location Temp Trend 12 hour Record
High Low High Low
Outside 72.28 °F 0.62 °F/hr 78.13 72.16 98.82 - Jul 06, 2005 30.54 - Dec 26, 2004
Computer Room 74.64 °F 1.21 °F/hr 74.64 73.85 87.13 - Sep 26, 2005 55.96 - Dec 26, 2006


Temperature charts offline



Problem

I did this project so that I could get a data log of the temperature outside, inside my house, and in my attic. Why would I want to do this? Well, my attic needs some ventilation.

But how would I know that installing ventilation would do any good?

I decided it would be fun and interesting to set up some sensors so that I could first see the temperature of the attic in relation to the outside temperature, and then see how this relationship changes after I install my attic ventilation. That was the catalyst for this project. I would like to expand it later to include more rooms and possibly use it in a control loop to control temperatures throughout the house.


Design

My first goal in the design was to avoid having to run wires in the attic and in the walls. I already have a 802.11b wireless network in my house, so I was hoping to find some 802.11b temperature sensors that I could install and get data from directly using TCP/IP. Well, no luck. I looked for other types of wireless sensors as well but never found anything at a reasonable price that a hobbyist would be interested in.

So, basically, I completely failed to achieve my first goal. I was going to be running cable. If you are reading this and you know of something that is wireless and does not cost a fortune, please email me and let me know about it.

Down to wired sensors, I did find Dallas Semiconductor's line of "1-wire" devices. I found this site which sells kits (DT1A) to build a sensor board including RJ-45 connectors and nice circuit-board for $9. Also, to talk to these devices, you need a serial adapter. I opted to go with the Link45 since it would work with an RJ-45 connector, and also because it has a chip inside which makes it smarter allowing it to return more accurate readings.

Another driver in my seletion of sensor and adapter was that I was planning to use this software. It is called Digitemp and it was written by Brian Lane. It is a really neat piece of software and I appreciate him making it free for download and for donating his time. It is being used all over the world for temperature sensing. I often look at this site as an example for a cool way of displaying the temperature data over the web. They are also using Brian's Digitemp software.


Implementation

Construction

I received my sensors in the mail and soldered the parts together. They came with a very good instruction sheet and building them was extremely easy. If you don't have any soldering experience, however, you may want to opt for the assembled version and pay an extra few dollars per sensor.

Here is an image of one of the completed sensors:

Sensor


Installation

After building the sensors, it was time to run the cable. I decided I was going to run CAT-5e cable. That way, at least the left-over cable would be useful to me in the future for home networking.

Needless to say, I got up in my hot attic, and ran the cable. I didn't take any pictures of this, but there was nothing special about it. I ran down the wall next to my computer. From there, I ran up to the 2nd floor attic, and then looped around and ran over the first floor attic to my outside patio for my outdoor temperature sensor. Here are some pics of the final placement of the sensors:

Outside Sensor

Attic Sensor


Next, I added a wall jack on the wall next to my computer just to clean it up a bit.

Wall Jack


Software

My first idea was to plug in the serial adapter to my linux box, and run Brian's Digitemp software in Linux (which is what it was developed for). However, I had problems. For some reason, I kept getting the error "Error locking ttyS2. Do you have permission to write to /var/lock?". Yes! I do have permission!

I wrote Brian and he responded quickly suggesting that I use the utility "minicom" in Linux to test communication with the adapter. He also pointed out that I should be using ttyS0 instead of ttyS2, but I had tried that already. For minicom, he said, "If you set it up for 9600bps and send it a space it should return the version number of the Link45, and if you send it a 'f' it should list all the attached devices if you then type 'n' to get the next device."

Well, in the meantime, I tried running his Windows version of the software and that seemed to work beautifully. I could see all of my sensors and all of them were reporting accutate data. I decided that I would just set up one of my Windows machines to do the temperature logging instead. But, this came at a price - all of the free utilities and programs out there for digitemp that allow you to log data to a database, and graph data on a website dynamically, etc., are all Linux utilites. This meant I was going to have to do some development myself.

So, I've got the windows version of Digitemp extracted into "C:\digitemp". Running digitemp alone reports all of the temperatures directly. How would I log my data? I looked through the digitemp documentation and found that it has built in support for cyclically logging data, but it seemed to suggest that I had to enter a maximum number of samples to take (which I did not want to do - I want to record indefinitely).

It was time to whip out the Perl scripts! I wrote one that does two things: First, it calls the digitemp.exe file and passes the appropriate switches to tell it to append the data to the log file "temp_log.txt". I also set it up so that it does not pop up the annoying DOS console window when digitemp.exe runs. I did this because I plan on scheduling the job and I did not want an annoying black box constantly popping up. Next, it grabs the last temperature reading for each temperature sensor (at the bottom of the log file) and writes out a file in my webserver directory to show the current temperatures. You can see the results of that file at the top of this page. The file is called "temperatures.inc" and I simply include it in my .asp page to show the current temperatures (rather than setting the page to ping the sensors directly and potentially conflict with the data recording job). This Perl script is not really in a state to be distributed since the number of sensors and filenames are all hardcoded in, but feel free to download it here. It shouldn't be hard to update it to do whatever you want.

Update!!! After adding to my excel spreadsheet and having it automatically update the chart and export the chart to a graphic file, I added to this perl script to call Excel and have it update the graph used on the website. This gives me the dynamic graphing ability I was hoping for!! Download the updated perl script here.

Update 6/17/04!!! I updated the perl script to calculate the trend based off of the last 3 data points. However, unlike everything else in there, this is configurable to average the trends over as many data points as you like. Since my data points are nominally at 10 minutes apart, I think 3 data points (2 deltas) is just fine. Download the updated perl script here.

Update 7/08/04!!! I updated the perl scripts yet again. This time, I added the 24 hour high/low and record high/low tracking. Download the updated perl script here.

Update 2/15/05!!! OK... don't download any of that other stuff. I've completely rewritten the perl script and the excel spreadsheet macro. Download them both here.

Next, I added a scheduled task to Windows. After some playing, I finally got this to work with my perl script and not pop up annoying DOS console windows (Note to Micro$oft - you need a checkbox for this!). Here is the command I used (without the quotes): "C:\Perl\bin\wperl.exe c:\digitemp\house_temps.pl". Using wperl.exe instead of perl.exe is the important factor in keeping the console window from popping up. I scheduled this job to run every 10 minutes, every day, with no stop date. This will log my temperatures and update the live temperatures on my website every 10 minutes.

Finally, I wanted to visualize my data. Ultimately, I would like to have dynamic graphs on the webpage. But, all of the great, free utilities out there for doing this are all PHP/Apache/mySQL/Linux oriented. There are a couple of free ones out there that will do dynamic line graphs (not bar charts) and work in ASP such as this one and this one, but nothing really jumped out at me as being easy to use and good-looking. For the time being, I set up an Excel spreadsheet with some macros in it. These macros get tied into one button on the front page. Hitting this button causes Excel to automatically go to c:\digitemp\temp_log.txt, import the data, split the data up for three sensors, and update the graph to show the newest data. Again, these macros are hardcoded for filenames, number of sensors, etc., but it shouldn't be hard to modify to do whatever you want. You can download the file here.

Update!!! I changed the Excel spreadsheet to also perform the update function as soon as it is opened. Now, all I need to do is set up the Perl script to automatically open Excel, open the spreadsheet, close the spreadsheet, and close Excel (see above). With the help of this website, this was easy! Download the updated excel spreadsheet here.

Update 6/16/04!!! I changed the Excel spreadsheet once again to now create 3 charts as you see above - past 24hours, past week, and past month. Download the excel spreadsheet with these changes here.

Update 2/15/05!!! As mentioned above, I've completely rewritten this stuff. Download the new perl script and spreadsheet here.

Update 2/26/05!!! I created a perl script that uses the Win32::GUI extension. This perl script creates an icon in my systray. Whenever I put my mouse over it, it shows me the last temperatures that I read. All it is really doing is reading a file every few minutes that contains the raw temperatures and updating the popup text. Here's a screenshot:

Tray Temp script

I got the idea from this page that a buddy of mine at work gave me. I changed it up so that it doesn't require any perk/tk extension though. The script is pretty simple, but it could be used to show data in any file, so it might be useful for other things. I originally intended it to read data from the environment variables to display, but I later found out that you cannot set a system wide environment variable in a process - each process is given its own copy of variables. So, setting your own variable which gets destroyed when the process ends, doesn't help. If you want to download the script to read a file and display it in the system tray, you can download it here.

Last Modified: 10.14.07    Valid XHTML 1.0!    Valid CSS! Powered by Blogger