|
![]() |
![]() |
![]() |
![]() |
Sie können ein PHP Skript auslösen, sobald ein Datenpunkte angesteuert wird.
Im Xhome Server unter "Konfiguration" - "Datenpunkt Name / Einheit" geben Sie hierzu das PHP Skript an.
Anbei ein Beispiel PHP Skript:
<?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 "; };
}
echo $distributorMessage;
$myFile = "noti.txt"; $fh = fopen($myFile, 'a') or die("can't open file"); fwrite($fh, $distributorMessage." \n"); fclose($fh);
echo "true";
?>
Dieses PHP Skript legt eine Textdatei an. Hierfür benötigen Sie Schreibrechte auf den Ordner worin das Skript liegt.
Als Beispiel wurde ein Licht aus geschaltet:
Ausgabe im Text Dokument:
commandName=SWITCH_OFF STATE=true dp_Name=2:Aussenbel_alter_Eingang dp_Type=SWITCH:LICHT
Der Server übergibt folgende Parameter: commandName , dp_Name und dp_Type.
Beispiel Ausgabe beim ansteuern eines RGB Licht:
commandName=SET_VALUE_BLUE commandValue=20 VALUE_GREEN=0.0 VALUE_BLUE=0.0 STATE=false VALUE_RED=0.0 dp_Name=1:RGB dp_Type=RGB_LIGTH
So könnte man z.B. die Variablen abgreifen:
<? 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;
};
}
$_VALUE_RED = str_replace(".0", "", $_VALUE_RED ); $_VALUE_GREEN = str_replace(".0", "", $_VALUE_GREEN ); $_VALUE_BLUE = str_replace(".0", "", $_VALUE_BLUE ); $_commandValue = str_replace(".0", "", $_commandValue );
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($_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" ;
?>
|