1 <?php |
|
2 /***************************************************************************** |
|
3 * Copyright (C) 2014-2024 |
|
4 * |
|
5 * Michiel Broek <mbroek at mbse dot eu> |
|
6 * |
|
7 * This file is part of ThermFerm |
|
8 * |
|
9 * This is free software; you can redistribute it and/or modify it |
|
10 * under the terms of the GNU General Public License as published by the |
|
11 * Free Software Foundation; either version 2, or (at your option) any |
|
12 * later version. |
|
13 * |
|
14 * ThermFerm is distributed in the hope that it will be useful, but |
|
15 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
17 * General Public License for more details. |
|
18 * |
|
19 * You should have received a copy of the GNU General Public License |
|
20 * along with ThermFerm; see the file COPYING. If not, write to the Free |
|
21 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
22 *****************************************************************************/ |
|
23 |
|
24 /* |
|
25 * Look for the style names in the jqwidgets/styles directory. |
|
26 */ |
|
27 $my_style = 'ui-redmond'; |
|
28 |
|
29 require_once('utilities.php'); |
|
30 require_once('liveview.php'); |
|
31 |
|
32 |
|
33 |
|
34 /* |
|
35 * Handle the post events |
|
36 */ |
|
37 if (isset($_POST['mode']) && isset($_POST['UUID'])) { |
|
38 send_array(array('UNIT PUT '.$_POST['UUID'], 'MODE,'.$_POST['mode'], '.')); |
|
39 unset($_POST['UUID']); |
|
40 unset($_POST['mode']); |
|
41 } |
|
42 |
|
43 |
|
44 if (isset($_POST['HeaterState']) && isset($_POST['UUID'])) { |
|
45 send_array(array('UNIT PUT '.$_POST['UUID'], 'HEATER_STATE,'.$_POST['HeaterState'], '.')); |
|
46 unset($_POST['UUID']); |
|
47 unset($_POST['HeaterState']); |
|
48 } |
|
49 |
|
50 |
|
51 if (isset($_POST['CoolerState']) && isset($_POST['UUID'])) { |
|
52 send_array(array('UNIT PUT '.$_POST['UUID'], 'COOLER_STATE,'.$_POST['CoolerState'], '.')); |
|
53 unset($_POST['UUID']); |
|
54 unset($_POST['CoolerState']); |
|
55 } |
|
56 |
|
57 |
|
58 if (isset($_POST['FanState']) && isset($_POST['UUID'])) { |
|
59 send_array(array('UNIT PUT '.$_POST['UUID'], 'FAN_STATE,'.$_POST['FanState'], '.')); |
|
60 unset($_POST['UUID']); |
|
61 unset($_POST['FanState']); |
|
62 } |
|
63 |
|
64 |
|
65 if (isset($_POST['Fridge_lo']) && isset($_POST['Fridge_hi']) && isset($_POST['key']) && isset($_POST['UUID'])) { |
|
66 |
|
67 if ($_POST['key'] == "Set") { |
|
68 send_array(array('UNIT PUT '.$_POST['UUID'], 'FRIDGE_SET_LO,'.$_POST['Fridge_lo'], 'FRIDGE_SET_HI,'.$_POST['Fridge_hi'], '.')); |
|
69 } |
|
70 unset($_POST['Fridge_lo']); |
|
71 unset($_POST['Fridge_hi']); |
|
72 unset($_POST['key']); |
|
73 unset($_POST['UUID']); |
|
74 } |
|
75 |
|
76 |
|
77 if (isset($_POST['Beer_lo']) && isset($_POST['Beer_hi']) && isset($_POST['key']) && isset($_POST['UUID'])) { |
|
78 |
|
79 if ($_POST['key'] == "Set") { |
|
80 send_array(array('UNIT PUT '.$_POST['UUID'], 'BEER_SET_LO,'.$_POST['Beer_lo'], 'BEER_SET_HI,'.$_POST['Beer_hi'], '.')); |
|
81 } |
|
82 unset($_POST['Beer_lo']); |
|
83 unset($_POST['Beer_hi']); |
|
84 unset($_POST['key']); |
|
85 unset($_POST['UUID']); |
|
86 } |
|
87 |
|
88 |
|
89 if (isset($_POST['SetProfile']) && isset($_POST['key']) && isset($_POST['UUID'])) { |
|
90 |
|
91 $cmd = array('UNIT PUT '.$_POST['UUID']); |
|
92 if ($_POST['key'] == "Start") |
|
93 $cmd[] = 'PROF_STATE,RUN'; |
|
94 else if (($_POST['key'] == "Pause") || ($_POST['key'] == "Resume")) |
|
95 $cmd[] = 'PROF_STATE,PAUSE'; |
|
96 else if ($_POST['key'] == "Abort") |
|
97 $cmd[] = 'PROF_STATE,ABORT'; |
|
98 else if ($_POST['key'] == "Off") |
|
99 $cmd[] = 'PROF_STATE,OFF'; |
|
100 $cmd[] = '.'; |
|
101 send_array($cmd); |
|
102 unset($_POST['SetProfile']); |
|
103 unset($_POST['key']); |
|
104 unset($_POST['UUID']); |
|
105 } |
|
106 |
|
107 |
|
108 /* |
|
109 * Get initial room temperature and humidity |
|
110 */ |
|
111 $answer = send_cmd('GLOBAL GET'); |
|
112 $arr = explode("\r\n", $answer); |
|
113 |
|
114 $version = "?"; |
|
115 $temp_value = "NA"; |
|
116 $temp_state = "NA"; |
|
117 $hum_value = "NA"; |
|
118 $hum_state = "NA"; |
|
119 |
|
120 if (startsWith($arr[0], "213")) { |
|
121 $j = 1; |
|
122 while (1) { |
|
123 if (strcmp($arr[$j], ".") == 0) |
|
124 break; |
|
125 $f = explode(",", $arr[$j]); |
|
126 |
|
127 if ($f[0] == "RELEASE") |
|
128 $version = $f[1]; |
|
129 if ($f[0] == "TEMP_STATE") |
|
130 $temp_state = $f[1]; |
|
131 if (($f[0] == "TEMP_VALUE") && ($temp_state == "YES")) |
|
132 $temp_value = $f[1]; |
|
133 if ($f[0] == "HUM_STATE") |
|
134 $hum_state = $f[1]; |
|
135 if (($f[0] == "HUM_VALUE") && ($hum_state == "YES")) |
|
136 $hum_value = $f[1]; |
|
137 $j++; |
|
138 } |
|
139 } |
|
140 |
|
141 $outstr = '<!DOCTYPE html>'.PHP_EOL; |
|
142 $outstr .= '<html>'.PHP_EOL; |
|
143 $outstr .= ' <head>'.PHP_EOL; |
|
144 $outstr .= ' <meta http-equiv="content-type" content="text/html; charset=utf-8" />'.PHP_EOL; |
|
145 $outstr .= ' <title>ThermFerm monitor</title>'.PHP_EOL; |
|
146 $outstr .= ' <link type="text/css" href="css/style.css" rel="stylesheet" media="all" />'.PHP_EOL; |
|
147 $outstr .= ' <link type="text/css" href="jqwidgets/styles/jqx.base.css" rel="stylesheet" />'.PHP_EOL; |
|
148 $outstr .= ' <link type="text/css" href="jqwidgets/styles/jqx.'.$my_style.'.css" rel="stylesheet" />'.PHP_EOL; |
|
149 $outstr .= ' <script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>'.PHP_EOL; |
|
150 $outstr .= ' <script type="text/javascript" src="jqwidgets/jqxcore.js"></script>'.PHP_EOL; |
|
151 $outstr .= ' <script type="text/javascript" src="jqwidgets/jqxwindow.js"></script>'.PHP_EOL; |
|
152 $outstr .= ' <script type="text/javascript" src="jqwidgets/jqxtabs.js"></script>'.PHP_EOL; |
|
153 $outstr .= ' <script type="text/javascript" src="jqwidgets/jqxcheckbox.js"></script>'.PHP_EOL; |
|
154 $outstr .= ' <script type="text/javascript" src="jqwidgets/jqxbuttons.js"></script>'.PHP_EOL; |
|
155 $outstr .= ' <script type="text/javascript" src="jqwidgets/jqxradiobutton.js"></script>'.PHP_EOL; |
|
156 $outstr .= ' <script type="text/javascript" src="jqwidgets/jqxchart.core.js"></script>'.PHP_EOL; |
|
157 $outstr .= ' <script type="text/javascript" src="jqwidgets/jqxgauge.js"></script>'.PHP_EOL; |
|
158 $outstr .= ' <script type="text/javascript" src="jqwidgets/jqxdraw.js"></script>'.PHP_EOL; |
|
159 $outstr .= ' <script type="text/javascript" src="jqwidgets/jqxdata.js"></script>'.PHP_EOL; |
|
160 $outstr .= ' <script type="text/javascript" src="jqwidgets/jqxdata.export.js"></script>'.PHP_EOL; |
|
161 $outstr .= ' <script type="text/javascript" src="jqwidgets/jqxtooltip.js"></script>'.PHP_EOL; |
|
162 $outstr .= ' </head>'.PHP_EOL; |
|
163 |
|
164 $outstr .= ' <body class="default">'.PHP_EOL; |
|
165 $outstr .= ' <div id="jqxWidget">'.PHP_EOL; |
|
166 $outstr .= ' <div id="header">'.PHP_EOL; |
|
167 $outstr .= ' <div id="title">'.PHP_EOL; |
|
168 $outstr .= ' ThermFerm '.$version.PHP_EOL; |
|
169 $outstr .= ' </div>'.PHP_EOL; |
|
170 $outstr .= ' <div id="room">'.PHP_EOL; |
|
171 $outstr .= ' <div id="room_temp" class="rtemp">'.$temp_value.' °C</div>'.PHP_EOL; |
|
172 $outstr .= ' <div id="room_hum" class="rtemp">'.$hum_value.' %</div>'.PHP_EOL; |
|
173 $outstr .= ' </div>'.PHP_EOL; |
|
174 $outstr .= ' <form action="maintenance.php" style="margin:30px; float:right">'.PHP_EOL; |
|
175 $outstr .= ' <input type="submit" id="maintenance" value="Maintenance panel" />'.PHP_EOL; |
|
176 $outstr .= ' </form>'.PHP_EOL; |
|
177 $outstr .= ' </div> <!-- header -->'.PHP_EOL; |
|
178 $outstr .= liveview(); |
|
179 |
|
180 /* Create the tabs */ |
|
181 $outstr .= ' <script type="text/javascript" src="js/index.js"></script>'.PHP_EOL; |
|
182 $outstr .= ' </div> <!-- jqxWidget -->'.PHP_EOL; |
|
183 $outstr .= ' </body>'.PHP_EOL; |
|
184 $outstr .= '</html>'.PHP_EOL; |
|
185 |
|
186 echo $outstr; |
|