-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoggle.php
70 lines (61 loc) · 1.81 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
header('Content-Type: application/json');
header('Cache-Control: no-cache, must-revalidate');
// Edit these codes for each outlet
$codes = array(
"1" => array(
"on" => 349491,
"off" => 349500
),
"2" => array(
"on" => 5526979,
"off" => 5526988
),
"3" => array(
"on" => 5527299,
"off" => 5527308
),
"4" => array(
"on" => 5528835,
"off" => 5528844
),
"5" => array(
"on" => 5534979,
"off" => 5534988
),
);
// Path to the codesend binary (current directory is the default)
$codeSendPath = './codesend';
// This PIN is not the first PIN on the Raspberry Pi GPIO header!
// Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/
// for more information.
$codeSendPIN = "0";
// Pulse length depends on the RF outlets you are using. Use RFSniffer to see what pulse length your device uses.
$codeSendPulseLength = "181";
if (!file_exists($codeSendPath)) {
error_log("$codeSendPath is missing, please edit the script", 0);
die(json_encode(array('success' => false)));
}
$outletLight = $_POST['outletId'];
$outletStatus = $_POST['outletStatus'];
if ($outletLight == "6") {
// 6 is all 5 outlets combined
if (function_exists('array_column')) {
// PHP >= 5.5
$codesToToggle = array_column($codes, $outletStatus);
} else {
$codesToToggle = array();
foreach ($codes as $outletCodes) {
array_push($codesToToggle, $outletCodes[$outletStatus]);
}
}
} else {
// One
$codesToToggle = array($codes[$outletLight][$outletStatus]);
}
foreach ($codesToToggle as $codeSendCode) {
shell_exec($codeSendPath . ' ' . $codeSendCode . ' -p ' . $codeSendPIN . ' -l ' . $codeSendPulseLength);
sleep(1);
}
die(json_encode(array('success' => true)));
?>