Exemplo n.º 1
1
 protected function Send_LED($address, $command)
 {
     $ip_aiogateway = $this->GetIPGateway();
     $GatewayPassword = $this->GetPassword();
     IPS_LogMessage("IP AIO Gateway:", $ip_aiogateway);
     IPS_LogMessage("LED Adresse:", $address);
     IPS_LogMessage("LED Command:", $command);
     if ($GatewayPassword !== "") {
         $gwcheck = file_get_contents("http://" . $this->GetIPGateway() . "/command?XC_USER=user&XC_PASS="******"&XC_FNC=SendSC&type=L2&data=" . $address . $command);
     } else {
         $gwcheck = file_get_contents("http://" . $this->GetIPGateway() . "/command?XC_FNC=SendSC&type=L2&data=" . $address . $command);
     }
     if ($gwcheck == "{XC_SUC}") {
         $this->response = true;
     } elseif ($gwcheck == "{XC_AUTH}") {
         $this->response = false;
         echo "Keine Authentifizierung möglich. Das Passwort für das Gateway ist falsch.";
     }
     return $this->response;
 }
Exemplo n.º 2
1
 protected function SendCommand($address)
 {
     $address = $this->ReadPropertyString('Adresse');
     IPS_LogMessage("Adresse:", $address);
     IPS_LogMessage("Dooya Command:", $command);
     $GatewayPassword = $this->GetPassword();
     if ($GatewayPassword !== "") {
         $gwcheck = file_get_contents("http://" . $this->GetIPGateway() . "/command?XC_USER=user&XC_PASS="******"&XC_FNC=SendSC&type=RT&data=" . $command . $address);
     } else {
         $gwcheck = file_get_contents("http://" . $this->GetIPGateway() . "/command?XC_FNC=SendSC&type=RT&data=" . $command . $address);
     }
     if ($gwcheck == "{XC_SUC}") {
         $this->response = true;
     } elseif ($gwcheck == "{XC_AUTH}") {
         $this->response = false;
         echo "Keine Authentifizierung möglich. Das Passwort für das Gateway ist falsch.";
     }
     return $this->response;
 }
Exemplo n.º 3
1
 /**
  * Log Message
  * @param string $Message
  */
 protected function Log($Message)
 {
     if ($this->ReadPropertyBoolean("Log")) {
         IPS_LogMessage(__CLASS__, $Message);
     }
 }
Exemplo n.º 4
0
 public function ProcessHookData()
 {
     if ($_IPS['SENDER'] == "Execute") {
         echo "This script cannot be used this way.";
         return;
     }
     if (!isset($_POST['deviceName']) || !isset($_POST['deviceType']) || !isset($_POST['deviceFamily'])) {
         IPS_LogMessage("ips4WinDeviceRegistration", "Malformed data: " . print_r($_POST, true));
         return;
     }
     $id = str_replace("-", "", utf8_decode($_POST['deviceName']) . utf8_decode($_POST['deviceId']));
     $id = str_replace(" ", "", $id);
     $deviceID = $this->CreateInstanceByIdent($this->InstanceID, $id, utf8_decode($_POST['deviceName']) . "-" . utf8_decode($_POST['deviceId']));
     SetValue($this->CreateVariableByIdent($deviceID, "deviceName", "deviceName", 3), utf8_decode($_POST['deviceName']));
     SetValue($this->CreateVariableByIdent($deviceID, "deviceType", "deviceType", 3), utf8_decode($_POST['deviceType']));
     SetValue($this->CreateVariableByIdent($deviceID, "deviceId", "deviceId", 3), utf8_decode($_POST['deviceId']));
     SetValue($this->CreateVariableByIdent($deviceID, "deviceFamily", "deviceFamily", 3), utf8_decode($_POST['deviceFamily']));
     if (isset($_POST['SecChannel'])) {
         SetValue($this->CreateVariableByIdent($deviceID, "SecChannelExp", "SecChannelExp", 1, "~UnixTimestamp"), intval(strtotime($_POST['SecChannelExp'])));
         SetValue($this->CreateVariableByIdent($deviceID, "SecChannel", "SecChannel", 3), utf8_decode($_POST['SecChannel']));
         SetValue($this->CreateVariableByIdent($deviceID, "AccessToken", "AccessToken", 3), utf8_decode($_POST['AccessToken']));
     }
     if (isset($_POST['geoID'])) {
         $geoIDName = str_replace("-", "", utf8_decode($_POST['geoID']));
         $geoIDName = str_replace(" ", "", $geoIDName);
         $idGeofences = $this->CreateCategoryByIdent($deviceID, "Geofences", "Geofences");
         $idGeofence = $this->CreateInstanceByIdent($idGeofences, $geoIDName, utf8_decode($_POST['geoID']));
         //SetValue($this->CreateVariableByIdent($idGeofence, "Latitude", "Latitude", 2), floatval($_POST['Latitude']));
         //SetValue($this->CreateVariableByIdent($idGeofence, "Longitude", "Longitude", 2), floatval($_POST['Longitude']));
         SetValue($this->CreateVariableByIdent($idGeofence, "Timestamp", "Timestamp", 1, "~UnixTimestamp"), intval(strtotime($_POST['date'])));
         SetValue($this->CreateVariableByIdent($idGeofence, "LocationState", "Status", 0, "~Presence"), intval($_POST['geoPresence']) > 0);
     }
 }
