Skip to content

Commit

Permalink
Update magichome.class.php
Browse files Browse the repository at this point in the history
  • Loading branch information
directman66 committed Sep 7, 2018
1 parent 193b255 commit 0f45bd1
Showing 1 changed file with 61 additions and 7 deletions.
68 changes: 61 additions & 7 deletions modules/magichome/magichome.class.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -309,12 +309,65 @@ function scan() {
$str = 'HF-A11ASSISTHREAD'; $str = 'HF-A11ASSISTHREAD';




$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); $cs = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1);
socket_sendto($sock, $str, strlen($str), 0, $ip, $port); if(!$cs){
socket_recvfrom($sock, $buf,100 , 0, $ip, $port); echo "error socket";
usleep(100); }
socket_close($sock);
socket_set_option($cs, SOL_SOCKET, SO_REUSEADDR, 1);
socket_set_option($cs, SOL_SOCKET, SO_BROADCAST, 1);
socket_set_option($cs, SOL_SOCKET, SO_RCVTIMEO, array('sec'=>1, 'usec'=>0));
socket_bind($cs, 0, 0);

socket_sendto($cs, $str, strlen($str), 0, $ip, $port);
//socket_recvfrom($sock, $buf,100, 0, $ip, $port);
while(socket_recvfrom($cs, $buf, 2048, 0, $ip, $port)){

sg('test.buf',$buf);



if($buf != NULL){
if ($ip) {

$par=explode(",",$buf);

$mhdevices=SQLSelect("SELECT * FROM magichome_devices where MAC='".$par[1]."' and IP='$ip'");
if ($mhdevices[0]['ID']) {} else

{ $mhdevices=SQLSelect("SELECT max(ID) ID FROM magichome_devices");
if ($mhdevices[0]['ID']) {
$id=$mhdevices[0]['ID']+1;} else $id=0;


$par['ID'] = $id;
//$par['TITLE'] = 'RGB LED';

$par['TITLE'] = $par[2];
$par['IP'] = $ip;
$par['PORT'] = $port;
$par['MAC'] = $par[1];
$par['FIND'] = date('m/d/Y H:i:s',time());
SQLInsert('magichome_devices', $par);
}
}
}
}

@socket_shutdown($cs, 2);
socket_close($cs);





//$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
//socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1);
//socket_sendto($sock, $str, strlen($str), 0, $ip, $port);
//socket_recvfrom($sock, $buf,100 , 0, $ip, $port);
//usleep(100);
//socket_close($sock);


// $buf = null; // $buf = null;
// $data = null; // $data = null;
Expand Down Expand Up @@ -355,6 +408,7 @@ function scan() {
//$lead_byte = #0x51 //$lead_byte = #0x51
//sg('test.magichome',$buf .":".$ip.":".$port); //sg('test.magichome',$buf .":".$ip.":".$port);


/*
if ($ip) { if ($ip) {
$par=explode(",",$buf); $par=explode(",",$buf);
Expand All @@ -378,7 +432,7 @@ function scan() {
SQLInsert('magichome_devices', $par); SQLInsert('magichome_devices', $par);
} }
} }

*/






Expand Down

0 comments on commit 0f45bd1

Please sign in to comment.