www-thermferm/getstate.php

Sun, 27 Dec 2015 17:52:26 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 27 Dec 2015 17:52:26 +0100
changeset 477
9167ad4c2e77
parent 397
00ca08f5a6f8
child 522
4d9ed666431d
permissions
-rw-r--r--

Renamed Mash-in step to Prepare on the display. Don't run the pump when the mash is added. When preparing the mash, first heat the HLT, and then the MLT so that both have the chance to reach their target temperatures.

<?php
/*****************************************************************************
 * Copyright (C) 2014
 *   
 * Michiel Broek <mbroek at mbse dot eu>
 *
 * This file is part of ThermFerm
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * ThermFerm is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ThermFerm; see the file COPYING.  If not, write to the Free
 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *****************************************************************************/

require_once('utilities.php');

if (isset($_GET["uuid"]))
	$uuid = $_GET["uuid"];
else
	$uuid = "48c9ae27-3f58-41c9-ae4b-1d57b249c45a";

$answer = send_cmd('UNIT GET '.$uuid);
$arr = explode("\r\n", $answer);

$air_temperature = "NA";
$air_state = "NA";
$beer_temperature = "NA";
$beer_state = "NA";
$target_temperature_lo = "NA";
$target_temperature_hi = "NA";
$led1 = $led2 = $led3 = $sw1 = $sw2 = $sw3 = "";
$fridge_set = "NA";
$beer_set = "NA";
$heater = $cooler = $fan = $psu = $door = "no";
$prof_state = "OFF";
$mode = "NA";
$cooler_state = "NA";
$heater_state = "NA";
$fan_state = "NA";


if (startsWith($arr[0], "213")) {
    $j = 1;
    while (1) {
	if (strcmp($arr[$j], ".") == 0)
	    break;
	$f = explode(",", $arr[$j]);

	if ($f[0] == "AIR_STATE")
		$air_state = $f[1];
	if (($f[0] == "AIR_TEMPERATURE") && ($air_state == "OK"))
		$air_temperature = $f[1];
	if ($f[0] == "BEER_STATE")
		$beer_state = $f[1];
	if (($f[0] == "BEER_TEMPERATURE") && ($beer_state == "OK"))
		$beer_temperature = $f[1];
	if ($f[0] == "MODE")
		$mode = $f[1];
	if (($f[0] == "COOLER_ADDRESS") && (strcmp($f[1], "(null)")))
		$cooler = "yes";
	if ($f[0] == "COOLER_STATE") {
		$cooler_state = $f[1];
		$led1 = $f[1] ? '<div class="LEDgreen_on"></div>' : '<div class="LEDgreen_off"></div>';
	}
	if (($f[0] == "HEATER_ADDRESS") && (strcmp($f[1], "(null)")))
		$heater = "yes";
	if ($f[0] == "HEATER_STATE") {
		$heater_state = $f[1];
		$led2 = $f[1] ? '<div class="LEDgreen_on"></div>' : '<div class="LEDgreen_off"></div>';
	}
	if (($f[0] == "FAN_ADDRESS") && (strcmp($f[1], "(null)")))
		$fan = "yes";
	if ($f[0] == "FAN_STATE") {
		$fan_state = $f[1];
		$led3 = $f[1] ? '<div class="LEDgreen_on"></div>' : '<div class="LEDgreen_off"></div>';
	}
	if (($f[0] == "PSU_ADDRESS") && (strcmp($f[1], "(null)")))
		$psu = "yes";
	if (($f[0] == "DOOR_ADDRESS") && (strcmp($f[1], "(null)")))
		$door = "yes";
	if (($f[0] == "BEER_SET") && ($mode == "BEER"))
		$target_temperature_lo = $target_temperature_hi = $f[1];
	if (($f[0] == "FRIDGE_SET") && ($mode == "FRIDGE"))
		$target_temperature_lo = $target_temperature_hi = $f[1];
	if (($f[0] == "PROF_TARGET_LO") && ($mode == "PROFILE"))
		$target_temperature_lo = $f[1];
	if (($f[0] == "PROF_TARGET_HI") && ($mode == "PROFILE"))
		$target_temperature_hi = $f[1];
	if (($f[0] == "PROF_STATE") && ($mode == "PROFILE"))
		$prof_state = 'State: '.$f[1];
	$j++;
    }
}


