Home Brew Forums > Home Brewing Beer > DIY Projects > Monitoring/controlling with Linux on the cheap




Reply
 
LinkBack Thread Tools Display Modes
Old 12-07-2012, 03:42 AM   #241
Feedback Score: 0 reviews
Recipes 
 
Join Date: Nov 2012
Posts: 227
Liked 12 Times on 12 Posts
Likes Given: 37

Default

Not kokomo, but I'm using PHP to pull the data out of a mysql database and display it using a simple line graph from the google chart API. You can check out the code I used (basically copied and pasted, replaced with data) here


__________________
Primary: Amber Ale, Columbus/Cascade IPA
Bottled: Two Hearted Clone, Zippy Cream Ale, NB Hefeweizen, Semi-Sweet Cider, Tart Cider, Kolsch
On Deck: Drinking some beer.
Next Purchase: BCS Book
bfinleyui is offline
 
Reply With Quote Quick reply to this message
Old 12-07-2012, 03:47 PM   #242
Feedback Score: 0 reviews
Recipes 
 
Join Date: May 2009
Location: Sacramento, CA
Posts: 103
Liked 5 Times on 5 Posts

Default

bfinleyui- that's pretty much what I'm trying to accomplish. I have no experience with PHP or mysql. I looked at the page source, but I don't see any reference to PHP or mysql. Can you give me a hint? Thanks!


bikesnbeers is offline
 
Reply With Quote Quick reply to this message
Old 12-07-2012, 04:23 PM   #243
Feedback Score: 0 reviews
Recipes 
 
Join Date: Nov 2012
Posts: 227
Liked 12 Times on 12 Posts
Likes Given: 37

Default

I don't have the python script handy, I can post that when I get home, but here's what I can show...

- Python script (running on a cron job) polls the temp sensor once a minute, and sends the data t
to a mysql database running on my webhost.

- Then I just have a PHP script that you can hit, and here's the code for that, commented where needed, lemme know if you have issues.

Code:
<?php

// Connec to the database
mysql_connect("DATABASEHOST", "DATABASEUSER", "DATABASEPASSWORD");
mysql_select_db("DATABASENAME");

// Run query for all temp readings, oldest first.
$result = mysql_query("SELECT * FROM readings order by reading_time desc ");

// Initialize a blank array
$temps = array();

// Push those temperatures into the array, using the time as the key
while ($row = mysql_fetch_array($result)) {
        $temps[strtotime($row['reading_time'])] = $row['reading'];

}


?>


<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">

        function mysqlTimeStampToDate(timestamp) {
          //function parses mysql datetime string and returns javascript Date object
          //input has to be in this format: 2007-06-05 15:26:02
          var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
          var parts=timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
          return new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
        }


        // Initialization code from Google
        google.load("visualization", "1", {packages:["corechart"]});
        google.setOnLoadCallback(drawChart);


        function drawChart() {

                //  Setup the column name and types
                var data = new google.visualization.DataTable();
                data.addColumn('datetime','Time');
                data.addColumn('number', 'Temp');

                // Add rows of data
                data.addRows([
                <?php

                        // Iterate through that php array, echoing it out in [date, temp] format, a javascript array.
                        foreach ($temps as $k => $v) {
                                echo "[new Date(" . $k . " * 1000), " . $v ."],\n";
                        }
                ?>
                ]);

                var options = {
                        title: 'Fermentation Chamber'
                };


                var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
                chart.draw(data, options);
      }
    </script>
  </head>

  <body>

    <div id="chart_div" style="width: 100%; height: 600px;"></div>
  </body>
</html>
__________________
Primary: Amber Ale, Columbus/Cascade IPA
Bottled: Two Hearted Clone, Zippy Cream Ale, NB Hefeweizen, Semi-Sweet Cider, Tart Cider, Kolsch
On Deck: Drinking some beer.
Next Purchase: BCS Book
bfinleyui is offline
 
Reply With Quote Quick reply to this message
Old 12-07-2012, 04:33 PM   #244
Vagoo?
Feedback Score: 0 reviews
 
mrgstiffler's Avatar
Recipes 
 
Join Date: May 2009
Location: Newberg, OR, Cascadia
Posts: 1,050
Liked 73 Times on 64 Posts
Likes Given: 1

Default

Heh, I saw what you did... I've made the same mistake before.
__________________
Simple BIAB Calculator
mrgstiffler is offline
 
Reply With Quote Quick reply to this message
Old 12-07-2012, 05:18 PM   #245
Feedback Score: 0 reviews
Recipes 
 
Join Date: Nov 2012
Posts: 227
Liked 12 Times on 12 Posts
Likes Given: 37

Default

Lol. The host limiting would have saved me anyway, it's only accepting connections from localhost or my home isp
__________________
Primary: Amber Ale, Columbus/Cascade IPA
Bottled: Two Hearted Clone, Zippy Cream Ale, NB Hefeweizen, Semi-Sweet Cider, Tart Cider, Kolsch
On Deck: Drinking some beer.
Next Purchase: BCS Book
bfinleyui is offline
 
Reply With Quote Quick reply to this message
Old 12-07-2012, 08:09 PM   #246
Feedback Score: 0 reviews
Recipes 
 
Join Date: May 2009
Location: Sacramento, CA
Posts: 103
Liked 5 Times on 5 Posts

Default

I see that php works on the server side. That's a little out of my league right now. I'm thinking that I can use the spreadsheet and google query to fill in the chart. Thanks for the info. I'd still like to see the python if you get a chance. If you want the chart to auto update, do you have to refresh the page? I'm looking at the gauge chart too. Thanks.
bikesnbeers is offline
 
Reply With Quote Quick reply to this message
Old 12-19-2012, 04:47 PM   #247
Feedback Score: 0 reviews
Recipes 
 
Join Date: Mar 2011
Location: Brandon, Florida
Posts: 234
Liked 5 Times on 4 Posts
Likes Given: 20

Default

nice work guys...


GatorDad is offline
 
Reply With Quote Quick reply to this message
Reply

Quick Reply
Message:
Options
Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Temperature Monitoring and Control with Arduino erock2112 DIY Projects 85 04-05-2011 07:46 PM
Controlling Wort Flow capnr0n DIY Projects 12 03-16-2010 04:00 AM
Temperature Controlled Brewcloset with remote monitoring Mista_Sparkle DIY Projects 1 11-26-2009 07:53 AM
Monitoring temp on the cheap... tireater DIY Projects 20 04-15-2009 07:06 PM
Basic ambient temperature monitoring jasper9 DIY Projects 8 12-31-2008 11:19 PM



FOLLOW US ON