Homebrew Temperature Sensing with 1-wire

I wanted a way to graph the temperatures of my home brew and throw alarms at me if it goes out of the bounds. I know that’s not RDWHAHB, but I figured it’d be a fun project anyway.

So I settled on 1-wire as my sensing network. The beauty of 1-wire networks is their simplicity. Each device on the network has a unique ID. Then all you need is a ground and a data line. Since the temp sensor I used can work off parasitic power, I don’t need a third voltage line. So the software just does a query for the temps of all sensors and they start spitting out their unique id and the value. Pretty awesome.

I grabbed a couple of Dallas DS18S20 IC temp sensors and a Dallas DS9490R USB adapter. The adapter takes in RJ11 (really only two wires) and converts it to USB. The usb adapter is plugged into an old laptop running Ubuntu 11.10 and digitemp. On top of digitemp I have another software package called dtgraph making it oh so very pretty.  More about how all these work and how to set up later. But first a few pictures!

Here is what the graphing system looks like. I have mine to log every 15 min. Below we’re seeing 13 hours with all three sensors. Notice that you can see when the fridge turns on and off. Nice!

Here I’ve set it to view 28 days. Again this logging every 15min and you can see that it captured 2,565 temperatures. It’s only showing 726 of them to save on render time. You can make it show all if you check the Repeats and All Data. Renders pretty fast on my 10 year old laptop.

Here’s the size of the mysql database after logging every 15 min for 29 days.

So really not too bad.

Here’s what the DS9490R 1-wire to USB adapter looks like plugged into my laptop

I have the beige RJ45 cable coming out of the DS9490R going into a 5 RJ11 breakout box as shown below.

All three cables have DS18S20 sensors at their ends. The grey cable is a telephone cable I hacked up and the blue ones are standard cat5 cables that I crimped a RJ11 onto the end. All you really need are two cables — data and ground. If you’re running really long cables you might need a voltage line, but if it’s less than 30-40ft you should be good.

Enough talk here’s the sensor taped onto my carboy. Got a American Pale Ale on the way!

And here’s one going into my refrigerator. I stripped back the insulation and extra wires to make the cable smaller. It seals pretty well like this as the cables are fairly small. One day I’ll drill a hole and caulk. Right now it’s taped up with electrical tape. We shall see how well that handles the cold.

Also note that there are 4 wires gong in, but I’m actually only using 2. The white ones just keep the sensor hooked onto the tray, and consequently centered in the middle of the fridge.

Here’s the outside sensor. I was able to slip it under the window sill and shut and lock the window. Make sure you put it in the shade or it might tell you it’s 138F outside. 😉 This part of the house stays shaded all day.

I wrapped it in a small plastic ziplock and then sealed up the end of the ziplock with more electrical tape. Then I sealed it up again with a rubber band. Close up below.

Hardware Setup

Now to the hardware details. If you’re just dealing with parasitic power (i.e. no Vdd line) you’ll just need two wires, data and ground. The DS18S20 has three pins as seen below

Taken from the DS18S20 Datasheet @ Maxim

So for parasitic power you’ll solder the GND to Vdd. Grab a CAT5 cable and strip down two wires (I used orange and green). Solder a line on your CAT5 to the GND+Vdd and another line to the DQ (data line). Pay attention to your colors.

Now on the other end you’re going to crimp the CAT5 into a RJ11 (this is your standard telephone line). I don’t suggest using a telephone line as the wires are so thin that my solder gun burned through them (grr!).

Below is the diagram for your crimped RJ11.

Above chart taken from the DS9490R Datasheet @ Maxim

You’ll be just using 3 and 4, where 3 is the Data line and 4 is the GND line in a parasitic power setup. They call it 1-Wire Data and 1-Wire Return on the chart.

Crimp the RJ11 on there and that’s it. You’ve got a temperature sensor ready to slap on your carboy.

Software Setup

Now to setting up the software. I used digitemp combined with dtgraph. Digitemp pulls the data from the sensors. DTGraph pushes the data into a mysql database and handles the php website.

I used Ubuntu 11.10 for this but it should work for other Ubuntu versions. First up grab a copy of digitemp via apt-get

Now we need to see if your usb adapter can see your sensors. Run the following and you should see the sensors on your network. -w means walk the network.

Not sure why I always have a device called ‘Unknown Family Code’ but it still works.

Now let’s set up the .digitemprc config file.

