S1_Main.requestStatus
if(!isset($bridge)) {return;}
$ip = gg($bridge.'.IP');
$port = gg($bridge.'.Port');
$mac = $this->getProperty('deviceMAC');
$sensorsStr = $this->getProperty('connectedSensors');
$sensors = explode(",", $sensorsStr);
if(!$sensors || count($sensors) == 0) {return;}
$ctx = stream_context_create(array(
'http' => array('timeout'=>1)
)
);
//sensors status
$response = file_get_contents('http://'.$ip.':'.$port.'/?devMAC='.$mac, 0, $ctx);
if(isset($response) && $response!='') {
$json = json_decode($response);
$sensorsStatus = $json->{'sensorsList'};
for($i=0; $i<count($sensorsStatus); $i++) {
for($j=0; $j<count($sensors); $j++) {
if(gg($sensors[$j].'.index') == $sensorsStatus[$i]->{'index'}){
sg($sensors[$j].'.status', (int)$sensorsStatus[$i]->{'status'});
}
}
}
}
if(!isset($bridge)) {return;}
$ip = gg($bridge.'.IP');
$port = gg($bridge.'.Port');
$mac = $this->getProperty('deviceMAC');
$ctx = stream_context_create(array(
'http' => array('timeout'=>3)
)
);
//S1 defence
$response = file_get_contents('http://'.$ip.':'.$port.'/?devMAC='.$mac.'&action=defence', 0, $ctx);
if(isset($response) && $response!='') {
$json = json_decode($response);
$this->setProperty('defence', (int)$json->{'systemDefence'});
}
if(!isset($bridge)) {return;}
$ip = gg($bridge.'.IP');
$port = gg($bridge.'.Port');
$mac = $this->getProperty('deviceMAC');
$sensorsStr = $this->getProperty('connectedSensors');
$sensors = explode(",", $sensorsStr);
if(!$sensors || count($sensors) == 0) {return;}
$ctx = stream_context_create(array(
'http' => array('timeout'=>2)
)
);
//sensors alarm
$response = file_get_contents('http://'.$ip.':'.$port.'/?devMAC='.$mac.'&action=alarm', 0, $ctx);
if(isset($response) && $response!='') {
$json = json_decode($response);
$sensorsStatus = $json->{'sensorsAlarm'};
$s1Alarm = 0;
for($i=0; $i<count($sensorsStatus); $i++) {
for($j=0; $j<count($sensors); $j++) {
if(gg($sensors[$j].'.index') == $sensorsStatus[$i]->{'index'}){
sg($sensors[$j].'.alarm', (int)$sensorsStatus[$i]->{'alarm'});
if($sensorsStatus[$i]->{'alarm'} == 1) {
$s1Alarm = 1;
}
}
}
}
$this->setProperty('alarm', (int)$s1Alarm);
}