3 for QUERY in `echo $QUERY_STRING | tr '&' ' '`; do
4 for VALUE in `echo $QUERY | tr '=' ' '`; do
5 if [ "$VALUE" == "id" ]; then
7 elif [ "$ID" == "?" ]; then
9 elif [ "$VALUE" == "power" ]; then
11 elif [ "$POWER" == "?" ]; then
13 elif [ "$VALUE" == "mobile" ]; then
16 elif [ "$VALUE" == "nofloat" ]; then
24 GPIOPATH=/sys/class/gpio/gpio
25 #VALID_ONOFF_IDS="7 18 20 29"
26 VALID_ONOFF_IDS="7 18 20"
30 GPIOVALUE=$(cat "${GPIOPATH}${1}/value")
31 if [ "$GPIOVALUE" = "1" ]; then
39 GPIOVALUE=$(cat "${GPIOPATH}${1}/value")
40 [ "$GPIOVALUE" = "1" ]
43 if [ "$POWER" == "1" -o "$POWER" == "0" ]; then
44 for CHECKID in $VALID_ONOFF_IDS ; do
45 if [ "$CHECKID" == "$ID" ]; then
46 echo "$POWER" > "${GPIOPATH}${ID}/value"
47 echo "Content-type: text/html"
51 echo "<title>Realraum Relay Switch</title>"
52 echo '<script type="text/javascript">window.location="/cgi-bin/switch.cgi";</script>'
59 DESC_7="Decke Links Vorne"
60 DESC_20="Decke Rechts Vorne"
61 DESC_18="Decke Rechts Mitte"
62 #DESC_29="GPIO Nicht Belegt"
64 echo "Content-type: text/html"
68 echo "<title>Realraum Relay Power</title>"
69 echo '<script type="text/javascript">'
71 echo 'function callbackUpdateButtons(req) {
72 if (req.status != 200) {
75 var data = JSON.parse(req.responseText);
76 for (var keyid in data) {
77 on_btn = document.getElementById("onbtn_"+keyid);
78 off_btn = document.getElementById("offbtn_"+keyid);
79 if (on_btn && off_btn)
81 on_btn.className = "onbutton";
82 off_btn.className = "offbutton";
84 { on_btn.className += " enableborder"; }
86 { off_btn.className += " enableborder"; }
91 echo 'function updateButtons(uri) {
92 var req = new XMLHttpRequest;
93 req.overrideMimeType("application/json");
94 req.open("GET", uri, true);
95 req.onload = function() {callbackUpdateButtons(req)};
96 req.setRequestHeader("googlechromefix","");
100 echo 'function sendMultiButton( str ) {
101 url = "/cgi-bin/mswitch.cgi?"+str;
105 echo 'setInterval("updateButtons(\"/cgi-bin/mswitch.cgi\");", 30*1000);'
107 echo 'function sendButton( onoff, btn )'
109 echo ' var req = new XMLHttpRequest();'
110 echo ' url = "/cgi-bin/switch.cgi?power="+onoff+"&id="+btn;'
111 echo ' req.open("GET", url ,false);'
112 echo ' //google chrome workaround'
113 echo ' req.setRequestHeader("googlechromefix","");'
114 echo ' req.send(null);'
118 echo 'div.switchbox {'
121 #echo ' max-width:236px;'
122 echo ' max-width:300px;'
123 echo ' font-size:10pt;'
124 echo ' border:1px solid black;'
125 #echo ' height: 32px;'
129 echo 'div.switchnameleft {'
130 echo ' width:12em; display:inline-block; vertical-align:middle; margin-left:3px;'
133 echo 'span.alignbuttonsright {'
134 echo ' top:0px; float:right; display:inline-block; text-align:right; padding:0;'
137 echo 'div.switchnameright {'
138 echo ' width:12em; display:inline-block; vertical-align:middle; float:right; display:inline-block; margin-left:1ex; margin-right:3px; margin-top:3px; margin-bottom:3px;'
141 echo 'span.alignbuttonsleft {'
142 echo ' float:left; text-align:left; padding:0;'
146 echo ' font-size:11pt;'
148 echo ' height: 32px;'
149 echo ' background-color: lime;'
154 echo ' font-size:11pt;'
156 echo ' height: 32px;'
157 echo ' background-color: red;'
162 echo ' font-size:11pt;'
164 echo ' height: 32px;'
165 #echo ' background-color: grey;'
169 echo '.enableborder {
171 font-variant: small-caps;
172 border-style: inset;'
177 #echo "<h1>Realraum rf433ctl</h1>"
178 #echo "<div style=\"float:left; border:1px solid black;\">"
179 echo "<div style=\"float:left;\">"
180 echo "<div style=\"float:left; border:1px solid black; margin-right:2ex; margin-bottom:2ex;\">"
181 for DISPID in $VALID_ONOFF_IDS; do
182 NAME="$(eval echo -n \$DESC_$DISPID)"
183 [ -z "$NAME" ] && NAME=$DISPID
185 echo "<div class=\"switchbox\">"
186 echo "<span class=\"alignbuttonsleft\">"
187 if gpio_is_on $DISPID; then
188 echo " <button id=\"onbtn_$DISPID\" class=\"onbutton enableborder\" onClick='sendMultiButton(\"$DISPID=1\");'>On</button>"
189 echo " <button id=\"offbtn_$DISPID\" class=\"offbutton\" onClick='sendMultiButton(\"$DISPID=0\");'>Off</button>"
191 echo " <button id=\"onbtn_$DISPID\" class=\"onbutton\" onClick='sendMultiButton(\"$DISPID=1\");'>On</button>"
192 echo " <button id=\"offbtn_$DISPID\" class=\"offbutton enableborder\" onClick='sendMultiButton(\"$DISPID=0\");'>Off</button>"
195 echo -n "<div class=\"switchnameright\">$NAME</div>"
196 # echo -n "<div class=\"switchnameright\">$NAME ("
197 # print_gpio_state $DISPID
201 if [ "$NOFLOAT" == "1" ]; then
206 echo "<div class=\"switchbox\">"
207 echo "<span class=\"alignbuttonsleft\">"
208 echo -n " <button class=\"onbutton\" onClick='sendMultiButton(\""
209 for DISPID in $VALID_ONOFF_IDS; do echo -n "$DISPID=1&"; done
210 echo "\");'>On</button>"
211 echo -n " <button class=\"offbutton\" onClick='sendMultiButton(\""
212 for DISPID in $VALID_ONOFF_IDS; do echo -n "$DISPID=0&"; done
213 echo "\");'>Off</button>"
215 echo -n "<div class=\"switchnameright\">Alle</div>"
217 if [ "$NOFLOAT" == "1" ]; then
222 if [ "$MOBILE" != "1" -a -n "$VALID_SEND_IDS" ]; then
224 echo "<div style=\"float:left; border:1px solid black; margin-right:2ex; margin-bottom:2ex;\">"
228 for DISPID in $VALID_SEND_IDS; do
229 ITEMCOUNT=$((ITEMCOUNT+1))
230 NAME="$(eval echo \$DESC_$DISPID)"
231 [ -z "$NAME" ] && NAME=$DISPID
233 echo "<div class=\"switchbox\">"
234 echo "<span class=\"alignbuttonsleft\">"
235 echo " <button class=\"sendbutton\" onClick='sendButton(\"on\",\"$DISPID\");'> </button>"
237 echo "<div class=\"switchnameright\">$NAME</div>"
239 if [ "$NOFLOAT" == "1" -a $((ITEMCOUNT % 2 )) -ne 1 ]; then