forked from bren1818/TCPLightingWebInterface
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdiscoverBulbs.php
106 lines (78 loc) · 2.63 KB
/
discoverBulbs.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
include "include.php";
pageHeader("TCP Lighting Controller");
ob_flush();
flush ();
function getDeviceIDs(){
//get system state
$CMD = "cmd=GWRBatch&data=<gwrcmds><gwrcmd><gcmd>RoomGetCarousel</gcmd><gdata><gip><version>1</version><token>".TOKEN."</token><fields>name,image,imageurl,control,power,product,class,realtype,status</fields></gip></gdata></gwrcmd></gwrcmds>&fmt=xml";
$result = getCurlReturn($CMD);
$array = xmlToArray($result);
if( !isset($array["gwrcmd"]) ){
exit;
}
$DEVICES = array();
if( isset( $array["gwrcmd"]["gdata"]["gip"]["room"] ) ){
$DATA = $array["gwrcmd"]["gdata"]["gip"]["room"];
}else{
exit;
}
if( sizeof($DATA) > 0 ){
if ( isset( $DATA["rid"] ) ){ $DATA = array( $DATA ); }
foreach($DATA as $room){
if( isset($room['rid'] ) ){
if( ! is_array($room["device"]) ){
}else{
$device = (array)$room["device"];
if( isset($device["did"]) ){
$DEVICES[] = $device["did"];
}else{
for( $x = 0; $x < sizeof($device); $x++ ){
if( isset($device[$x]) && is_array($device[$x]) && ! empty($device[$x]) ){
$DEVICES[] = $device[$x]["did"];
}
}
}
}
}
}
}
return $DEVICES;
}
$BASE_DEVICES = getDeviceIDs();
$NOW_DEVICES = array();
ob_flush();
flush ();
echo '<div class="roomContainer" style="padding: 20px;">';
echo "<p>Current State: ".sizeof($BASE_DEVICES)." Devices.</p>";
echo "<p>Searching for new devices...</p>";
$CMD = "cmd=GatewayInclusionStart&data=<gip><version>1</version><token>".TOKEN."</token></gip>";
$result = getCurlReturn($CMD);
$array = xmlToArray($result);
echo "<p>";
for( $x = 0; $x < 10; $x ++ ){
$CMD = "cmd=GatewayInclusionProgressGet&data=<gip><version>1</version><token>".TOKEN."</token></gip>";
$result = getCurlReturn($CMD);
$array = xmlToArray($result);
echo ".";
ob_flush();
flush ();
sleep (1);
}
echo "</p>";
ob_flush();
flush ();
$CMD = "cmd=GatewayInclusionStop&data=<gip><version>1</version><token>".TOKEN."</token></gip>";
$result = getCurlReturn($CMD);
$array = xmlToArray($result);
sleep (5);
$NOW_DEVICES = getDeviceIDs();
if( sizeof($NOW_DEVICES) > sizeof($BASE_DEVICES) ){
echo "<p><b>FOUND ". ( $BASE_COUNT - sizeof($BASE_DEVICES) ). " Devices</p>";
pa( array_diff($BASE_DEVICES, $NOW_DEVICES) );
}
echo "<p>Final Result: ".sizeof($NOW_DEVICES).". You may need to run this more than once to discover the bulbs. They will be auto-added to your system. </p>";
//pa( $NOW_DEVICES);
echo '</div>';
pageFooter();
?>