Exemplo n.º 5
0
 public function ProcessHookData()
 {
     if ($_IPS['SENDER'] == "Execute") {
         echo "This script cannot be used this way.";
         return;
     }
     if (!isset($_POST['ips4Command'])) {
         IPS_LogMessage("ips4WinCortana", "Malformed data: " . print_r($_POST, true));
         return;
     }
     if ($_POST['ips4Command'] == "GetConfig") {
         $vid = @IPS_GetObjectIDByIdent("ips4WinCortanaVoiceCommands", $this->InstanceID);
         if ($vid === false) {
             echo "ERROR: Variable ips4WinCortanaVoiceCommands not found in IPS, please check installation of instance \"ips4WinCortana\"!";
         } else {
             $ret = GetValueString($vid);
             if ($ret == "") {
                 $ret = "ERROR: ips4WinCortanaVoiceCommands has no entries, please check script \"ipsWinCortanaSprachbefehle\" and don't forget to start the script!";
             }
             echo $ret;
         }
     } elseif ($_POST['ips4Command'] == "Data") {
         $this->Result = $_POST;
     }
 }
Exemplo n.º 6
0
 /**
  * This function will be available automatically after the module is imported with the module control.
  * Using the custom prefix this function will be callable from PHP and JSON-RPC through:
  *
  * LOCATIVE_ProcessHookData($id);
  *
  */
 public function ProcessHookData()
 {
     if ($_IPS['SENDER'] == "Execute") {
         echo "This script cannot be used this way.";
         return;
     }
     if (IPS_GetProperty($this->InstanceID, "Username") != "" || IPS_GetProperty($this->InstanceID, "Password") != "") {
         if (!isset($_SERVER['PHP_AUTH_USER'])) {
             $_SERVER['PHP_AUTH_USER'] = "";
         }
         if (!isset($_SERVER['PHP_AUTH_PW'])) {
             $_SERVER['PHP_AUTH_PW'] = "";
         }
         if ($_SERVER['PHP_AUTH_USER'] != IPS_GetProperty($this->InstanceID, "Username") || $_SERVER['PHP_AUTH_PW'] != IPS_GetProperty($this->InstanceID, "Password")) {
             header('WWW-Authenticate: Basic Realm="Locative WebHook"');
             header('HTTP/1.0 401 Unauthorized');
             echo "Authorization required";
             return;
         }
     }
     /**
     			The following $_POST data are slightly different from Geofency
     			**/
     if (!isset($_POST['device']) || !isset($_POST['id']) || !isset($_POST['trigger'])) {
         IPS_LogMessage("Locative", "Malformed data: " . print_r($_POST, true));
         return;
     }
     $trigger = strtolower(isset($_POST["trigger"]) ? $_POST["trigger"] : "");
     $name = htmlentities(utf8_decode(isset($_REQUEST["name"]) ? $_REQUEST["name"] : "Home"));
     IPS_LogMessage("IPSLocative", print_r($_REQUEST, true));
     $deviceID = $this->CreateInstanceByIdent($this->InstanceID, $this->ReduceGUIDToIdent($_POST['device']), "Device");
     SetValue($this->CreateVariableByIdent($deviceID, "Latitude", "Latitude", 2), floatval($_POST['latitude']));
     SetValue($this->CreateVariableByIdent($deviceID, "Longitude", "Longitude", 2), floatval($_POST['longitude']));
     SetValue($this->CreateVariableByIdent($deviceID, "Time", "Time", 1, "~UnixTimestamp"), $_POST['timestamp']);
     SetValue($this->CreateVariableByIdent($deviceID, "LastTrigger", "LastTrigger", 3), $trigger);
     $varID = $this->CreateVariableByIdent($deviceID, $name, $name, 0, "~Presence");
     switch ($trigger) {
         case "enter":
             SetValue($varID, 1);
             echo "Welcome!";
             break;
         case "exit":
             SetValue($varID, 0);
             echo "Bye!";
             break;
         case "test":
             $status = isset($_GET["status"]) ? $_GET["status"] == "1" : false;
             echo "Test for {$name} received. Status {$status}";
             SetValue($varID, $status);
             break;
     }
 }
Exemplo n.º 7
0
function CheckSML($stream, $parentID)
{
    for ($i = 1; $i < count(EHz(0, 1)); $i++) {
        $var = stristr($stream, EHz($i, 1));
        if ($var != false) {
            CheckVariable(EHz($i, 0), EHz($i, 2), EHz($i, 3), $parentID);
            IPS_LogMessage('EHz', $i);
        } else {
            IPS_LogMessage('EHz <-> Port:', $stream);
        }
    }
    return true;
}
Exemplo n.º 8
0
 private function CheckParents()
 {
     $result = $this->HasActiveParent();
     if ($result) {
         $instance = IPS_GetInstance($this->InstanceID);
         $parentGUID = IPS_GetInstance($instance['ConnectionID'])['ModuleInfo']['ModuleID'];
         if ($parentGUID == '{61051B08-5B92-472B-AFB2-6D971D9B99EE}') {
             IPS_DisconnectInstance($this->InstanceID);
             IPS_LogMessage('XBee-ZigBee Gateway', 'XB-ZB Gateway has invalid Parent.');
             $result = false;
         }
     }
     return $result;
 }
Exemplo n.º 9
0
 public function ReceiveData($JSONString)
 {
     $data = json_decode($JSONString);
     //IPS_LogMessage('EHz <- Port:', bin2hex(utf8_decode($data->Buffer)));
     $stream = bin2hex(utf8_decode($data->Buffer));
     for ($i = 1; $i < EHz(0, 1); $i++) {
         $var = stristr($stream, EHz($i, 1));
         IPS_LogMessage('EHz', $i);
         if ($var != false) {
             CheckVariable(EHz($i, 0), EHz($i, 2), EHz($i, 3), $this->InstanceID);
             IPS_LogMessage('EHz', $i);
         } else {
             IPS_LogMessage('EHz <-> Port:', $stream);
         }
     }
     return true;
 }
Exemplo n.º 10
0
 public function GetClients()
 {
     $this->Login();
     $url = $this->baseURL . "/api/s/default/stat/sta";
     IPS_LogMessage("GetClients", print_r($this->ch, true));
     IPS_LogMessage("GetClients", $url);
     curl_setopt($this->ch, CURLOPT_URL, $url);
     curl_setopt($this->ch, CURLOPT_POST, 1);
     curl_setopt($this->ch, CURLOPT_POSTFIELDS, "json={}");
     $response = curl_exec($this->ch);
     IPS_LogMessage("GetClients", $response);
     $this->Logout();
     if ($response !== false) {
         return json_decode($response);
     } else {
         return 0;
     }
 }
Exemplo n.º 11
0
 /**
  * This function will be available automatically after the module is imported with the module control.
  * Using the custom prefix this function will be callable from PHP and JSON-RPC through:
  *
  * GEO_ProcessHookData($id);
  *
  */
 public function ProcessHookData()
 {
     //workaround for bug
     if (!isset($_IPS)) {
         global $_IPS;
     }
     if ($_IPS['SENDER'] == "Execute") {
         echo "This script cannot be used this way.";
         return;
     }
     if (!isset($_POST['device']) || !isset($_POST['id']) || !isset($_POST['name'])) {
         IPS_LogMessage("Geofency", "Malformed data: " . print_r($_POST, true));
         return;
     }
     $deviceID = $this->CreateInstanceByIdent($this->InstanceID, $this->ReduceGUIDToIdent($_POST['device']), "Device");
     SetValue($this->CreateVariableByIdent($deviceID, "Latitude", "Latitude", 2), floatval($_POST['latitude']));
     SetValue($this->CreateVariableByIdent($deviceID, "Longitude", "Longitude", 2), floatval($_POST['longitude']));
     SetValue($this->CreateVariableByIdent($deviceID, "Timestamp", "Timestamp", 1, "~UnixTimestamp"), intval(strtotime($_POST['date'])));
     SetValue($this->CreateVariableByIdent($deviceID, $this->ReduceGUIDToIdent($_POST['id']), utf8_decode($_POST['name']), 0, "~Presence"), intval($_POST['entry']) > 0);
 }
