Sat, 19 Jan 2019 12:05:37 +0100
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.
<?php require_once('config.php'); if (isset($_GET["code"])) $code = $_GET["code"]; else $code = "TB0015"; $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."'"; $connect = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME); if (! $connect) { echo "[]"; return; } $step = 600; // Must be a multiple of 300 $ld = 0; $lh = 0; $ch = 0; $lc = 0; $cc = 0; $result = mysqli_query($connect, $query); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $dt = new DateTime($row['datetime'], new DateTimeZone('Europe/Amsterdam')); $ts = $dt->getTimestamp(); $diff = $ts - $ld; if ($diff < $step) { // Read on } else if ($diff > $step) { // Reset, out of sync. $ld = $ts; $lh = $ch = $row['heater_usage']; $lc = $cc = $row['cooler_usage']; } else { // This is a valid timeframe. $ch = $row['heater_usage']; $cc = $row['cooler_usage']; $heat = round(($ch - $lh) / ($step / 100)); $cool = round(($cc - $lc) / ($step / 100)); // echo $heat . ' ' . $cool . PHP_EOL; $logs[] = array( 'date' => $row['datetime'], 'air' => $row['temperature_air'], 'beer' => $row['temperature_beer'], 'chiller' => $row['temperature_chiller'], 'room' => $row['temperature_room'], 'tlo' => $row['target_low'], 'thi' => $row['target_high'], 'heater' => $heat, 'cooler' => $cool ); $ld = $ts; $lh = $ch; $lc = $cc; } } echo json_encode($logs);