private function TestGateway() { $timeout = 1; $commandport = 48899; $result = true; $msg = "Link_Wi-Fi"; $msgreply = "/.+[.].+[.].+[.].+,[a-zA-Z0-9]{12}/"; // regex check, valid is a response of "<IP address>,<MAC address>," e.g. "192.168.1.111,AABB00112233," if (strcasecmp($this->ReadPropertyString('ValueCIP'), "255.255.255.255") != 0) { try { $handle = @fsockopen("udp://".$this->ReadPropertyString('ValueCIP'), $commandport, $errno, $errstr, $timeout); if (!$handle) { $result = false; } else { socket_set_timeout($handle, $timeout); for ($count=0; $count < $this->CommandRepeat; $count++) { $write = fwrite($handle, $msg); ips_sleep(50); } $read = fread($handle, 255); if (!preg_match($msgreply, $read)) $result = false; fclose($handle); } } catch (Exception $e) { $result = false; } } if (!$result) { $this->SetStatus(201); IPS_LogMessage("milight", "socket error"); } else { $this->SetStatus(102); } }
/** * @public * * Senden von Daten * * @param string $string - Daten, die gesendet werden sollen */ public function SendText($string){ // Translate special Characters $string = str_replace("Ä", "\x8E", $string); $string = str_replace("ä", "\x84", $string); $string = str_replace("Ö", "\x99", $string); $string = str_replace("ö", "\x94", $string); $string = str_replace("ü", "\x81", $string); $string = str_replace("Ü", "\x9A", $string); $string = str_replace("ß", "\xE1", $string); //$string = str_replace(",", "\xFB", $string); $string = str_replace("°", "\xF8", $string); // Build Message $string = chr(17).chr(strlen($string)).$string; //Build Message <DC1><Len><DataBytes> $checkSum = 0; // Calc Checksum for($i = 0; $i < strlen($string); $i++) { $checkSum = $checkSum + ord(substr($string, $i, 1)); } $string .= chr($checkSum % 256); //IPSLogger_Com(__file__,'Send Msg to EDIP: '.$string); RegVar_SendText($this->registerId, $string); ips_sleep($this->sendDelay); }