Thu, 10 Jan 2019 20:22:06 +0100
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.
<?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);