Das folgende Skript ermöglicht das Lesen der Eingänge des IPswitch-SG Gerät.
Infos / Hersteller: SMS-GUARD, Überwachen und Schalten mit dem Handy per SMS - europaweit, SMS Alarm, GSM Alarm, m2m, Warnsystem für Privathandys, Warnsystem für Notfälle
//Hier die IP-Adresse des Geräts eintragen und per Excute das Skript ausführen //um die Installation zu vollziehen. Es wird automatisch ein Timer angelegt, //der alle 5 Minuten das Gerät abfragt.
$ip = "192.168.2.82";
//Ab hier nichts mehr ändern
$object = IPS_GetObject($IPS_SELF);
$parentID = $object['ParentID'];
//Installer
if ($IPS_SENDER == "Execute") {
IPS_SetHidden($IPS_SELF, true);
IPS_SetName($IPS_SELF, "Auslese-Skript");
$parentObject = IPS_GetObject($parentID);
if ($parentObject['ObjectType'] !== 1)
{
$instanceID = IPS_CreateInstance("{485D0419-BE97-4548-AA9C-C083EB82E61E}");
IPS_SetParent($instanceID, $parentID);
$parentID = $instanceID;
IPS_SetParent($IPS_SELF, $parentID);
IPS_SetName($instanceID, "IPSwitchSG");
}
IPS_SetScriptTimer($IPS_SELF, 300);
}
$data = file_get_contents("http://$ip/csv.html");
$lines = explode(",", strip_tags($data));
SetValue(CreateVariableByName($parentID, "iC1", 0), $lines[1] > 0);
SetValue(CreateVariableByName($parentID, "iC2", 0), $lines[2] > 0);
SetValue(CreateVariableByName($parentID, "iC3", 0), $lines[3] > 0);
SetValue(CreateVariableByName($parentID, "iE1", 0), $lines[4] > 0);
SetValue(CreateVariableByName($parentID, "iE2", 0), $lines[5] > 0);
SetValue(CreateVariableByName($parentID, "iTi Exceed", 0), $lines[6] > 0);
SetValue(CreateVariableByName($parentID, "iTe Exceed", 0), $lines[7] > 0);
SetValue(CreateVariableByName($parentID, "i10V Exceed", 0), $lines[8] > 0);
SetValue(CreateVariableByName($parentID, "iTi", 2, "~Temperature"), str_replace(".", ",", $lines[9]));
SetValue(CreateVariableByName($parentID, "iTe", 2, "~Temperature"), str_replace(".", ",", $lines[10]));
SetValue(CreateVariableByName($parentID, "i10V", 2), str_replace(".", ",", $lines[11]));
SetValue(CreateVariableByName($parentID, "oC1", 0), $lines[12] > 0);
SetValue(CreateVariableByName($parentID, "oC2", 0), $lines[13] > 0);
SetValue(CreateVariableByName($parentID, "oE1", 0), $lines[14] > 0);
SetValue(CreateVariableByName($parentID, "oE2", 0), $lines[15] > 0);
$data = file_get_contents("http://$ip/cnt.html");
$pos = strpos($data, "iC1= ");
SetValue(CreateVariableByName($parentID, "iCnt1", 1), substr($data, $pos+5, strpos($data, ",", $pos)-$pos-5));
$pos = strpos($data, "iC2= ");
SetValue(CreateVariableByName($parentID, "iCnt2", 1), substr($data, $pos+5, strpos($data, " <", $pos)-$pos-5));
$pos = strpos($data, "iC3= ");
SetValue(CreateVariableByName($parentID, "iCnt3", 1), substr($data, $pos+5, strpos($data, " <", $pos)-$pos-5));
function CreateVariableByName($id, $name, $type, $profile = "") {
global $IPS_SELF;
$vid = @IPS_GetVariableIDByName($name, $id);
if($vid === false) {
$vid = IPS_CreateVariable($type);
IPS_SetParent($vid, $id);
IPS_SetName($vid, $name);
IPS_SetInfo($vid, "this variable was created by script #$IPS_SELF");
if($profile !== "") { IPS_SetVariableCustomProfile($vid, $profile); }
}
return $vid;
}
Zum Schalten können folgende Befehle verwendet werden:
(bitte die IP-Adresse anpassen)
//Zum Schalten können diese Befehle kopiert werden
file_get_contents("http://192.168.2.82/?oCA=1"); //oC1 AN
file_get_contents("http://192.168.2.82/?oCA=0"); //oC1 AUS
file_get_contents("http://192.168.2.82/?oC1=1"); //oC2 AN
file_get_contents("http://192.168.2.82/?oC1=0"); //oC2 AUS
file_get_contents("http://192.168.2.82/?oE1=1"); //oE1 AN
file_get_contents("http://192.168.2.82/?oE1=0"); //oE1 AUS
file_get_contents("http://192.168.2.82/?oE2=1"); //oE1 AN
file_get_contents("http://192.168.2.82/?oE2=0"); //oE1 AUS
file_get_contents("http://192.168.2.82/?res1"); //Reset CNT1
file_get_contents("http://192.168.2.82/?res2"); //Reset CNT2
file_get_contents("http://192.168.2.82/?res3"); //Reset CNT3
MST