www/cmd_fermenter.php

Thu, 10 Jan 2019 20:22:06 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 10 Jan 2019 20:22:06 +0100
changeset 185
4c25db9e8102
parent 183
a810539dc218
child 189
6470e5c6a001
permissions
-rw-r--r--

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

/*
 * Sequence number file. Must be mode 666 in directory mode 777
 */
$sfile = "run/sequence";
if (fopen($sfile, "r")) {
	$data = file_get_contents($sfile);
	$nr = intval($data);
} else {
	$nr = 1;
}
$nr++;
if ($fp = fopen($sfile, "w")) {
	file_put_contents($sfile, $nr);
	fclose($fp);
}


if (isset($_POST['node'])) {
	$node = $_POST['node'];
} else {
	return 1;
}
if (isset($_POST['alias'])) {
	$alias = $_POST['alias'];
} else {
	return 1;
}
if (isset($_POST['payload'])) {
	$payload = $_POST['payload'];
} else {
	return 1;
}


/*
 * topic:    mbv1.0/fermenters/DCMD/$node/$alias
 * payload:  {"timestamp":1546956819,"seq":688,"metric":$payload}
 * $payload: {"product":{"code":"HUP001","name":"Hop Hup"}}
 *           {"stage":"PRIMARY","mode":"FRIDGE","setpoint":{"low":17.8,"high":18.2}}
 *           {"heater":{"state":0},"cooler":{"state":0},"fan":{"state":0},"light":{"state":0}}
 *           {"profile":{"uuid":"...","name":"profielnaam","inittemp":{"low":18.2,"high":20.5},"fridgemode":0,
 *              "steps":[{"resttime":12,"steptime":36,"target":{"low":20.8,"high":23.1},"fridgemode":0},
 *              	 {"resttime":48,"steptime":48,"target":{"low":27.5,"high":28.0},"fridgemode":0}]}}
 */
$topic = "mbv1.0/fermenters/DCMD/" . $node . "/" . $alias;
$payload = '\'{"timestamp":' . time() . ',"seq":' . $nr . ',"metric":' . $payload . '}\'';

syslog(LOG_NOTICE, $topic . ' ' . $payload);
shell_exec('mosquitto_pub -h '.MQTT_HOST.' -q 0 -t '.$topic.' -m '.$payload);

?>

mercurial