Exemplo n.º 12
0
 public function ApplyChanges()
 {
     // Diese Zeile nicht löschen
     parent::ApplyChanges();
     if (strlen($this->ReadPropertyString("API")) == 16) {
         //Instanz ist aktiv
         $this->SetStatus(102);
         //Script + Timer
         $UpdateInterval = $this->ReadPropertyInteger("UpdateInterval");
         IPS_LogMessage($_IPS['SELF'], "Update Interval " . $UpdateInterval . " Minuten");
         $UpdateWeatherScriptID = @$this->GetIDForIdent("_updateWeather");
         if ($UpdateWeatherScriptID === false) {
             $UpdateWeatherScriptID = $this->RegisterScript("_updateWeather", "_updateWeather", file_get_contents(__DIR__ . "/_updateWeather.php"), 99);
         } else {
             IPS_SetScriptContent($UpdateWeatherScriptID, file_get_contents(__DIR__ . "/_updateWeather.php"));
         }
         IPS_SetHidden($UpdateWeatherScriptID, true);
         IPS_SetScriptTimer($UpdateWeatherScriptID, $UpdateInterval);
     } else {
         //Instanz ist inaktiv
         $this->SetStatus(104);
     }
 }
Exemplo n.º 13
0
 /**
  * Startet den Timer bis zum Alarm
  *
  * @access private
  */
 private function StartTimer()
 {
     if (IPS_GetKernelRunlevel() != KR_READY) {
         return;
     }
     $this->ActiveVarID = 0;
     $NowTime = time();
     $LastTime = $NowTime + 98765;
     //init wert damit lasttime immer größer als aktuelle zeit
     $TriggerVarList = $this->NoTriggerVarList;
     foreach ($TriggerVarList->Items as $i => $IPSVars) {
         if (!IPS_VariableExists($IPSVars->VarId)) {
             continue;
         }
         if ($IPSVars->Alert === true) {
             continue;
         }
         $Variable = IPS_GetVariable($IPSVars->VarId);
         $TestTime = $Variable['VariableUpdated'];
         if ($TestTime + $this->ReadPropertyInteger('Timer') < $NowTime) {
             $TriggerVarList->Items[$i]->Alert = true;
             $this->Alerts++;
             if ($this->Alerts == 1) {
                 $this->SetStateVar(true, $IPSVars->VarId);
                 $this->DoScript($IPSVars->VarId, true, false);
             } else {
                 if ($this->ReadPropertyBoolean('MultipleAlert')) {
                     $this->DoScript($IPSVars->VarId, true, false);
                 }
             }
             continue;
         } else {
             if ($TestTime < $LastTime) {
                 $LastTime = $TestTime;
                 $this->ActiveVarID = $IPSVars->VarId;
             }
         }
     }
     $this->NoTriggerVarList = $TriggerVarList;
     if ($this->ActiveVarID == 0) {
         IPS_LogMessage('NoTrigger', 'Keine Var mehr in Ruhe. Überwachung pausiert');
         $this->StopTimer();
     } else {
         $TargetTime = $LastTime + $this->ReadPropertyInteger('Timer');
         $DiffTime = $TargetTime - $NowTime;
         $this->SetTimerInterval('NoTrigger', $DiffTime * 1000);
     }
 }
 /**
  * overloaded function to maintain variables and timer
  */
 protected function SetStatusVariables()
 {
     parent::SetStatusVariables();
     $caps = $this->GetCaps();
     if (count($caps) < 1) {
         return;
     }
     if (!isset($caps['Timer'])) {
         $tid = @IPS_GetEventIDByName("DeviceTimer", $this->InstanceID);
         if ($tid > 0) {
             IPS_LogMessage(__CLASS__, __FUNCTION__ . "Drop DeviceTimer ({$tid})");
             IPS_DeleteEvent($tid);
         }
     }
 }
Exemplo n.º 15
0
 public function ForwardData($JSONString)
 {
     $data = json_decode($JSONString);
     IPS_LogMessage('EmpfangChild', print_r($data, 1));
 }
Exemplo n.º 16
0
 public function SomfyCreateInstance(string $InstName, string $AIOSomfyAdresse, string $SomfyType, string $CategoryID)
 {
     //Prüfen ob Instanz schon existiert
     $InstanzID = @IPS_GetInstanceIDByName($InstName, $CategoryID);
     if ($InstanzID === false) {
         //echo "Instanz nicht gefunden!";
         //Neue Instanz anlegen
         $InsID = IPS_CreateInstance("{0F83D875-4737-4244-8234-4CF08E6F2626}");
         IPS_SetName($InsID, $InstName);
         // Instanz benennen
         IPS_SetParent($InsID, $CategoryID);
         // Instanz einsortieren unter dem Objekt mit der ID "$CategoryID"
         IPS_SetProperty($InsID, "Adresse", $AIOSomfyAdresse);
         //Adresse setzten.
         IPS_ApplyChanges($InsID);
         //Neue Konfiguration übernehmen
         IPS_LogMessage("Instanz erstellt:", "Name: " . $InstName);
         return $InsID;
     } else {
         //echo "Die Instanz-ID lautet: ". $InstanzID;
         return $InstanzID;
     }
 }
