-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_lifx.php
More file actions
46 lines (32 loc) · 918 Bytes
/
check_lifx.php
File metadata and controls
46 lines (32 loc) · 918 Bytes
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
#!/usr/bin/php
<?php
$authtok = "REDACTED";
$apibase = "https://api.lifx.com/v1";
$which = "id:" . $argv[1];
syslog(LOG_DEBUG, $which);
// echo "*Begin*\n";
$c = curl_init();
$headers = array( "Authorization: Bearer $authtok", "User-Agent: check_lifx/1.0" );
curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
curl_setopt($c, CURLOPT_URL, $apibase . "/lights/" . $which);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
// echo "*cURL exec*\n";
$result = curl_exec($c) or die("Error when running curl");
// echo "*cURL result*\n";
// print_r($result);
curl_close($c);
// echo "*JSON Decode*\n";
$parse = json_decode($result, true);
// print_r($parse);
$pulse = $parse[0]["seconds_since_seen"];
if ( isset($pulse) && ($pulse < 900) ) {
$ret = 0;
$text = "Recent light update detected";
} else {
$ret = 2;
$text = "Update not found for this light";
} // end if
echo $text;
exit($ret);
// echo "*End*\n";
?>