PHP Control – senden – empfangen

Niedrig
Erledigt
Erweiterung Software
Server
4.099
Xsolution

Der Server kann nun durch PHP SSL/https gesteuert werden.

Mit diesen Funktionen lassen sich alle Geräte welche nicht in Xhome implementiert sind steuern. Alle Geräte welche per PHP ansteuerbar sind,  können somit in Xhome eingebunden werden.

Beispiel STATE eines RGB Datenpunkt setzen:

<?php

				$dp_Name = "2:RGB Wifi";
				$dp_Type = "RGB_LIGTH";
				$Attribute = "STATE";
				$Attribute_Value = "1.0";
				$command = "Set_Attributte";

				$service_port = 3425;
				$address = gethostbyname('localhost');
				$socket = fsockopen("ssl://".$address, $service_port, $errno, $errstr, 2);
				stream_set_timeout($socket, 5);

				if ($socket) {

				 $message = fread($socket, 1024);

				 $reader = new XMLReader();
				 $reader->xml($message);

		   		 	while ( $reader->read() ) {
				 	 	if (  $reader->nodeType ==XMLReader::ELEMENT ) {
					   		 if($reader->name == 'res:security'){
					   		  $Random = $reader->readString() ;
					   		 }
					  	}
					}

				$Random_Key_Server = rand(0,100);
				(int) $ValueKey = substr($Random, 3, 1).substr($Random, 1, 1).substr($Random, 6, 1).substr($Random, 7, 1).substr($Random, 0, 1);
			    $Response_Generated_Key = ((int)$ValueKey) * $Random_Key_Server;
			     $Key = '<request xsi:schemaLocation="/ls24/mcs/xmladapter/extern/request file:/request.xsd" xmlns:mcom="/ls24/mcs/xmladapter/extern/common" xmlns="/ls24/mcs/xmladapter/extern/request" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><prefix>'.$Random_Key_Server.'</prefix><suffix>'.$Response_Generated_Key.'</suffix><user>PHP_Control</user><uuid>PHP_Control</uuid><noinit>true</noinit><getRequest_after_command>true</getRequest_after_command></request>';
		         $length=pack("n",strlen($Key));

		         fwrite($socket,$length.$Key,strlen($Key)+2);

				    $message = fread($socket, 1024);

					$Kommando = '<request xsi:schemaLocation="/ls24/mcs/xmladapter/extern/request file:/request.xsd" xmlns:mcom="/ls24/mcs/xmladapter/extern/common" xmlns="/ls24/mcs/xmladapter/extern/request" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><timestamp>2011-09-29T21:59:11</timestamp><command><id>'.$Attribute.'</id><dataPoint><mcom:name>'.$dp_Name.'</mcom:name><mcom:type>'.$dp_Type.'</mcom:type></dataPoint><command>'.$command.'</command><parameter>'.$Attribute_Value.'</parameter></command><close_after_command>true</close_after_command><noinit>true</noinit></request>';

					$length=pack("n",strlen($Kommando));
		            fwrite($socket,$length.$Kommando,strlen($Kommando)+2);

				}	

?>

 

Kommando an Server senden (Für Siri Logik Baustein), im Beispiel wird auf Pin und Handys geprüft:

 

<html>
<head>

		<meta charset="UTF-8" />
		<title>Befehl 1</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
        <link rel="apple-touch-icon-precomposed" sizes="114x114" href="Logo4.png" />
		<link rel="shortcut icon" href="favicon.ico">

</head>
<body>

<?php

if(strtolower($_SERVER['REQUEST_METHOD']) == 'post') { 
	$id = $_POST['id'];		
 }
if(strtolower($_SERVER['REQUEST_METHOD']) == 'get') { 
	$id = $_GET['id'];			
 }

$mobile = detect_mobile();