Exemplo n.º 17
0
function EncodeMonitorNormalData($Monitordaten, $ID, $Bus)
{
    $Bus = 1;
    $array = str_split($Monitordaten, 24);
    for ($x = 0; $x < count($array); $x++) {
        if (substr($array[$x], 0, 2) == 'a7') {
            $typ = ord(hex2bin(substr($array[$x], 8, 2)));
            if ($Bus === ord(hex2bin(substr($array[$x], 4, 2)))) {
                IPS_LogMessage('Buderus Logamatic', 'ECO-CAN Adresse ' . $Bus . ' Array: ' . $array[$x]);
                $offset = ord(hex2bin(substr($array[$x], 12, 2)));
                $substring = substr($array[$x], 16, 2);
                IPS_LogMessage('Buderus Logamatic', 'ECO-CAN Adresse ' . $Bus . ' Data: ' . $typ . ' : ' . $offset . ' : ' . $substring);
                $var = CheckVariable($typ, -1, 0, $ID);
                $value = GetValueString($var);
                $newvalue = substr_replace($value, $substring, $offset * 2, 2);
                SetValueString($var, $newvalue);
                EncodeVariableData($ID, $typ);
            } else {
                IPS_LogMessage('Logamatic Gateway', 'EncodeMonitorNormalData für falsche Bus-Adresse');
            }
        }
    }
    return true;
}
Exemplo n.º 18
0
 public function ReceiveData($JSONString)
 {
     $data = json_decode($JSONString);
     IPS_LogMessage("IOTest", utf8_decode($data->Buffer));
     //Parse and write values to our variables
 }
Exemplo n.º 19
0
 public function SetSleeptimer(integer $Minuten, string $Aktion, boolean $Aktiv)
 {
     if ($this->FeaturePreCheck("sleeptimer") === true) {
         $IP = $this->ReadPropertyString("Enigma2IP");
         $WebPort = $this->ReadPropertyInteger("Enigma2WebPort");
         if ($this->GetPowerState() == 1) {
             if ($Aktiv === true) {
                 $Aktiv = "True";
             } else {
                 $Aktiv = "False";
             }
             $url = "http://" . $IP . ":" . $WebPort . "/web/sleeptimer?cmd=set&time=" . $Minuten . "&action=" . $Aktion . "&enabled=" . $Aktiv;
             $xml = @simplexml_load_file($url);
             $E2_SleeptimerEnabled = $this->ResultAuswerten(trim($xml->e2enabled));
             $E2_SleeptimerMinuten = (int) trim($xml->e2minutes);
             $E2_SleeptimerAktion = (string) trim($xml->e2action);
             $E2_SleeptimerText = (string) trim($xml->e2text);
             $E2_SleeptimerInfo["SleeptimerAktiviert"] = $E2_SleeptimerEnabled;
             $E2_SleeptimerInfo["SleeptimerMinuten"] = $E2_SleeptimerMinuten;
             $E2_SleeptimerInfo["SleeptimerAktion"] = $E2_SleeptimerAktion;
             $E2_SleeptimerInfo["SleeptimerText"] = $E2_SleeptimerText;
             if ($this->ReadPropertyBoolean("ErwInformationen") == true) {
                 $this->SetValueBoolean("SleeptimerAktiviertVAR", $E2_SleeptimerEnabled);
                 $this->SetValueInteger("SleeptimerMinutenVAR", $E2_SleeptimerMinuten);
                 $this->SetValueString("SleeptimerAktionVAR", $E2_SleeptimerAktion);
             }
             return $E2_SleeptimerInfo;
         } else {
             return false;
         }
     } else {
         IPS_LogMessage("ENIGMA2BY", "Diese Funktion ist mit diesem Receiver/Image nicht verfügbar!");
     }
 }
Exemplo n.º 20
0
 protected function SetProperty($ident, $value)
 {
     IPS_SetProperty($this->InstanceID, $ident, $value);
     IPS_LogMessage(get_class($this), "SetProperty({$ident},{$value})");
 }
