www-thermferm/devices.php

Sun, 03 Aug 2014 22:49:33 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 03 Aug 2014 22:49:33 +0200
changeset 175
b73490398368
parent 174
244de612c572
child 196
4d7a96c5d1ff
permissions
-rw-r--r--

Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.

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

mercurial