/*
 * Create the value for the mode select radio buttons
 */
strcmp($mode, "OFF") ? $se = "" : $se = " checked";
$modestr  = '    <input type="radio" name="mode" onchange="this.form.submit()" class="select" value="OFF"'.$se.'>Off<br>'.PHP_EOL;
strcmp($mode, "NONE") ? $se = "" : $se = " checked";
$modestr .= '    <input type="radio" name="mode" onchange="this.form.submit()" class="select" value="NONE"'.$se.'>None<br>'.PHP_EOL;
(strcmp($heater, "no") || strcmp($cooler, "no")) ? $dis = "" : $dis = " disabled";
strcmp($mode, "FRIDGE") ? $se = "" : $se = " checked";
$modestr .= '    <input type="radio" name="mode" onchange="this.form.submit()" class="select" value="FRIDGE"'.$se.$dis.'>Fridge<br>'.PHP_EOL;
strcmp($mode, "BEER") ? $se = "" : $se = " checked";
$modestr .= '    <input type="radio" name="mode" onchange="this.form.submit()" class="select" value="BEER"'.$se.$dis.'>Beer<br>'.PHP_EOL;
strcmp($mode, "PROFILE") ? $se = "" : $se = " checked";
$modestr .= '    <input type="radio" name="mode" onchange="this.form.submit()" class="select" value="PROFILE"'.$se.$dis.'>Profile'.PHP_EOL;


/*
 * Create the values for the on/off switches
 */
(($mode == "NONE") && ($cooler == "yes")) ? $dis = "" : $dis = " disabled";
($cooler_state == "0") ? $ch = " checked" : $ch = "";
$sw1  = '        <input type="radio" name="CoolerState" onchange="this.form.submit()" value="0"'.$dis.$ch.'>Off<br>'.PHP_EOL;
($cooler_state == "100") ? $ch = " checked" : $ch = "";
$sw1 .= '        <input type="radio" name="CoolerState" onchange="this.form.submit()" value="100"'.$dis.$ch.'>On'.PHP_EOL;

(($mode == "NONE") && ($heater == "yes")) ? $dis = "" : $dis = " disabled";
($heater_state == "0") ? $ch = " checked" : $ch = "";
$sw2  = '        <input type="radio" name="HeaterState" onchange="this.form.submit()" value="0"'.$dis.$ch.'>Off<br>'.PHP_EOL;
($heater_state == "100") ? $ch = " checked" : $ch = "";
$sw2 .= '        <input type="radio" name="HeaterState" onchange="this.form.submit()" value="100"'.$dis.$ch.'>On'.PHP_EOL;

(($mode == "NONE") && ($fan== "yes")) ? $dis = "" : $dis = " disabled";
($fan_state == "0") ? $ch = " checked" : $ch = "";
$sw3  = '        <input type="radio" name="FanState" onchange="this.form.submit()" value="0"'.$dis.$ch.'>Off<br>'.PHP_EOL;
($fan_state == "100") ? $ch = " checked" : $ch = "";
$sw3 .= '        <input type="radio" name="FanState" onchange="this.form.submit()" value="100"'.$dis.$ch.'>On'.PHP_EOL;



$reply = array (
    'air_temperature'       => $air_temperature,
    'beer_temperature'      => $beer_temperature,
    'target_temperature_lo' => $target_temperature_lo,
    'target_temperature_hi' => $target_temperature_hi,
    'mode'                  => $modestr,
    'led1'                  => $led1,
    'led2'                  => $led2,
    'led3'                  => $led3,
    'sw1'                   => $sw1,
    'sw2'                   => $sw2,
    'sw3'                   => $sw3,
    'profile_state'         => $prof_state
);


echo json_encode($reply);
?>

mercurial