Exemplo n.º 21
0
 private function SendAPIData(ISCP_API_Data $APIData)
 {
     $DualType = substr($APIData->APICommand, 3, 1);
     $APIData->APICommand = substr($APIData->APICommand, 0, 3);
     if ($APIData->Mapping === null) {
         $APIData->GetMapping();
     }
     IPS_LogMessage('SendAPIData', print_r($APIData, 1));
     // Variable konvertieren..
     switch ($APIData->Mapping->VarType) {
         case IPSVarType::vtBoolean:
             $APIData->Data = ISCP_API_Commands::$BoolValueMapping[$APIData->Data];
             break;
         case IPSVarType::vtFloat:
             //                echo "Float VarType not implemented.";
             throw new Exception("Float VarType not implemented.", E_USER_NOTICE);
             break;
         case IPSVarType::vtInteger:
             if ($APIData->Mapping->ValueMapping == null) {
                 $APIData->Data = strtoupper(substr('0' . dechex($APIData->Data), -2));
             } else {
                 $Mapping = array_flip($APIData->Mapping->ValueMapping);
                 if (array_key_exists($APIData->Data, $Mapping)) {
                     $APIData->Data = $Mapping[$APIData->Data];
                 } else {
                     $APIData->Data = strtoupper(substr('0' . dechex($APIData->Data), -2));
                 }
             }
             break;
         case IPSVarType::vtDualInteger:
             if ($DualType === false) {
                 throw new Exception("Error on get DualInteger.", E_USER_NOTICE);
                 //                    echo "Error on get DualInteger.";
                 //                    return false;
             }
             $Prefix = array_flip($APIData->Mapping->ValuePrefix)[$DualType];
             $Mapping = array_flip($APIData->Mapping->ValueMapping);
             if (array_key_exists($APIData->Data, $Mapping)) {
                 $APIData->Data = $Prefix . $Mapping[$APIData->Data];
             } else {
                 $APIData->Data = strtoupper($Prefix . substr('0' . dechex($APIData->Data), -2));
             }
             break;
         default:
             //                echo "Unknow VarType.";
             //                return;
             throw new Exception("Unknow VarType.", E_USER_NOTICE);
             break;
     }
     try {
         $ret = $this->Send($APIData);
     } catch (Exception $exc) {
         throw $exc;
     }
     if ($ret->Data == "N/A") {
         throw new Exception("Command (temporally) not available.", E_USER_NOTICE);
         //            return;
     }
     switch ($APIData->Mapping->VarType) {
         case IPSVarType::vtBoolean:
         case IPSVarType::vtInteger:
         case IPSVarType::vtFloat:
             if ($ret->Data != $APIData->Data) {
                 IPS_LogMessage('RequestAction', print_r($APIData, 1));
                 IPS_LogMessage('RequestActionResult', print_r($ret, 1));
                 throw new Exception("Value not available.", E_USER_NOTICE);
                 //                    echo "Value not available.";
                 //                    return;
             }
             break;
         case IPSVarType::vtDualInteger:
             if (strpos($ret->Data, $APIData->Data) === false) {
                 IPS_LogMessage('RequestAction', print_r($APIData, 1));
                 IPS_LogMessage('RequestActionResult', print_r($ret, 1));
                 throw new Exception("Value not available.", E_USER_NOTICE);
                 //                    echo "Value not available.";
                 //                    return;
             }
             break;
     }
     return $ret;
 }
 /**
  * Log data to file
  * @param Integer $Device Device ID to log
  * @param array $weather_data
  */
 private function log_weather($Device, $weather_data)
 {
     //standard log)
     $fname = $this->GetLogFile();
     if ($fname == '') {
         return;
     }
     $i = $Device;
     $this->debug(__FUNCTION__, 'File:' . $fname);
     $exists = file_exists($fname);
     $o = @fopen($fname, "a");
     if (!$o) {
         IPS_LogMessage(__CLASS__, __FUNCTION__ . '::Cannot open ' . $fname);
         return;
     }
     if (!$exists) {
         fwrite($o, self::fieldlist . "\r\n");
     }
     //if exists
     $dt = $weather_data['date'];
     if ($dt == 0) {
         $dt = time();
     }
     //if date
     $datum = date('Y-m-d H:i:s', $dt);
     $id = $weather_data['records'][$i]['id'];
     $typ = $weather_data['records'][$i]['typ'];
     $sensor = $weather_data['records'][$i]['sensor'];
     $temp = $weather_data['records'][$i]['temp'];
     $hum = $weather_data['records'][$i]['hum'];
     $data = "{$datum};{$typ};{$id};{$sensor};{$temp};{$hum};";
     if ($i == 8) {
         $rain = $weather_data['rain'];
         $rainc = $weather_data['rainc'];
         $israining = $weather_data['israining'];
         $wind = $weather_data['wind'];
         $data = "{$datum};{$typ};{$id};{$sensor};{$temp};{$hum};;;{$wind};{$rain};{$israining};{$rainc}";
     }
     if ($temp > 0) {
         @fwrite($o, $data);
         fwrite($o, "\r\n");
     }
     //if temp
     fclose($o);
 }
 /**
  * Create a new EnergyDev instance and set its properties
  * @param array $data parsed record
  * @param String $caps String semicolon seperated capabilities of this device
  * @return int new Instance ID
  */
 private function CreateEnergyDevice($data, $caps)
 {
     $instID = 0;
     $Device = $data['Id'];
     $typ = $data['Typ'];
     $name = $data['Name'];
     $branch = $data['Branch'];
     unset($data['Branch']);
     if (!$name) {
         $name = "XS1 {$branch} {$Device}";
     }
     $class = __CLASS__ . "-EN";
     //$host = $this->GetHost();
     $ModuleID = $this->module_interfaces['EnergyDev'];
     if (IPS_ModuleExists($ModuleID)) {
         //return $result;
         $this->debug(__FUNCTION__, 'Device:' . $Device);
         $instID = IPS_CreateInstance($ModuleID);
         if ($instID > 0) {
             IPS_SetProperty($instID, 'DeviceID', $Device);
             IPS_SetProperty($instID, 'Class', $class);
             IPS_SetProperty($instID, 'Typ', $typ);
             IPS_SetProperty($instID, 'CapList', $caps);
             IPS_SetProperty($instID, 'Debug', $this->isDebug());
             //follow debug settings from splitter
             IPS_SetName($instID, "XS1 {$branch} '{$name}'");
             $ident = $class . "_" . $branch . "_{$Device}";
             $ident = preg_replace("/\\W/", "_", $ident);
             //nicht-Buchstaben/zahlen entfernen
             IPS_SetIdent($instID, $ident);
             IPS_ConnectInstance($instID, $this->InstanceID);
             IPS_ApplyChanges($instID);
             //set category
             $cat = $this->GetCategory() . " {$branch}" . "s";
             $pcat = $this->GetParentCategory();
             $ident = preg_replace("/\\W/", "_", $cat);
             //fix naming
             $catid = @IPS_GetObjectIDByIdent($ident, $pcat);
             if ($catid == 0) {
                 $catid = IPS_CreateCategory();
                 IPS_SetName($catid, $cat);
                 if (IPS_SetIdent($catid, $ident) && IPS_SetParent($catid, $pcat)) {
                     IPS_LogMessage($class, "Category {$cat} Ident {$ident} ({$catid}) created");
                 } else {
                     IPS_LogMessage($class, "Category {$cat} Ident {$ident} ({$catid}) FAILED");
                 }
             }
             $this->debug(__FUNCTION__, "Category:{$catid}");
             if (!IPS_SetParent($instID, $catid)) {
                 $this->debug(__FUNCTION__, "SetParent Instance {$instID} to Cat {$catid} failed, Dropping instance");
                 IPS_DeleteInstance($instID);
                 $instID = 0;
             } else {
                 $this->debug(__FUNCTION__, 'New ID:' . $instID);
             }
             //if instID
         } else {
             $this->debug(__FUNCTION__, 'Instance  is not created!');
         }
     }
     //module exists
     return $instID;
 }
