www-thermferm/getstate.php

Sat, 14 Jul 2018 17:21:25 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 14 Jul 2018 17:21:25 +0200
changeset 533
49580ca85ab7
parent 529
00b45f2aaac3
child 578
d694abd9d809
permissions
-rw-r--r--

Versie 0.6.3. MQTT device berichten alleen als een fermenter ingeschakeld is. MQTT fermenter birth en death berichhten als een fementer in of uitgeschakeld wordt. MQTT node death bericht bij normaal afsluiten van de daemon. Alle MQTT persistent berichten worden nu goed opgeruikmd.

<?php
/*****************************************************************************
 * Copyright (C) 2014-2017
 *   
 * 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 = "e53858c3-a97e-4b07-85e9-524257909f45";

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

$air_temperature = "NA";
$air_state = "NA";
$beer_temperature = "NA";
$beer_state = "NA";
$chiller_temperature = "NA";
$chiller_state = "NA";
$target_temperature_lo = "NA";
$target_temperature_hi = "NA";
$led1 = $led2 = $led3 = $sw1 = $sw2 = $sw3 = $alarmled = "";
$fridge_set = "NA";
$beer_set = "NA";
$heater = $cooler = $chiller = $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] == "CHILLER_STATE")
	    	$chiller_state = $f[1];
	if (($f[0] == "CHILLER_TEMPERATURE") && ($chiller_state == "OK"))
	    	$chiller_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];
	if ($f[0] == "ALARM")
		$alarmled = $f[1] ? '<div class="LEDred_on"></div>' : '<div class="LEDred_off"></div>';
	$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,
    'chiller_temperature'   => $chiller_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,
    'alarm'                 => $alarmled
);


echo json_encode($reply);
?>

mercurial