forked from alextoft/sureflap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setHubLedBrightness.php
37 lines (31 loc) · 930 Bytes
/
setHubLedBrightness.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
<?php
if(!$argv[1]) {
die("Usage: php ".$_SERVER['PHP_SELF']." [bright|dim|off]\n");
}
switch($argv[1]) {
case "bright":
$led = 1;
break;
case "dim":
$led = 4;
break;
case "off":
$led = 0;
break;
default:
die("Usage: php ".$_SERVER['PHP_SELF']." [bright|dim|off]\n");
}
include_once 'getDevices.php';
$json = json_encode(array("led_mode" => $led));
$ch = curl_init($endpoint."/api/device/$hub/control");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Content-Length: ".strlen($json),"Authorization: Bearer $token"));
$result = json_decode(curl_exec($ch),true) or die("Curl Failed\n");
if($result['data']['led_mode']==$led) {
print "Successfully Set $hubname LED Brightness!\n";
} else {
die("LED Brightness Change Failed!\n");
}
?>