www/getfermentlog.php

Thu, 10 Jan 2019 20:22:06 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 10 Jan 2019 20:22:06 +0100
changeset 185
4c25db9e8102
parent 179
8adaeecd9dc8
child 194
d202777ebae5
permissions
-rw-r--r--

Added configuration settings for MQTT in config.php. Finished screen box sizes for the fermenters monitor. Select beername and code from the current brew products and send it to the fermenter. Added switch commands to the fermenter. Delay data get from the fermenter after sending any command so there is time to process the commands. Turn switches off when the mode changes. Removed 0.2 degrees setpoint diffs for low and high, the fermenter must deal with it. Prevent turning the heater and cooler together on.

172
684c651dd165 Added fermentation graph screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 <?php
684c651dd165 Added fermentation graph screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2
684c651dd165 Added fermentation graph screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 require_once('config.php');
684c651dd165 Added fermentation graph screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4
684c651dd165 Added fermentation graph screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 if (isset($_GET["code"]))
684c651dd165 Added fermentation graph screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 $code = $_GET["code"];
684c651dd165 Added fermentation graph screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 else
179
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
8 $code = "TB0015";
172
684c651dd165 Added fermentation graph screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9
179
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
10 $query = "SELECT datetime,temperature_air,temperature_beer,temperature_chiller,temperature_room,target_low,target_high,heater_usage,cooler_usage FROM log_fermentation WHERE product_code='".$code."'";
172
684c651dd165 Added fermentation graph screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 $connect = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME);
684c651dd165 Added fermentation graph screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 if (! $connect) {
684c651dd165 Added fermentation graph screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 echo "[]";
684c651dd165 Added fermentation graph screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 return;
684c651dd165 Added fermentation graph screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 }
179
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
16 $step = 600; // Must be a multiple of 300
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
17 $ld = 0;
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
18 $lh = 0;
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
19 $ch = 0;
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
20 $lc = 0;
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
21 $cc = 0;
172
684c651dd165 Added fermentation graph screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 $result = mysqli_query($connect, $query);
684c651dd165 Added fermentation graph screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
179
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
24
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
25 $dt = new DateTime($row['datetime'], new DateTimeZone('Europe/Amsterdam'));
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
26 $ts = $dt->getTimestamp();
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
27 $diff = $ts - $ld;
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
28
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
29 if ($diff < $step) {
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
30 // Read on
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
31 } else if ($diff > $step) {
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
32 // Reset, out of sync.
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
33 $ld = $ts;
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
34 $lh = $ch = $row['heater_usage'];
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
35 $lc = $cc = $row['cooler_usage'];
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
36 } else {
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
37 // This is a valid timeframe.
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
38 $ch = $row['heater_usage'];
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
39 $cc = $row['cooler_usage'];
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
40 $heat = round(($ch - $lh) / ($step / 100));
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
41 $cool = round(($cc - $lc) / ($step / 100));
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
42 // echo $heat . ' ' . $cool . PHP_EOL;
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
43 $logs[] = array(
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
44 'date' => $row['datetime'],
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
45 'air' => $row['temperature_air'],
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
46 'beer' => $row['temperature_beer'],
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
47 'chiller' => $row['temperature_chiller'],
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
48 'room' => $row['temperature_room'],
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
49 'tlo' => $row['target_low'],
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
50 'thi' => $row['target_high'],
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
51 'heater' => $heat,
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
52 'cooler' => $cool
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
53 );
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
54 $ld = $ts;
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
55 $lh = $ch;
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
56 $lc = $cc;
8adaeecd9dc8 Fixed the fermentation chart to be just like the thermferm chart.
Michiel Broek <mbroek@mbse.eu>
parents: 172
diff changeset
57 }
172
684c651dd165 Added fermentation graph screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 }
684c651dd165 Added fermentation graph screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 echo json_encode($logs);

mercurial