-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlights-nazi.php
76 lines (63 loc) · 1.53 KB
/
lights-nazi.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
71
72
73
74
75
76
<?php
/*
Call this php script on startup (we suggest doing this using screen running as a daemon),
so that it's always running in the background.
*/
//Add your own values here. Don't expect it to work with ours :)
$status_url = "http://p-space.gr/status/";
$apollo_url = "http://localhost/Apollo/Helios.php";
$verbose = FALSE;
$oldData = -1;
for(;;)
{
if($verbose)
echo "Connecting to '".$status_url."'\n";
$data = file_get_contents($status_url);
if($data !== FALSE)
{
if($verbose)
{
echo "Connected. Data received:\n";
echo $data."\n";
}
if($data != $oldData)
{
$oldData = $data;
echo "Status Changed. New status is: ";
echo ($data == 1? "Open":"Closed")."\n";
$handle = curl_init($apollo_url);
$data = array('state' => ($data == 1? 'ALL_ON':'ALL_OFF'));
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
for($i=0; $i<3; $i++)
{
echo "Calling Apollo (".($i+1)." of 3)\n";
$retVal = curl_exec($handle);
if($retVal == false)
{
echo "Couldn't connect to: ".$apollo_url."\n";
echo "Error: ";
echo curl_errno($handle)." ";
echo curl_error($handle)."\n";
sleep(9);
}
else
{
echo "Apollo responded. Success!\n";
}
sleep(1);
}
curl_close($handle);
}
}
else
{
if($verbose)
echo "Error connecting to '".$status_url."'. Trying again in 30 seconds.\n";
sleep(25);
}
// echo "Connecting in 5 seconds...\n";
sleep(5);
}
?>