if($mobile === true &&  $id == '56987'){

		error_reporting(0);

				$result = 'error';
				$service_port = 3425;
				$address = gethostbyname('localhost');
				$siri = 'Kom_1';

				$socket = fsockopen("ssl://".$address, $service_port, $errno, $errstr, 2);

				stream_set_timeout($socket, 5);

				if ($socket) {

					$message = fread($socket, 1024);

				 $reader = new XMLReader();
				 $reader->xml($message);

		   		 	while ( $reader->read() ) {
				 	 	if (  $reader->nodeType ==XMLReader::ELEMENT ) {
					   		 if($reader->name == 'res:security'){
					   		  $Random = $reader->readString() ;
					   		 }
					  	}
					}

				$Random_Key_Server = rand(0,100);
				(int) $ValueKey = substr($Random, 3, 1).substr($Random, 1, 1).substr($Random, 6, 1).substr($Random, 7, 1).substr($Random, 0, 1);
			    $Response_Generated_Key = ((int)$ValueKey) * $Random_Key_Server;
			     $Key = '<request xsi:schemaLocation="/ls24/mcs/xmladapter/extern/request file:/request.xsd" xmlns:mcom="/ls24/mcs/xmladapter/extern/common" xmlns="/ls24/mcs/xmladapter/extern/request" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><prefix>'.$Random_Key_Server.'</prefix><suffix>'.$Response_Generated_Key.'</suffix><user>PHP_Control</user><uuid>PHP_Control</uuid><noinit>true</noinit><getRequest_after_command>true</getRequest_after_command></request>';
		         $length=pack("n",strlen($Key));

		         fwrite($socket,$length.$Key,strlen($Key)+2);

				  $message = fread($socket, 1024);

					$Kommando = '<request xsi:schemaLocation="/ls24/mcs/xmladapter/extern/request file:/request.xsd" xmlns:mcom="/ls24/mcs/xmladapter/extern/common" xmlns="/ls24/mcs/xmladapter/extern/request" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><timestamp>2011-09-29T21:59:11</timestamp><command><id>0815</id><dataPoint><mcom:name>SIRI</mcom:name><mcom:type>SIRI</mcom:type></dataPoint><command>'.$siri.'</command></command><close_after_command>true</close_after_command><noinit>true</noinit></request>';

					$length=pack("n",strlen($Kommando));
		            fwrite($socket,$length.$Kommando,strlen($Kommando)+2);

				}	

	}

	function detect_mobile()
	{
		if(preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $_SERVER['HTTP_USER_AGENT']))
			return true;

		else
			return false;
	}
?>

<script type="text/javascript">

var conf = confirm("Fenster schließen?");

if(conf == true){

	var win = window.open("","_self"); 
	win.close();

}

</script>
</body></html>

 

 

Kommandos vom Server empfangen und weiter verwenden (host ist hier ein Wifi RGB Controller)-   inkl. Kommando + Kommando Parameter falls verfügbar + Status aller anderen Attributen des DP:

(Xsolution Xhome-Server – „Konfiguration“ – „Datenpunkt Name/Einheit“ – „PHP Kommando Notif. URL“   hier url eintragen)

<?
error_reporting(1);
$host = "192.168.111.129";

if(strtolower($_SERVER['REQUEST_METHOD']) == 'post') { 

	foreach ($_POST as $VarName=>$VarValue)
	{
		${"_".$VarName}=$VarValue;
	};

 }
if(strtolower($_SERVER['REQUEST_METHOD']) == 'get') { 

	foreach ($_GET as $VarName=>$VarValue)
	{
		${"_".$VarName}=$VarValue;

	}; 	

 }

if($_VALUE_RED == 100){ $_VALUE_RED = "ff";}
if($_VALUE_GREEN == 100){ $_VALUE_GREEN = "ff";}
if($_VALUE_BLUE == 100){ $_VALUE_BLUE = "ff";}