This should create a .digitemprc file in your local directory. Mine looked like this:

You’re gonna want to copy this somewhere safe so you don’t overwrite it. I put mine in /home/jdrews/digitemp/digitemp.conf

Now let’s read some temps!

Ok so now that we have some temps let’s start setting up the UI: dtgraph. Grab the latest tarball off http://sourceforge.net/projects/dtgraph/

Mine was dtgraph-0.4m.tar.gz. Untar it

In this file is an INSTALL doc that is pretty straight forward. I’ll walk you through the basics.

You’ll need a LAMP server. Install it with apt-get

For 12.04 LTS the above line looks like the following

You’ll also need some mdb2 drivers and jpgraph

Ok now that we have the reqs down lets set up the mysql database to hold our temps. In this case my database is called stats.

Then use dtgraph’s scripts to create the structure in your new database.

If you get a warning that looks like the following, just change your ‘TYPE=MyISAM’ to ‘ENGINE=MyISAM’. This is happening since we’re using a different version of mysql.

Now we’ll create a user for digitemp and grant it privileges to our new stats database. Log into mysql.

And grant the rights to your new user, dt_logger

So the database should now be setup. Lets get the website going.

Copy the contents of the ‘www’ folder in your dtgraph folder (the one we untar’d) to /var/www/dtgraph. You might need to create this folder. Feel free to name it something else if you want.

Set the permissions on your conf.php to read and write. Group should suffice.

You’ll want to edit the conf.php and add in all your configuration info. Here’s the first half of mine with all the important changes. Pay particular notice to the digitemp_conf, the sql username and password, and the jp_path.

Ok now that that’s done let’s make sure you can see your webpage. Go to http://localhost/dtgraph (or whatever you named your folder). You should see the webpage. If not check to make sure apache and mysql are running. You could also see a blank page if index.php is not a default page type. If so go to http://localhost/dtgraph/index.php. Lastly start reading through the INSTALL file in dtgraph and see if there’s something we missed. 😉

Now lets set up the logging. I’m going to be using the logger.php that’s included with dtgraph. It pulls it configuration values from the conf.php file so as long as that’s set up correctly you should be able to run the following and get it to insert data into your digitemp database.

Now log into your mysql database and see if you have data. If all went well it should look like this.

Horray we have data! So let’s add some more datapoints by running the logger.php script a few more times. Now go look at your website again and you should see plot points. If not, you most likely have an issue connecting to the database. Check your conf.php and make sure it’s all correct.

Now it’s a good idea to password protect your admin folder if this is gonna be viewable from outside your network. You can do this with a simple .htaccess file sitting in the /admin folder. Refer to the tutorial here for more details: https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles

You set up the colors of your graph and the name of your sensors in the admin section. Here’s a helpful hint– Put your thumb and index finger on a sensor and watch the temp go up to figure out which is which.

http://localhost/dtgraph/admin/

Here’s how mine is set up.

You’ll notice I have alarms set for range and change amounts. To do this you’ll need to use sendmail or ssmtp (how I did it).

I’ll update this post later on how to set up ssmtp so your new fangled temperature monitoring system can send you alerts when your precious homebrew gets to warm/cold, or starts warming up/cooling down too fast.

 

5 thoughts on “Homebrew Temperature Sensing with 1-wire”

  1. Hi Jon,

    I’m trying to setup Dtgraph according your instructions, bu the install fails at all three sql-scripts.

    mysql -u <username> -p stats < mysql_create_digitemp_metadata.sql

    mysql -u <username> -p stats < mysql_create_digitemp.sql

    mysql -u <username> -p stats < mysql_create_digitemp_alarms.sql

    with error like:

    ERROR 1064 (42000) at line 8: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘(14) NOT NULL,
    SerialNumber varchar(17) NOT NULL default ”,
    Fahrenheit deci’ at line 3

    Any clues here?

    I’m using Ubuntu 12.04 and MySQL v5.5.29

    Thx, Roger

    1. Hey sorry it took me awhile to get back to you. Did you ever figure it out?

      My first thought was there’s some sort of dos line ending problem. Try running dos2unix on the sql scripts. apt-get install dos2unix if you don’t have it.

      I’m currently on 12.04 and 5.5.32 so that shouldn’t be the problem…

  2. Thanks a lot for the info!

    Your page gave me a starting point on what to look for. Although I ran digitemp on Mac and I had to use slightly different hardware.

    Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *