Sat, 16 Aug 2014 15:38:45 +0200
Fixed add unit web interface
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | <?php |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | /***************************************************************************** |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * Copyright (C) 2014 |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * Michiel Broek <mbroek at mbse dot eu> |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * This file is part of ThermFerm |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * This is free software; you can redistribute it and/or modify it |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * under the terms of the GNU General Public License as published by the |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * Free Software Foundation; either version 2, or (at your option) any |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * later version. |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * ThermFerm is distributed in the hope that it will be useful, but |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | * General Public License for more details. |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | * You should have received a copy of the GNU General Public License |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | * along with ThermFerm; see the file COPYING. If not, write to the Free |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | *****************************************************************************/ |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | |
173 | 24 | require_once('utilities.php'); |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | |
207 | 26 | |
27 | if (isset($_POST['action'])) { | |
28 | if ($_POST['action'] == "testdata") | |
29 | testdata(); | |
30 | } else { | |
31 | edit_screen(""); | |
32 | } | |
33 | ||
34 | ||
35 | exit; | |
36 | ||
37 | ||
38 | /***************************************************************************** | |
39 | * | |
40 | */ | |
41 | ||
42 | ||
43 | function global_update() { | |
44 | ||
45 | if ($_POST['key'] == 'Save') { | |
46 | $sock = open_socket(); | |
47 | if ($sock != false) { | |
48 | /* | |
49 | * Send command and absorb the result. | |
50 | */ | |
51 | socket_write($sock, "GLOBAL PUT", 4096); | |
52 | usleep(20000); | |
53 | socket_write($sock, "NAME,".$_POST['Name'], 4096); | |
54 | usleep(20000); | |
55 | socket_write($sock, "PORT,".$_POST['Port'], 4096); | |
56 | usleep(20000); | |
57 | socket_write($sock, "TEMP_ADDRESS,".$_POST['TempAddress'], 4096); | |
58 | usleep(20000); | |
59 | socket_write($sock, "HUM_ADDRESS,".$_POST['HumAddress'], 4096); | |
60 | usleep(20000); | |
61 | if (isset($_POST['LCDcols'])) { | |
62 | socket_write($sock, "LCD_COLS,".$_POST['LCDcols'], 4096); | |
63 | usleep(20000); | |
64 | } | |
65 | if (isset($_POST['LCDrows'])) { | |
66 | socket_write($sock, "LCD_ROWS,".$_POST['LCDrows'], 4096); | |
67 | usleep(20000); | |
68 | } | |
69 | socket_write($sock, ".", 4096); | |
70 | while (1) { | |
71 | $line = socket_read($sock, 4096); | |
72 | if ($line === '') | |
73 | break; | |
74 | } | |
75 | socket_close($sock); | |
76 | } | |
77 | } | |
78 | ||
79 | unset($_POST['Name']); | |
80 | unset($_POST['Port']); | |
81 | unset($_POST['TempAddress']); | |
82 | unset($_POST['HumAddress']); | |
83 | unset($_POST['LCDcols']); | |
84 | unset($_POST['LCDrows']); | |
85 | unset($_POST['key']); | |
86 | load('global.php'); | |
87 | } | |
88 | ||
89 | ||
90 | ||
91 | function test_thedata() { | |
92 | ||
93 | if (isset($_POST['Name']) && isset($_POST['Port']) && | |
94 | isset($_POST['TempAddress']) && isset($_POST['HumAddress']) && | |
95 | isset($_POST['key'])) { | |
96 | ||
97 | if ($_POST['key'] == 'Cancel') | |
98 | return 99; | |
99 | ||
100 | if (isset($_POST['LCDcols']) && (($_POST['LCDcols'] != 16) && ($_POST['LCDcols'] != 20))) | |
101 | return 2; | |
102 | ||
103 | if (isset($_POST['LCDrows']) && (($_POST['LCDrows'] != 2) && ($_POST['LCDrows'] != 4))) | |
104 | return 3; | |
105 | ||
106 | } else { | |
107 | return 1; | |
108 | } | |
109 | ||
110 | return 0; | |
111 | } | |
112 | ||
113 | ||
114 | ||
115 | function testdata() | |
116 | { | |
117 | $result = test_thedata(); | |
118 | $error = ''; | |
119 | ||
120 | switch ($result) { | |
121 | case 0: global_update(); | |
122 | return; | |
123 | break; | |
124 | case 1: $error = 'Missing data'; | |
125 | break; | |
126 | case 2: $error = 'LCD columns must be 16 or 20'; | |
127 | break; | |
128 | case 3: $error = 'LCD rows must be 2 or 4'; | |
129 | break; | |
130 | case 99: | |
131 | load('global.php'); | |
132 | break; | |
133 | } | |
134 | ||
135 | edit_screen($error); | |
136 | } | |
137 | ||
138 | ||
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
139 | |
207 | 140 | function edit_screen($error_message) |
141 | { | |
142 | /* | |
143 | * Get list of devices, we need it later | |
144 | */ | |
145 | $answer = send_cmd("DEVICE LIST"); | |
146 | $devices = explode("\r\n", $answer); | |
147 | ||
148 | /* | |
149 | * Get current global data | |
150 | */ | |
151 | $answer = send_cmd("GLOBAL GET"); | |
152 | $reply = explode("\r\n", $answer); | |
153 | ||
154 | $outstr = build_header("ThermFerm - Global Setup"); | |
155 | $outstr .= ' <div id="errors">'.PHP_EOL; | |
156 | $outstr .= ' '.$error_message.PHP_EOL; | |
157 | $outstr .= ' </div> <!-- errors -->'.PHP_EOL; | |
158 | $outstr .= ' <div id="etable">'.PHP_EOL; | |
159 | $outstr .= ' <form method="POST" action="global.php">'.PHP_EOL; | |
160 | $outstr .= ' <table class="editor">'.PHP_EOL; | |
161 | $outstr .= ' <tr class="trhead">'.PHP_EOL; | |
162 | $outstr .= ' <td class="setup" colspan="2" style="text-align: center; height: 20px; padding-top: 5px;">Global Setup</td>'.PHP_EOL; | |
163 | $outstr .= ' </tr>'.PHP_EOL; | |
164 | ||
165 | if (startsWith($reply[0], "213")) { | |
166 | $i = 1; | |
167 | while (1) { | |
168 | if (strcmp($reply[$i], ".") == 0) | |
169 | break; | |
170 | $f = explode(",", $reply[$i]); | |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
171 | |
207 | 172 | if ($f[0] == "NAME") { |
173 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
174 | $outstr .= ' <td class="editname">System Name</td>'.PHP_EOL; | |
175 | $outstr .= ' <td class="editfield"><input type="text" name="Name" size="50" value="'.$f[1].'"></td>'.PHP_EOL; | |
176 | $outstr .= ' </tr>'.PHP_EOL; | |
177 | } | |
178 | if ($f[0] == "PORT") { | |
179 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
180 | $outstr .= ' <td class="editname">Telnet port</td>'.PHP_EOL; | |
181 | $outstr .= ' <td class="editfield"><input type="text" name="Port" size="5" value="'.$f[1].'"></td>'.PHP_EOL; | |
182 | $outstr .= ' </tr>'.PHP_EOL; | |
183 | } | |
184 | if ($f[0] == "TEMP_ADDRESS") { | |
185 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
186 | $outstr .= ' <td class="editname">Room temperature sensor</td>'.PHP_EOL; | |
187 | $outstr .= ' <td class="editfield"><select name="TempAddress">'.PHP_EOL; | |
188 | $outstr .= ' <option value="">Not Assigned</option>'.PHP_EOL; | |
189 | if (startsWith($devices[0], "212")) { | |
190 | $j = 1; | |
191 | while (1) { | |
192 | if (strcmp($devices[$j], ".") == 0) | |
193 | break; | |
194 | $g = explode(",", $devices[$j]); | |
195 | if ($g[5] == "IN_ANALOG") { | |
196 | ($f[1] == $g[0]) ? $se = " selected" : $se = ""; | |
197 | $outstr .= ' <option value="'.$g[0].'"'.$se.'>'.$g[1].' '.$g[4].'</option>'.PHP_EOL; | |
198 | } | |
199 | $j++; | |
200 | } | |
201 | } | |
202 | $outstr .= ' </select></td>'.PHP_EOL; | |
203 | $outstr .= ' </tr>'.PHP_EOL; | |
204 | } | |
205 | if ($f[0] == "HUM_ADDRESS") { | |
206 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
207 | $outstr .= ' <td class="editname">Room humidity sensor</td>'.PHP_EOL; | |
208 | $outstr .= ' <td class="editfield"><select name="HumAddress">'.PHP_EOL; | |
209 | $outstr .= ' <option value="">Not Assigned</option>'.PHP_EOL; | |
210 | if (startsWith($devices[0], "212")) { | |
211 | $j = 1; | |
212 | while (1) { | |
213 | if (strcmp($devices[$j], ".") == 0) | |
214 | break; | |
215 | $g = explode(",", $devices[$j]); | |
216 | if ($g[5] == "IN_ANALOG") { | |
217 | ($f[1] == $g[0]) ? $se = " selected" : $se = ""; | |
218 | $outstr .= ' <option value="'.$g[0].'"'.$se.'>'.$g[1].' '.$g[4].'</option>'.PHP_EOL; | |
219 | } | |
220 | $j++; | |
221 | } | |
222 | } | |
223 | $outstr .= ' </select></td>'.PHP_EOL; | |
224 | $outstr .= ' </tr>'.PHP_EOL; | |
225 | } | |
226 | if ($f[0] == "LCD_COLS") { | |
227 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
228 | $outstr .= ' <td class="editname">LCD columns</td>'.PHP_EOL; | |
229 | $outstr .= ' <td class="editfield"><input type="text" name="LCDcols" size="5" value="'.$f[1].'"></td>'.PHP_EOL; | |
230 | $outstr .= ' </tr>'.PHP_EOL; | |
231 | } | |
232 | if ($f[0] == "LCD_ROWS") { | |
233 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
234 | $outstr .= ' <td class="editname">LCD rows</td>'.PHP_EOL; | |
235 | $outstr .= ' <td class="editfield"><input type="text" name="LCDrows" size="5" value="'.$f[1].'"></td>'.PHP_EOL; | |
236 | $outstr .= ' </tr>'.PHP_EOL; | |
237 | } | |
238 | $i++; | |
239 | } | |
240 | } | |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
241 | |
207 | 242 | $outstr .= ' <tr class="editor">'.PHP_EOL; |
243 | $outstr .= ' <td class="editname"><input type="submit" value="Save" name="key"></td>'.PHP_EOL; | |
244 | $outstr .= ' <td class="editfield"><input type="submit" value="Cancel" name="key">'; | |
245 | $outstr .= '<input type="hidden" value="testdata" name="action">'; | |
246 | $outstr .= ' </tr>'.PHP_EOL; | |
247 | $outstr .= ' </table>'.PHP_EOL; | |
248 | $outstr .= ' </form>'.PHP_EOL; | |
249 | $outstr .= ' </div> <!-- etable -->'.PHP_EOL; | |
250 | $outstr .= build_footer(); | |
251 | ||
252 | echo $outstr; | |
253 | } | |
254 | ||
255 |