www-thermferm/getstate.php

Mon, 15 Apr 2024 17:04:57 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 15 Apr 2024 17:04:57 +0200
changeset 678
cc49115e769e
parent 578
d694abd9d809
child 693
3518c07737d8
permissions
-rw-r--r--

Better websocket broadcast messages. Added GLOBAL JSON command to the server. Better logic to trigger websocket and mqtt data updates for the fermenter units. Websocket receive added fermenter mode, stage, setpoints, switches. Added more css styles for the fermenter screen. Added the fermenter screen php and javascript.

<?php
/*****************************************************************************
 * Copyright (C) 2014-2019
 *   
 * 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_LO") && ($mode == "BEER"))
		$target_temperature_lo = $f[1];
	if (($f[0] == "BEER_SET_HI") && ($mode == "BEER"))
		$target_temperature_hi = $f[1];
	if (($f[0] == "FRIDGE_SET_LO") && ($mode == "FRIDGE"))
		$target_temperature_lo = $f[1];
	if (($f[0] == "FRIDGE_SET_HI") && ($mode == "FRIDGE"))
		$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