Monitoring/controlling with Linux on the cheap

Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum

Help Support Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.
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
 
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!
 
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>
 
Lol. The host limiting would have saved me anyway, it's only accepting connections from localhost or my home isp
 
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.
 
I finally discovered the problem with my temperature inaccuracies. My DIY thermowells are causing 100% of the errors. When I took the probes out of the kettles and dunked them in water, they measured exactly the same as my calibrated thermometer. Installing them in the kettles results in a somewhat linear error likely caused by conduction in the kettle walls. The error is likely volume dependent, so I can't just fit a curve to correct the installation error. On one hand, I'm glad all of the electronics are working properly. On the other hand, I guess I'm going to need new thermowells!
 
Back
Top