www/getfermentlog.php

Sat, 19 Jan 2019 12:05:37 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 19 Jan 2019 12:05:37 +0100
changeset 189
6470e5c6a001
parent 179
8adaeecd9dc8
child 194
d202777ebae5
permissions
-rw-r--r--

In bmsd added missing json percent. The Makefile didn't install the fpdf library. Added profile commands. Small changes to the monitor fermenters screen. The monitor fermenters scheduler is now more responsive. Profiles selection and commands in the remote thermferm.

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