Thu, 14 Aug 2014 22:43:41 +0200
Added thread locks for device processing
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 | |
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
|
24 | require_once('utilities.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
|
25 | |
174 | 26 | /* |
27 | * $arr contains the complete reply of the LIST BUS command | |
28 | */ | |
196 | 29 | $answer = send_cmd("DEVICE LIST"); |
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
|
30 | $arr = explode("\r\n", $answer); |
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
|
31 | |
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
|
32 | |
174 | 33 | if (isset($_GET['action'])) { |
34 | switch ($_GET['action']) { | |
35 | case 'edit': device_edit(); | |
36 | break; | |
37 | default: break; | |
38 | } | |
39 | } elseif (isset($_POST['action'])) { | |
40 | switch ($_POST['action']) { | |
41 | case 'testdata': testdata(); | |
42 | break; | |
43 | default: break; | |
44 | } | |
45 | } else { | |
46 | device_list(); | |
47 | } | |
48 | ||
49 | exit; | |
50 | ||
51 | /**************************************************************************** | |
52 | * | |
53 | */ | |
54 | ||
55 | ||
56 | /* | |
57 | * Device add | |
58 | * | |
59 | * @param string $_POST['Name'] The rpofile name | |
60 | */ | |
61 | function device_add() { | |
62 | ||
63 | if ($_POST['key'] == 'Add') { | |
64 | ||
65 | $cmd = "DEVICE ADD ".$_POST['Type']; | |
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
|
66 | |
174 | 67 | $sock = open_socket(); |
68 | if ($sock != false) { | |
69 | /* | |
70 | * Send command and absorb the result. | |
71 | */ | |
72 | socket_write($sock, $cmd, 4096); | |
73 | while (1) { | |
74 | $line = socket_read($sock, 4096); | |
75 | if ($line === '') | |
76 | break; | |
77 | } | |
78 | socket_close($sock); | |
79 | } | |
80 | } | |
81 | ||
82 | unset($_POST['UUID']); | |
83 | unset($_POST['Name']); | |
84 | unset($_POST['key']); | |
85 | unset($_POST['command']); | |
86 | load('devices.php'); | |
87 | } | |
88 | ||
89 | ||
90 | ||
91 | /* | |
92 | * Device update | |
93 | * | |
94 | * @param string $_POST['UUID'] The device UUID | |
95 | * @param string $_POST['Type'] The device Type | |
96 | * @param string $_POST['Direction'] The device IO Direction | |
97 | * @param string $_POST['Value'] The device value | |
209
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
196
diff
changeset
|
98 | * @param string $_POST['Offset'] The device offset |
174 | 99 | * @param string $_POST['Present'] The device Present state |
100 | * @param string $_POST['Address'] The device Address | |
101 | * @param string $_POST['Subdevice'] The device Subaddress | |
102 | * @param string $_POST['Gpiopin'] The device GPIO pin | |
103 | * @param string $_POST['Description'] The device Description | |
104 | * @param string $_POST['Comment'] The device Comment | |
105 | * @param string $_POST['key'] The button pressed. | |
106 | */ | |
107 | function device_update() { | |
108 | /* | |
109 | * Build the update command | |
110 | */ | |
111 | if ($_POST['key'] == 'Delete') { | |
196 | 112 | send_cmd("DEVICE DEL ".$_POST['UUID']); |
174 | 113 | } |
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
|
114 | |
174 | 115 | if ($_POST['key'] == 'Save') { |
116 | $sock = open_socket(); | |
117 | if ($sock != false) { | |
118 | /* | |
119 | * Send command and absorb the result. | |
120 | */ | |
121 | socket_write($sock, "DEVICE PUT ".$_POST['UUID'], 4096); | |
122 | usleep(20000); | |
123 | socket_write($sock, "TYPE,".$_POST['Type'], 4096); | |
124 | usleep(20000); | |
125 | socket_write($sock, "DIRECTION,".$_POST['Direction'], 4096); | |
126 | usleep(20000); | |
127 | socket_write($sock, "VALUE,".$_POST['Value'], 4096); | |
128 | usleep(20000); | |
209
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
196
diff
changeset
|
129 | socket_write($sock, "OFFSET,".$_POST['Offset'], 4096); |
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
196
diff
changeset
|
130 | usleep(20000); |
174 | 131 | socket_write($sock, "PRESENT,".$_POST['Present'], 4096); |
132 | usleep(20000); | |
133 | socket_write($sock, "ADDRESS,".$_POST['Address'], 4096); | |
134 | usleep(20000); | |
135 | socket_write($sock, "SUBDEVICE,".$_POST['Subdevice'], 4096); | |
136 | usleep(20000); | |
137 | socket_write($sock, "GPIOPIN,".$_POST['Gpiopin'], 4096); | |
138 | usleep(20000); | |
139 | socket_write($sock, "DESCRIPTION,".$_POST['Description'], 4096); | |
140 | usleep(20000); | |
141 | socket_write($sock, "COMMENT,".$_POST['Comment'], 4096); | |
142 | usleep(20000); | |
143 | socket_write($sock, '.', 4096); | |
144 | /* Absorb response */ | |
145 | while (1) { | |
146 | $line = socket_read($sock, 4096); | |
147 | if ($line === '') | |
148 | break; | |
149 | } | |
150 | socket_close($sock); | |
151 | } | |
152 | } | |
153 | ||
154 | unset($_POST['UUID']); | |
155 | unset($_POST['Type']); | |
156 | unset($_POST['Direction']); | |
157 | unset($_POST['Value']); | |
158 | unset($_POST['Present']); | |
159 | unset($_POST['Address']); | |
160 | unset($_POST['Subdevice']); | |
161 | unset($_POST['Gpiopin']); | |
162 | unset($_POST['Description']); | |
163 | unset($_POST['Comment']); | |
164 | unset($_POST['key']); | |
165 | unset($_POST['command']); | |
166 | load('devices.php'); | |
167 | } | |
168 | ||
169 | ||
170 | ||
171 | /* | |
172 | * Test input of a modified or new device. | |
173 | * | |
174 | * @param string $_POST['UUID'] Unique record UUID | |
175 | * @param string $_POST['Type'] Device Type | |
176 | * @param string $_POST['Direction'] | |
177 | * @param string $_POST['Value'] | |
209
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
196
diff
changeset
|
178 | * @param string $_POST['Offset'] |
174 | 179 | * @param string $_POST['Present'] |
180 | * @param string $_POST['Address'] | |
181 | * @param string $_POST['Subdevice'] | |
182 | * @param string $_POST['Gpiopin'] | |
183 | * @param string $_POST['Description'] | |
184 | * @param string $_POST['Comment'] | |
185 | * @param string $_POST['key'] Key choice, Save or Cancel | |
186 | * @param string $_POST['command'] Command used, 'add' or 'update' | |
187 | * | |
188 | * Return: 0 = Ok | |
189 | * 1 = Missing data | |
190 | * 2 = Address field too short | |
191 | * 3 = Address/Subdevice already in use | |
192 | * 4 = Description field too short | |
193 | * 5 = Comment field too short | |
194 | * 99 = Cancel key | |
195 | */ | |
196 | function test_thedata() { | |
197 | ||
198 | global $arr; | |
199 | ||
209
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
196
diff
changeset
|
200 | if (isset($_POST['UUID']) && isset($_POST['Type']) && isset($_POST['Direction']) && isset($_POST['Value']) && isset($_POST['Offset']) && |
174 | 201 | isset($_POST['Present']) && isset($_POST['Address']) && isset($_POST['Subdevice']) && isset($_POST['Gpiopin']) && |
202 | isset($_POST['Description']) && isset($_POST['Comment']) && isset($_POST['key']) && isset($_POST['command'])) { | |
203 | ||
204 | if ($_POST['key'] == 'Cancel') | |
205 | return 99; | |
206 | ||
207 | if (strlen($_POST['Address']) < 2) | |
208 | return 2; | |
209 | ||
210 | if (startsWith($arr[0], "212")) { | |
211 | $j = 1; | |
212 | while (1) { | |
213 | if (strcmp($arr[$j], ".") == 0) | |
214 | break; | |
215 | $f = explode(",", $arr[$j]); | |
216 | if (strcmp($f[0], $_POST['UUID']) && ($f[1] == $_POST['Address']) && ($f[2] == $_POST['Subdevice'])) { | |
217 | return 3; | |
218 | } | |
219 | $j++; | |
220 | } | |
221 | } | |
222 | ||
223 | if (strlen($_POST['Description']) < 2) | |
224 | return 4; | |
225 | ||
226 | if (strlen($_POST['Comment']) < 2) | |
227 | return 5; | |
228 | ||
229 | } else { | |
230 | return 1; | |
231 | } | |
232 | ||
233 | return 0; | |
234 | } | |
235 | ||
236 | ||
237 | ||
238 | /* | |
239 | * Test result from edit screen and do next action | |
240 | */ | |
241 | function testdata() { | |
242 | ||
243 | $result = test_thedata(); | |
244 | $error = ''; | |
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
|
245 | |
174 | 246 | switch ($result) { |
247 | case 0: if ($_POST['command'] == 'add') { | |
248 | device_add(); | |
249 | return; | |
250 | } else if ($_POST['command'] == 'update') { | |
251 | device_update(); | |
252 | return; | |
253 | } | |
254 | break; | |
255 | case 1: $error = 'Missing data'; | |
256 | break; | |
257 | case 2: $error = 'The Address is too short'; | |
258 | break; | |
259 | case 3: $error = 'The Address + Subdevice is already in use, choose another one'; | |
260 | break; | |
261 | case 4: $error = 'The Description is too short'; | |
262 | break; | |
263 | case 5: $error = 'The Comment is too short'; | |
264 | break; | |
265 | case 99: | |
266 | load('devices.php'); | |
267 | break; | |
268 | } | |
269 | ||
270 | if ($_POST['command'] == 'add') { | |
271 | $heading = 'ThermFerm - Add Device'; | |
272 | } else { | |
273 | $heading = 'ThermFerm - Edit Device'; | |
274 | } | |
275 | ||
276 | edit_screen($_POST['UUID'], $_POST['command'], $heading, $error); | |
277 | } | |
278 | ||
279 | ||
280 | ||
281 | /* | |
282 | * Unit edit screen. Used by unit_edit(), unit_add() and testdata() | |
283 | * | |
284 | * @param string $UUID The record UUID (fixed). | |
285 | * @param string $command 'add' or 'update' | |
286 | * @param string $heading Page heading title. | |
287 | * @Param string $error_message Blank or previous error. | |
288 | */ | |
289 | function edit_screen($UUID, $command, $heading, $error_message) { | |
290 | ||
196 | 291 | $answer = send_cmd("DEVICE GET ".$UUID); |
174 | 292 | $reply = explode("\r\n", $answer); |
293 | ||
294 | $outstr = build_header($heading); | |
295 | $outstr .= ' <div id="errors">'.PHP_EOL; | |
296 | $outstr .= ' '.$error_message.PHP_EOL; | |
297 | $outstr .= ' </div> <!-- errors -->'.PHP_EOL; | |
298 | $outstr .= ' <div id="etable">'.PHP_EOL; | |
299 | $outstr .= ' <form method="POST" action="devices.php">'.PHP_EOL; | |
300 | $outstr .= ' <table class="editor">'.PHP_EOL; | |
301 | ||
302 | if (startsWith($reply[0], "213")) { | |
303 | $j = 1; | |
304 | while (1) { | |
305 | if (strcmp($reply[$j], ".") == 0) | |
306 | break; | |
307 | $f = explode(",", $reply[$j]); | |
308 | if ($f[0] == "TYPE") { | |
309 | $type = $f[1]; | |
310 | /* | |
311 | * Only allow certain types to edit. Auto detected hardware cannot be changed. | |
312 | */ | |
313 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
314 | $outstr .= ' <td class="editname">Device Type</td>'.PHP_EOL; | |
315 | if (($type == "W1") || ($type == "GPIO")) | |
316 | $outstr .= ' <td class="editfield"><input type="hidden" name="Type" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
317 | else | |
318 | $outstr .= ' <td class="editfield"><input type="text" name="Type" size="50" value="'.$f[1].'"></td>'.PHP_EOL; | |
319 | $outstr .= ' </tr>'.PHP_EOL; | |
320 | } | |
321 | if ($f[0] == "DIRECTION") { | |
322 | $direction = $f[1]; | |
323 | /* | |
324 | * Only devices that cannot auto detect can be changed. | |
325 | */ | |
326 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
327 | $outstr .= ' <td class="editname">IO Direction and mode</td>'.PHP_EOL; | |
328 | if ($type == "W1") | |
329 | $outstr .= ' <td class="editfield"><input type="hidden" name="Direction" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
330 | else { | |
331 | $outstr .= ' <td class="editfield"><select name="Direction">'.PHP_EOL; | |
332 | if ($type == "GPIO") { | |
333 | $se = ($f[1] == "UNDEF")?" selected":""; | |
334 | $outstr .= ' <option value="UNDEF"'.$se.'>Undefined</option>'.PHP_EOL; | |
335 | $se = ($f[1] == "IN_BIN")?" selected":""; | |
336 | $outstr .= ' <option value="IN_BIN"'.$se.'>Binary input</option>'.PHP_EOL; | |
337 | $se = ($f[1] == "OUT_BIN")?" selected":""; | |
338 | $outstr .= ' <option value="OUT_BIN"'.$se.'>Binary output</option>'.PHP_EOL; | |
339 | $se = ($f[1] == "OUT_PWM")?" selected":""; | |
340 | $outstr .= ' <option value="OUT_PWM"'.$se.'>PWM output</option>'.PHP_EOL; | |
341 | } | |
342 | if ($type == "RC433") { | |
343 | $se = ($f[1] == "UNDEF")?" selected":""; | |
344 | $outstr .= ' <option value="UNDEF"'.$se.'>Undefined</option>'.PHP_EOL; | |
345 | $se = ($f[1] == "OUT_BIN")?" selected":""; | |
346 | $outstr .= ' <option value="OUT_BIN"'.$se.'>Binary output</option>'.PHP_EOL; | |
347 | } | |
348 | if ($type == "DHT") { | |
349 | $se = ($f[1] == "UNDEF")?" selected":""; | |
350 | $outstr .= ' <option value="UNDEF"'.$se.'>Undefined</option>'.PHP_EOL; | |
351 | $se = ($f[1] == "IN_ANALOG")?" selected":""; | |
352 | $outstr .= ' <option value="IN_ANALOG"'.$se.'>Analog input</option>'.PHP_EOL; | |
353 | } | |
354 | $outstr .= ' </select></td>'.PHP_EOL; | |
355 | } | |
356 | $outstr .= ' </tr>'.PHP_EOL; | |
357 | } | |
358 | if ($f[0] == "VALUE") { | |
359 | /* | |
360 | * Only output can be changed | |
361 | */ | |
362 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
363 | $outstr .= ' <td class="editname">Value</td>'.PHP_EOL; | |
364 | if (($direction == "OUT_BIN") || ($direction == "OUT_ANALOG") || ($direction == "OUT_PWM")) | |
365 | $outstr .= ' <td class="editfield"><input type="text" name="Value" size="50" value="'.$f[1].'"></td>'.PHP_EOL; | |
366 | else | |
367 | $outstr .= ' <td class="editfield"><input type="hidden" name="Value" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
368 | $outstr .= ' </tr>'.PHP_EOL; | |
369 | } | |
209
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
196
diff
changeset
|
370 | if ($f[0] == "OFFSET") { |
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
196
diff
changeset
|
371 | $outstr .= ' <tr class="editor">'.PHP_EOL; |
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
196
diff
changeset
|
372 | $outstr .= ' <td class="editname">Value</td>'.PHP_EOL; |
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
196
diff
changeset
|
373 | if ($direction == "IN_ANALOG") |
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
196
diff
changeset
|
374 | $outstr .= ' <td class="editfield"><input type="text" name="Offset" size="50" value="'.$f[1].'"></td>'.PHP_EOL; |
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
196
diff
changeset
|
375 | else |
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
196
diff
changeset
|
376 | $outstr .= ' <td class="editfield"><input type="hidden" name="Offset" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; |
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
196
diff
changeset
|
377 | $outstr .= ' </tr>'.PHP_EOL; |
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
196
diff
changeset
|
378 | } |
174 | 379 | if ($f[0] == "PRESENT") { |
380 | /* | |
381 | * Only devices that cannot auto detect can be changed. | |
382 | */ | |
383 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
384 | $outstr .= ' <td class="editname">Device Present</td>'.PHP_EOL; | |
385 | if (($type == "W1") || ($type == "GPIO")) | |
386 | $outstr .= ' <td class="editfield"><input type="hidden" name="Present" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
387 | else { | |
388 | $outstr .= ' <td class="editfield"><select name="Present">'.PHP_EOL; | |
389 | $se = ($f[1] == "UNDEF")?" selected":""; | |
390 | $outstr .= ' <option value="UNDEF"'.$se.'>Undefined</option>'.PHP_EOL; | |
391 | $se = ($f[1] == "NO")?" selected":""; | |
392 | $outstr .= ' <option value="NO"'.$se.'>Not present</option>'.PHP_EOL; | |
393 | $se = ($f[1] == "YES")?" selected":""; | |
394 | $outstr .= ' <option value="YES"'.$se.'>Present and Ok</option>'.PHP_EOL; | |
395 | $se = ($f[1] == "ERROR")?" selected":""; | |
396 | $outstr .= ' <option value="ERROR"'.$se.'>Present and Error</option>'.PHP_EOL; | |
397 | $outstr .= ' </select></td>'.PHP_EOL; | |
398 | } | |
399 | $outstr .= ' </tr>'.PHP_EOL; | |
400 | } | |
401 | if ($f[0] == "ADDRESS") { | |
402 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
403 | $outstr .= ' <td class="editname">Address</td>'.PHP_EOL; | |
404 | if (($type == "W1") || ($type == "GPIO")) | |
405 | $outstr .= ' <td class="editfield"><input type="hidden" name="Address" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
406 | else | |
407 | $outstr .= ' <td class="editfield"><input type="text" name="Address" size="50" value="'.$f[1].'"></td>'.PHP_EOL; | |
408 | $outstr .= ' </tr>'.PHP_EOL; | |
409 | } | |
410 | if ($f[0] == "SUBDEVICE") { | |
411 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
412 | $outstr .= ' <td class="editname">Subdevice</td>'.PHP_EOL; | |
413 | if (($type == "W1") || ($type == "GPIO")) | |
414 | $outstr .= ' <td class="editfield"><input type="hidden" name="Subdevice" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
415 | else | |
416 | $outstr .= ' <td class="editfield"><input type="text" name="Subdevice" size="5" value="'.$f[1].'"></td>'.PHP_EOL; | |
417 | $outstr .= ' </tr>'.PHP_EOL; | |
418 | } | |
419 | if ($f[0] == "GPIOPIN") { | |
420 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
421 | $outstr .= ' <td class="editname">GPIO pin</td>'.PHP_EOL; | |
422 | $outstr .= ' <td class="editfield"><input type="text" name="Gpiopin" size="5" value="'.$f[1].'"></td>'.PHP_EOL; | |
423 | $outstr .= ' </tr>'.PHP_EOL; | |
424 | } | |
425 | if ($f[0] == "DESCRIPTION") { | |
426 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
427 | $outstr .= ' <td class="editname">Description</td>'.PHP_EOL; | |
428 | $outstr .= ' <td class="editfield"><input type="text" name="Description" size="50" value="'.$f[1].'"></td>'.PHP_EOL; | |
429 | $outstr .= ' </tr>'.PHP_EOL; | |
430 | } | |
431 | if ($f[0] == "COMMENT") { | |
432 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
433 | $outstr .= ' <td class="editname">Comment</td>'.PHP_EOL; | |
434 | $outstr .= ' <td class="editfield"><input type="text" name="Comment" size="50" value="'.$f[1].'"></td>'.PHP_EOL; | |
435 | $outstr .= ' </tr>'.PHP_EOL; | |
436 | } | |
437 | $j++; | |
438 | } | |
439 | } | |
440 | ||
441 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
442 | $outstr .= ' <td class="editname"><input type="submit" value="Save" name="key"></td>'.PHP_EOL; | |
443 | $outstr .= ' <td class="editfield"><input type="submit" value="Cancel" name="key">'; | |
444 | $outstr .= '<input type="submit" value="Delete" name="key" style="margin-left: 100px;">'; | |
445 | $outstr .= '<input type="hidden" value="testdata" name="action">'; | |
446 | $outstr .= '<input type="hidden" value="'.$command.'" name="command">'; | |
447 | $outstr .= '<input type="hidden" value="'.$UUID.'" name="UUID"></td>'.PHP_EOL; | |
448 | $outstr .= ' </tr>'.PHP_EOL; | |
449 | $outstr .= ' </table>'.PHP_EOL; | |
450 | $outstr .= ' </form>'.PHP_EOL; | |
451 | $outstr .= ' </div> <!-- etable -->'.PHP_EOL; | |
452 | $outstr .= build_footer(); | |
453 | echo $outstr; | |
454 | } | |
455 | ||
456 | ||
457 | ||
458 | /* | |
459 | * Edit a Device. Fetches the record data and shows the edit screen. | |
460 | * | |
461 | * @param string $_GET['action'] Must be 'edit'. | |
462 | * @param string $_GET['UUID'] The UUID of the Unit. | |
463 | */ | |
464 | function device_edit() { | |
465 | if ($_GET['action'] == 'edit') { | |
466 | edit_screen($_GET['UUID'], 'update', 'ThermFerm - Edit Device', ''); | |
467 | return; | |
468 | } else { | |
469 | load('devices.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
|
470 | } |
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
|
471 | } |
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
|
472 | |
174 | 473 | |
474 | ||
475 | /* | |
476 | * @link edit device | |
477 | * @link add device | |
478 | */ | |
479 | function device_list() { | |
480 | global $arr; | |
481 | ||
482 | $outstr = build_header("ThermFerm - Devices Setup"); | |
483 | $outstr .= ' <div id="errors">'.PHP_EOL; | |
484 | $outstr .= ' </div> <!-- errors -->'.PHP_EOL; | |
485 | $outstr .= ' <div id="etable">'.PHP_EOL; | |
486 | $outstr .= ' <table class="setup">'.PHP_EOL; | |
487 | $outstr .= ' <tr class="trhead">'.PHP_EOL; | |
488 | $outstr .= ' <td class="setup" style="width: 300px;">UUID</td>'.PHP_EOL; | |
489 | $outstr .= ' <td class="setup" style="width: 120px;">Address</td>'.PHP_EOL; | |
490 | $outstr .= ' <td class="setup" style="width: 30px;">Sub</td>'.PHP_EOL; | |
491 | $outstr .= ' <td class="setup" style="width: 30px;">Ref</td>'.PHP_EOL; | |
492 | $outstr .= ' <td class="setup" style="width: 300px;">Cmt</td>'.PHP_EOL; | |
493 | $outstr .= ' <td class="setup" style="width: 35px;">Edit</td>'.PHP_EOL; | |
494 | $outstr .= ' </tr>'.PHP_EOL; | |
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
|
495 | |
174 | 496 | if (startsWith($arr[0], "212")) { |
497 | $j = 1; | |
498 | while (1) { | |
499 | if (strcmp($arr[$j], ".") == 0) | |
500 | break; | |
501 | $f = explode(",", $arr[$j]); | |
502 | $outstr .= ' <tr class="setup">'.PHP_EOL; | |
503 | $outstr .= ' <td class="setup">'.$f[0].'</td>'.PHP_EOL; | |
504 | $outstr .= ' <td class="setup">'.$f[1].'</td>'.PHP_EOL; | |
505 | $outstr .= ' <td class="setup">'.$f[2].'</td>'.PHP_EOL; | |
506 | $outstr .= ' <td class="setup">'.$f[3].'</td>'.PHP_EOL; | |
507 | $outstr .= ' <td class="setup">'.$f[4].'</td>'.PHP_EOL; | |
508 | if ($f[3] == 0) | |
509 | $outstr .= ' <td class="setup"><a href="devices.php?action=edit&UUID='.$f[0].'">Edit</a></td>'.PHP_EOL; | |
510 | else | |
511 | $outstr .= ' <td class="setup">Busy</td>'.PHP_EOL; | |
512 | $outstr .= ' </tr>'.PHP_EOL; | |
513 | $j++; | |
514 | } | |
515 | } | |
516 | ||
517 | $outstr .= ' </table>'.PHP_EOL; | |
518 | $outstr .= ' </div> <!-- etable -->'.PHP_EOL; | |
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
|
519 | |
174 | 520 | $outstr .= ' <div id="atable">'.PHP_EOL; |
521 | $outstr .= ' <form method="POST" action="devices.php">'.PHP_EOL; | |
522 | $outstr .= ' <table class="editor">'.PHP_EOL; | |
523 | $outstr .= ' <tr class="trhead"><td colspan="3">Add new Device</td></tr>'.PHP_EOL; | |
524 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
525 | $outstr .= ' <td class="editname">Select Device type</td>'.PHP_EOL; | |
526 | $outstr .= ' <td class="editfield">'.PHP_EOL; | |
527 | $outstr .= ' <select name="Type">'.PHP_EOL; | |
528 | $outstr .= ' <option value="NA">Not Available</option>'.PHP_EOL; | |
529 | $outstr .= ' <option value="RC433">433 Mhz Radio Controller</option>'.PHP_EOL; | |
530 | $outstr .= ' <option value="DHT">DHTnn type sensor</option>'.PHP_EOL; | |
531 | $outstr .= ' <option value="I2C">I2C bus device</option>'.PHP_EOL; | |
532 | $outstr .= ' <option value="SPI">SPI bus device</option>'.PHP_EOL; | |
533 | $outstr .= ' </select>'.PHP_EOL; | |
534 | $outstr .= ' </td>'.PHP_EOL; | |
535 | $outstr .= ' <td class="editsub"><input type="submit" value="Add" name="key"></td>'.PHP_EOL; | |
536 | $outstr .= '<input type="hidden" value="testdata" name="action">'; | |
537 | $outstr .= '<input type="hidden" value="add" name="command">'; | |
538 | $outstr .= '<input type="hidden" value="00000000-0000-0000-0000-000000000000" name="UUID">'; | |
539 | $outstr .= '<input type="hidden" value="UNDEF" name="Direction">'; | |
540 | $outstr .= '<input type="hidden" value="0" name="Value">'; | |
232 | 541 | $outstr .= '<input type="hidden" value="0" name="Offset">'; |
174 | 542 | $outstr .= '<input type="hidden" value="UNDEF" name="Present">'; |
543 | $outstr .= '<input type="hidden" value="address unknown" name="Address">'; | |
544 | $outstr .= '<input type="hidden" value="0" name="Subdevice">'; | |
545 | $outstr .= '<input type="hidden" value="-1" name="Gpiopin">'; | |
546 | $outstr .= '<input type="hidden" value="Describe me" name="Description">'; | |
547 | $outstr .= '<input type="hidden" value="Comment me" name="Comment">'; | |
548 | $outstr .= ' </tr>'.PHP_EOL; | |
549 | $outstr .= ' </table>'.PHP_EOL; | |
550 | $outstr .= ' </form>'.PHP_EOL; | |
551 | $outstr .= ' </div> <!-- atable -->'.PHP_EOL; | |
552 | ||
553 | $outstr .= build_footer(); | |
554 | ||
555 | echo $outstr; | |
556 | } | |
557 |