Exemplo n.º 24
0
 public function ForwardData($JSONString)
 {
     // Empfangene Daten von der Device Instanz
     $data = json_decode($JSONString);
     IPS_LogMessage("ForwardData AIO Gateway Splitter", utf8_decode($data->Buffer));
     SetValue($this->GetIDForIdent("CommandOut"), $data->Buffer);
     // Hier würde man den Buffer im Normalfall verarbeiten
     // z.B. CRC prüfen, in Einzelteile zerlegen
     try {
         //
     } catch (Exception $ex) {
         echo $ex->getMessage();
         echo ' in ' . $ex->getFile() . ' line: ' . $ex->getLine() . '.';
     }
     // Weiterleiten zur I/O Instanz
     $resultat = $this->SendDataToParent(json_encode(array("DataID" => "{79827379-F36E-4ADA-8A95-5F8D1DC92FA9}", "Buffer" => $data->Buffer)));
     //TX GUID
     // Weiterverarbeiten und durchreichen
     return $resultat;
 }
Exemplo n.º 25
0
 protected function AddAddress($address)
 {
     $instance = IPS_GetInstance($this->InstanceID)["InstanceID"];
     IPS_SetProperty($instance, "AIOAdresse", $address);
     //FS20 Adresse setzten.
     IPS_SetProperty($instance, "LearnFS20Address", false);
     //Haken entfernen.
     IPS_ApplyChanges($instance);
     //Neue Konfiguration übernehmen
     IPS_LogMessage("FS20 Adresse hinzugefügt:", $address);
     // Status aktiv
     $this->SetStatus(102);
     $this->SetupVar();
     $this->SetupProfiles();
 }
