www/getfermentlog.php

Wed, 09 Jan 2019 16:19:26 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 09 Jan 2019 16:19:26 +0100
changeset 184
3dbe1d2265ed
parent 179
8adaeecd9dc8
child 194
d202777ebae5
permissions
-rw-r--r--

Removed the setpoints and temperatures from the right display panel. Added the current temperatures in text to the gauges as caption. Adjusted the gauge caption font display. Only send commands to the mqtt server just before we fetch fresh data. Added new target temperature settings in the right display box.

<?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);

mercurial