forked from timleland/rfoutlet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoggle.php
35 lines (30 loc) · 1.07 KB
/
toggle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
if (!isset($setupPhpDone)) { // avoid multiple inclusion
header('Content-Type: application/json');
header('Cache-Control: no-cache, must-revalidate');
include 'setup.php'; // setup variables reading ./outletCodes.json
}
$outletLight = $_POST['outletId'];
$outletStatus = $_POST['outletStatus'];
if ($outletLight == "All") {
// All is all outlets combined
$codesToToggle = array();
foreach ($codeBook as $light => $value) {
if ($light <> 'All') {
array_push($codesToToggle, $value[$outletStatus]);
}
}
} else {
// One
$codesToToggle = array($codeBook[$outletLight][$outletStatus]);
}
foreach ($codesToToggle as $codeSendCode) {
shell_exec($codeSendPath . ' ' . $codeSendCode . ' -p ' . $codeSendPIN . ' -l ' . $codeSendPulseLength);
error_log($outletLight . ' ' . $outletStatus . ': ' . $codeSendPath . ' ' . $codeSendCode . ' -p ' . $codeSendPIN . ' -l ' . $codeSendPulseLength);
sleep(0.2);
}
if (!isset($timerDaemon)) {
// not called from timer Daemon maybe from CGI
die(json_encode(array('success' => true)));
}
?>