Exemplo n.º 26
0
 private function Authenticate()
 {
     $tokenHeader = "X-API-KEY-TOKEN: " . $this->ReadPropertyString('APIKey');
     $result = $this->requestFoobotAPI($this->Host . "user/" . $this->ReadPropertyString('Username') . "/login/", "{$tokenHeader}");
     $auth = preg_match('/X-AUTH-TOKEN:\\s([a-zA-Z0-9._]+)/', $result, $token);
     if ($auth === false or $auth == 0) {
         if ($this->debug) {
             IPS_LogMessage("MODULE FOOBOT", "No Authentication Token returned");
         }
         return false;
     } else {
         $this->Token = $token[1];
         SetValue($this->GetIDForIdent('APIAT'), $token[1]);
         return true;
     }
 }
 /**
  * Log data to file
  * @param String $fname
  * @param array $data
  */
 private function log2file($fname, $data)
 {
     if ($fname == '') {
         return;
     }
     $this->debug(__FUNCTION__, 'File:' . $fname);
     $exists = file_exists($fname);
     $o = @fopen($fname, "a");
     if (!$o) {
         IPS_LogMessage(__CLASS__, __FUNCTION__ . '::Cannot open ' . $fname);
         return;
     }
     $header = implode(";", $this->fieldlist);
     if (!$exists) {
         fwrite($o, $header . "\r\n");
     }
     //if exists
     $line = '';
     for ($f = 0; $f < count($this->fieldlist); $f++) {
         $field = $this->fieldlist[$f];
         if (isset($data[$field])) {
             $val = $data[$field];
             $line .= $val;
             //$this->debug(__FUNCTION__,"Field: $field, Val: $val");
         }
         $line .= ";";
     }
     //for
     $line .= "\r\n";
     fwrite($o, $line);
     fclose($o);
 }
Exemplo n.º 28
0
	protected function RGB2HSLmilight($R, $G, $B) {
		if (($R < 0) or ( $R > 255) or ( $G < 0) or ( $G > 255) or ( $B < 0) or ( $B > 255))
			IPS_LogMessage("milight", "Color must be between 0 and 255");
		$R = ($R / 255);
		$G = ($G / 255);
		$B = ($B / 255);
		$cMin = min($R, $G, $B);
		$cMax = max($R, $G, $B);
		$Chroma = $cMax - $cMin;
		$L = ($cMax + $cMin) / 2 * 27;
		//$V = $maxRGB * 27;
		if ($Chroma == 0) {
			$H = 0;
		} else {
			if ($R == $cMin) {
				$H = 1 - (($B - $G) / $Chroma);
			} elseif ($B == $cMin) {
				$H = 3 - (($G - $R) / $Chroma);
			} elseif ($G == $cMin) {
				$H = 5 - (($R - $B) / $Chroma);
			}
			$H = $H / 6 * 255;
		}
		//IPS_LogMessage("rgb2hslmilight", "$R / $G / $B - $H / $L");
		return array('Color' => round($H), 'Luminance' => round($L));
	}
Exemplo n.º 29
0
 /**
  * Log Message
  * @param string $Message
  */
 protected function Log($Message)
 {
     IPS_LogMessage(__CLASS__, $Message);
 }
Exemplo n.º 30
0
 private function sendPacket($content)
 {
     $fp = fsockopen($this->address, 1400, $errno, $errstr, 10);
     if (!$fp) {
         throw new Exception("Error opening socket: " . $errstr . " (" . $errno . ")");
     }
     fputs($fp, $content);
     $ret = "";
     while (!feof($fp)) {
         $ret .= fgetss($fp, 128);
         // filters xml answer
     }
     fclose($fp);
     if (strpos($ret, "200 OK") === false) {
         IPS_LogMessage("sendPacket", $ret);
         throw new Exception("Error sending command: " . $ret);
     }
     // TAG_DEBUG_DEEP sendpacketdebug
     //echo "sendPacketDebug: "; //DEBUG
     //IPS_LogMessage("WHOLE",$ret);
     $parts = preg_split("/\r\n\r\n/", $ret);
     // split to header und body
     $header = $parts[0];
     $headerData = $this->getHeaderData($header);
     if (isset($headerData["TRANSFER-ENCODING"]) && $headerData["TRANSFER-ENCODING"] === "chunked") {
         $chunked = true;
     } else {
         $chunked = false;
     }
     $body = $parts[1];
     $array = preg_split("/\r\n/", $body);
     // split to header und body
     if (count($array) > 0) {
         $index = count($array) - 1;
     } else {
         $index = null;
     }
     for ($i = 0; $i < count($array); $i++) {
         if (strpos($array[$i], '&lt;DIDL') !== false) {
             $index = $i;
         } else {
             if (!ctype_xdigit(trim($array[$i]))) {
                 // is not hex
                 $array[$index] .= $array[$i];
             }
         }
     }
     if ($index !== null) {
         $returnContent = $array[$index];
     } else {
         $returnContent = $body;
     }
     return $returnContent;
 }