Mon, 07 Jan 2019 22:35:32 +0100
Fermenter monitor screen added control boxes and LED's.
172 | 1 | <?php |
2 | ||
3 | require_once('config.php'); | |
4 | ||
5 | if (isset($_GET["code"])) | |
6 | $code = $_GET["code"]; | |
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 | 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 | 11 | $connect = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME); |
12 | if (! $connect) { | |
13 | echo "[]"; | |
14 | return; | |
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 | 22 | $result = mysqli_query($connect, $query); |
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 | 58 | } |
59 | echo json_encode($logs); |