if($_commandName == "SWITCH_ON"){

	fwrite(fsockopen("tcp://$host", 5577), "\xcc\x23\x33");	
	fwrite(fsockopen("tcp://$host", 5577), "\x56".chr(hexdec("ff")) . chr(hexdec("ff")) . chr(hexdec("ff"))."\xaa");	
}
else if($_POST["commandName"] == "SWITCH_OFF"){

	fwrite(fsockopen("tcp://$host", 5577), "\xcc\x24\x33");
}
else if($_commandName == "SET_VALUE_RED"){
	if($_commandValue == 100){ $_commandValue = "ff";}
    fwrite(fsockopen("tcp://$host", 5577), "\xcc\x23\x33");
	fwrite(fsockopen("tcp://$host", 5577), "\x56".chr(hexdec($_commandValue)) . chr(hexdec($_VALUE_GREEN)) . chr(hexdec($_VALUE_BLUE))."\xaa");

}
else if($_commandName == "SET_VALUE_GREEN"){
	if($_commandValue == 100){ $_commandValue = "ff";}
    fwrite(fsockopen("tcp://$host", 5577), "\xcc\x23\x33");
	fwrite(fsockopen("tcp://$host", 5577), "\x56".chr(hexdec($_VALUE_RED)) . chr(hexdec($_commandValue)) . chr(hexdec($_VALUE_BLUE))."\xaa");

}
else if($_commandName == "SET_VALUE_BLUE"){
	if($_commandValue == 100){ $_commandValue = "ff";}
    fwrite(fsockopen("tcp://$host", 5577), "\xcc\x23\x33");
	fwrite(fsockopen("tcp://$host", 5577), "\x56".chr(hexdec($_VALUE_RED)) . chr(hexdec($_VALUE_GREEN)) . chr(hexdec($_commandValue))."\xaa");

}

fclose();

echo "ok" ;

?>

 

Beispiel: https://xsolution.de/forum/xsolution-forum-group5/updates-forum12/rgb-led-strip-anbindung-neuer-günstiger-wifi-controller-xhome-thread800/

 

 

Bei Änderung eines Datenpunkt PHP informieren:

(Xsolution Xhome-Server – „Konfiguration“ – „Datenpunkt Verhalten“ – „Update URL“   hier php url eintragen)

Schreibrechte müssen gesetzt sein, Textdatei mit den Variablen wird dabei erzeugt.

<?php

 $distributorMessage = "";  
 $ResponseMessage = "";  

if(strtolower($_SERVER['REQUEST_METHOD']) == 'post') { 

foreach ($_POST as $VarName=>$VarValue)
{
		$distributorMessage = $distributorMessage." $VarName=$VarValue ";
};

 }
  if(strtolower($_SERVER['REQUEST_METHOD']) == 'get') { 

foreach ($_GET as $VarName=>$VarValue)
{
		$distributorMessage = $distributorMessage." $VarName=$VarValue ";
}; 	

 }

 $myFile = "noti.txt";
 $fh = fopen($myFile, 'a') or die("can't open file");
 fwrite($fh, $distributorMessage." \n");
 fclose($fh);

echo "true";

?>

 

 

WordPress-Datenbank-Fehler: [Unknown column '4311comments.comment_ID' in 'field list']
SELECT SQL_CALC_FOUND_ROWS 4311comments.comment_ID FROM 4311comments AS wp1 LEFT JOIN 4311posts AS wp3 ON wp1.comment_post_id = wp3.ID WHERE ( wp1.comment_approved = '1' ) AND wp1.comment_post_ID = 6931 AND wp3.post_status = 'publish' AND NOT EXISTS (SELECT * FROM 4311commentmeta AS wp2 WHERE wp1.comment_ID = wp2.comment_id AND wp2.meta_key = 'wats_internal_update' AND wp2.meta_value = 1) ORDER BY 4311comments.comment_date_gmt ASC, 4311comments.comment_ID ASC

Leave a Reply