Esempio n. 1
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;
     }
 }
Esempio n. 2
0
 private function SetValueString($Ident, $value)
 {
     $id = $this->GetIDForIdent($Ident);
     if (GetValueString($id) != $value) {
         SetValueString($id, $value);
         return true;
     }
     return false;
 }
Esempio n. 3
0
 protected function SetValueString($Ident, $Value)
 {
     $ID = $this->GetIDForIdent($Ident);
     if (GetValueString($ID) != $Value) {
         SetValueString($ID, strval($Value));
         return true;
     }
     return false;
 }
Esempio n. 4
0
 public function RequestData() {
   $data = array();
   // Read data
   $this->ReadState();
   $this->ReadService();
   // Build hash for return
   $data['state'] = GetValueBoolean($this->GetIDForIdent('STATE'));
   $data['service']['name'] = GetValueString($this->GetIDForIdent('SERVICE_NAME'));
   $data['service']['reference'] = GetValueString($this->GetIDForIdent('SERVICE_REFERENCE'));
   return $data;
 }
Esempio n. 5
0
 protected function GetValueString($Ident)
 {
     $ID = is_numeric($Ident) ? $Ident : $this->GetIDForIdent($Ident);
     return GetValueString($ID);
 }
Esempio n. 6
0
 private function getDeviceAddress($deviceName)
 {
     $ret = IPS_GetInstanceListByModuleID("{44D8BE09-743E-484F-A64D-154C4235BE94}");
     $DeviceURL = "";
     $AccessToken = "";
     $retArray = "";
     $SecChannelExp = 0;
     if ($ret == null) {
         echo "Error: ips4WinDeviceRegistration is not implemented! Please create a new instance of ips4WinDeviceRegistration!\n";
     } else {
         if (count($ret) > 1) {
             echo "Error: multiple ips4WinDeviceRegistration found, unsupported installation! Please make sure you have only one instance of ips4WinDeviceRegistration!\n";
         } else {
             $id = $ret[0];
             $objList = IPS_GetChildrenIDs($id);
             //print_r($objList);
             $i = count($objList);
             for ($j = 0; $j < $i; $j++) {
                 $vid = @IPS_GetObjectIDByName("deviceName", $objList[$j]);
                 if ($vid !== false) {
                     if ($deviceName == null) {
                         $device = GetValueString($vid);
                         $vid = @IPS_GetObjectIDByName("SecChannel", $objList[$j]);
                         if ($vid !== false) {
                             $DeviceURL = GetValueString($vid);
                         }
                         $vid = @IPS_GetObjectIDByName("AccessToken", $objList[$j]);
                         if ($vid !== false) {
                             $AccessToken = GetValueString($vid);
                         }
                         $vid = @IPS_GetObjectIDByName("SecChannelExp", $objList[$j]);
                         if ($vid !== false) {
                             $SecChannelExp = GetValueInteger($vid);
                         }
                         if ($retArray == "") {
                             $retArray[0] = explode("###", $device . "###" . $DeviceURL . "###" . $AccessToken . "###" . $SecChannelExp);
                         } else {
                             $retArray[count($retArray)] = explode("###", $device . "###" . $DeviceURL . "###" . $AccessToken . "###" . $SecChannelExp);
                         }
                         $DeviceURL = "";
                         $AccessToken = "";
                         $SecChannelExp = 0;
                     } else {
                         if (strtolower($deviceName) == strtolower(GetValueString($vid))) {
                             $vid = @IPS_GetObjectIDByName("SecChannel", $objList[$j]);
                             if ($vid !== false) {
                                 $DeviceURL = GetValueString($vid);
                             }
                             $vid = @IPS_GetObjectIDByName("AccessToken", $objList[$j]);
                             if ($vid !== false) {
                                 $AccessToken = GetValueString($vid);
                             }
                             $vid = @IPS_GetObjectIDByName("SecChannelExp", $objList[$j]);
                             if ($vid !== false) {
                                 $SecChannelExp = GetValueInteger($vid);
                             }
                             $retArray = array(explode("###", $deviceName . "###" . $DeviceURL . "###" . $AccessToken . "###" . $SecChannelExp));
                             $j = $i;
                         }
                     }
                 }
             }
         }
     }
     return $retArray;
 }
Esempio n. 7
0
 public function SetGroup($groupCoordinator)
 {
     if ($this->ReadPropertyBoolean("GroupCoordinator")) {
         return;
     }
     $ip = $this->ReadPropertyString("IPAddress");
     $timeout = $this->ReadPropertyString("TimeOut");
     if ($timeout && Sys_Ping($ip, $timeout) != true) {
         throw new Exception("Sonos Box " . $ip . " is not available");
     }
     // get variable of coordinator members to be updated
     if ($groupCoordinator) {
         $groupMembersID = @IPS_GetObjectIDByIdent("GroupMembers", $groupCoordinator);
         $uri = "x-rincon:" . IPS_GetProperty($groupCoordinator, "RINCON");
     } else {
         $groupMembersID = @IPS_GetObjectIDByIdent("GroupMembers", GetValue($this->GetIDForIdent("MemberOfGroup")));
         $uri = "";
     }
     // update coordinator members
     SetValue($this->GetIDForIdent("MemberOfGroup"), $groupCoordinator);
     if ($groupMembersID) {
         $currentMembers = explode(",", GetValueString($groupMembersID));
         $currentMembers = array_filter($currentMembers, function ($v) {
             return $v != "";
         });
         $currentMembers = array_filter($currentMembers, function ($v) {
             return $v != $this->InstanceID;
         });
         if ($groupCoordinator) {
             $currentMembers[] = $this->InstanceID;
         }
         SetValueString($groupMembersID, implode(",", $currentMembers));
     }
     // Set relevant variables to hidden/unhidden
     if ($groupCoordinator) {
         $hidden = true;
     } else {
         $hidden = false;
     }
     IPS_SetHidden($this->GetIDForIdent("nowPlaying"), $hidden);
     IPS_SetHidden($this->GetIDForIdent("Radio"), $hidden);
     IPS_SetHidden($this->GetIDForIdent("Playlist"), $hidden);
     IPS_SetHidden($this->GetIDForIdent("Status"), $hidden);
     IPS_SetHidden($this->GetIDForIdent("Sleeptimer"), $hidden);
     include_once __DIR__ . "/sonosAccess.php";
     (new SonosAccess($ip))->SetAVTransportURI($uri);
 }
Esempio n. 8
0
 public function ReceiveData($JSONString)
 {
     $data = json_decode($JSONString);
     //IPS_LogMessage('ReceiveDataFrom???:'.$this->InstanceID,  print_r($data,1));
     $this->CheckParents();
     if ($this->Mode === false) {
         trigger_error("Wrong IO-Parent", E_USER_WARNING);
         //            echo "Wrong IO-Parent";
         return false;
     }
     $bufferID = $this->GetIDForIdent("BufferIN");
     // Empfangs Lock setzen
     if (!$this->lock("ReceiveLock")) {
         trigger_error("ReceiveBuffer is locked", E_USER_NOTICE);
         return false;
         //            throw new Exception("ReceiveBuffer is locked",E_USER_NOTICE);
     }
     // Datenstream zusammenfügen
     $head = GetValueString($bufferID);
     SetValueString($bufferID, '');
     // Stream in einzelne Pakete schneiden
     $stream = $head . utf8_decode($data->Buffer);
     if ($this->Mode == ISCPSplitter::LAN) {
         $minTail = 24;
         $start = strpos($stream, 'ISCP');
         if ($start === false) {
             IPS_LogMessage('ISCP Gateway', 'LANFrame without ISCP');
             $stream = '';
         } elseif ($start > 0) {
             IPS_LogMessage('ISCP Gateway', 'LANFrame start not with ISCP');
             $stream = substr($stream, $start);
         }
         //Paket suchen
         if (strlen($stream) < $minTail) {
             IPS_LogMessage('ISCP Gateway', 'LANFrame to short');
             SetValueString($bufferID, $stream);
             $this->unlock("ReceiveLock");
             return;
         }
         $header_len = ord($stream[6]) * 256 + ord($stream[7]);
         $frame_len = ord($stream[10]) * 256 + ord($stream[11]);
         //             IPS_LogMessage('ISCP Gateway', 'LANFrame info ' . $header_len. '+'. $frame_len . ' Bytes.');
         if (strlen($stream) < $header_len + $frame_len) {
             IPS_LogMessage('ISCP Gateway', 'LANFrame must have ' . $header_len . '+' . $frame_len . ' Bytes. ' . strlen($stream) . ' Bytes given.');
             SetValueString($bufferID, $stream);
             $this->unlock("ReceiveLock");
             return;
         }
         $header = substr($stream, 0, $header_len);
         $frame = substr($stream, $header_len, $frame_len);
         //EOT wegschneiden von reschts, aber nur wenn es einer der letzten drei zeichen ist
         $end = strrpos($frame, chr(0x1a));
         if ($end >= $frame_len - 3) {
             $frame = substr($frame, 0, $end);
         }
         //EOT wegschneiden von reschts, aber nur wenn es einer der letzten drei zeichen ist
         $end = strrpos($frame, chr(0xd));
         if ($end >= $frame_len - 3) {
             $frame = substr($frame, 0, $end);
         }
         //EOT wegschneiden von reschts, aber nur wenn es einer der letzten drei zeichen ist
         $end = strrpos($frame, chr(0xa));
         if ($end >= $frame_len - 3) {
             $frame = substr($frame, 0, $end);
         }
         //                IPS_LogMessage('ISCP Gateway', 'LAN $header:' . $header);
         //                IPS_LogMessage('ISCP Gateway', 'LAN $frame:' . $frame);
         // 49 53 43 50  // ISCP
         // 00 00 00 10  // HEADERLEN
         // 00 00 00 0B  // DATALEN
         // 01 00 00 00  // Version
         // 21 31 4E 4C  // !1NL
         // 53 43 2D 50  // SC-P
         // 1A 0D 0A     // EOT CR LF
         $tail = substr($stream, $header_len + $frame_len);
         if ($this->eISCPVersion != ord($header[12])) {
             $frame = false;
             trigger_error("Wrong eISCP Version", E_USER_NOTICE);
         }
     } else {
         $minTail = 6;
         $start = strpos($stream, '!');
         if ($start === false) {
             IPS_LogMessage('ISCP Gateway', 'eISCP Frame without !');
             $stream = '';
         } elseif ($start > 0) {
             IPS_LogMessage('ISCP Gateway', 'eISCP Frame do not start with !');
             $stream = substr($stream, $start);
         }
         //Paket suchen
         $end = strpos($stream, chr(0x1a));
         if ($end === false or strlen($stream) < $minTail) {
             IPS_LogMessage('ISCP Gateway', 'eISCP Frame to short');
             SetValueString($bufferID, $stream);
             $this->unlock("ReceiveLock");
             return;
         }
         $frame = substr($stream, $start, $end - $start);
         // Ende wieder in den Buffer werfen
         $tail = ltrim(substr($stream, $end));
     }
     if ($tail === false) {
         $tail = '';
     }
     SetValueString($bufferID, $tail);
     $this->unlock("ReceiveLock");
     if ($frame !== false) {
         $this->DecodeData($frame);
     }
     // Ende war länger als 6 / 23 ? Dann nochmal Packet suchen.
     if (strlen($tail) >= $minTail) {
         $this->ReceiveData(json_encode(array('Buffer' => '')));
     }
     return true;
 }
 /**
  * Get status variable Buffer
  * contains incoming data from IO, act as regVar
  * @return String
  */
 protected function GetBuffer()
 {
     $id = $this->GetIDForIdent('Buffer');
     $val = GetValueString($id);
     return $val;
 }
Esempio n. 10
0
 private function WaitForResponse()
 {
     $ReplyATDataID = $this->GetIDForIdent('ReplyATData');
     for ($i = 0; $i < 500; $i++) {
         if (GetValueString($ReplyATDataID) === '') {
             IPS_Sleep(10);
         } else {
             if ($this->lock('ReplyATData')) {
                 $ret = GetValueString($ReplyATDataID);
                 SetValueString($ReplyATDataID, '');
                 $this->unlock('ReplyATData');
                 $JSON = json_decode($ret);
                 $ATData = new TXB_Command_Data();
                 $ATData->GetDataFromJSONObject($JSON);
                 return $ATData;
             }
             return false;
         }
     }
     return false;
 }
Esempio n. 11
0
            if ($sleeptimer) {
                $SleeptimerArray = explode(":", $sonos->GetSleeptimer());
                $SleeptimerMinutes = $SleeptimerArray[0] * 60 + $SleeptimerArray[1];
                if ($SleeptimerArray[2]) {
                    $SleeptimerMinutes = $SleeptimerMinutes + 1;
                }
            } else {
                $SleeptimerMinutes = 0;
            }
            SetValueInteger(IPS_GetObjectIDByName("Sleeptimer", IPS_GetParent($_IPS["SELF"])), $SleeptimerMinutes);
        }
    }
    $nowPlaying = GetValueString(IPS_GetObjectIDByName("nowPlaying", IPS_GetParent($_IPS["SELF"])));
    if ($actuallyPlaying != $nowPlaying) {
        SetValueString(IPS_GetObjectIDByName("nowPlaying", IPS_GetParent($_IPS["SELF"])), $actuallyPlaying);
    }
}
// Set Group Volume
if (IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "GroupCoordinator")) {
    $groupMembers = GetValueString(IPS_GetObjectIDByName("GroupMembers", IPS_GetParent($_IPS["SELF"])));
    $groupMembersArray = array();
    if ($groupMembers) {
        $groupMembersArray = array_map("intval", explode(",", $groupMembers));
    }
    $groupMembersArray[] = IPS_GetParent($_IPS["SELF"]);
    $GroupVolume = 0;
    foreach ($groupMembersArray as $key => $ID) {
        $GroupVolume += GetValueInteger(IPS_GetObjectIDByName("Volume", $ID));
    }
    SetValueInteger(IPS_GetObjectIDByName("GroupVolume", IPS_GetParent($_IPS["SELF"])), intval(round($GroupVolume / sizeof($groupMembersArray))));
}
Esempio n. 12
0
 public function ReceiveData($JSONString)
 {
     $data = json_decode($JSONString);
     IPS_LogMessage('Logamatic <- Gateway:', bin2hex(utf8_decode($data->Buffer)));
     $monitorID = $this->GetIDForIdent('Monitordaten');
     $EinstellParID = $this->GetIDForIdent('EinstellPar');
     $stream = bin2hex(utf8_decode($data->Buffer));
     $datentyp = substr($stream, 0, 2);
     $bus = substr($stream, 4, 2);
     $modultyp = substr($stream, 8, 2);
     switch ($datentyp) {
         case 'a5':
             // A5 Statusmeldung
             IPS_LogMessage('Buderus Logamatic', 'ECO-CAN Adresse ' . $bus . ' is alive');
             return true;
         case 'a7':
             // A7 Monitordaten Normalmodus
             IPS_LogMessage('Buderus Logamatic', 'Monitordaten ECO-CAN Adresse ' . $bus . ' Normalmodus :' . $stream);
             EncodeMonitorNormalData($stream, $this->InstanceID, chr($this->ReadPropertyString('Bus')));
             break;
         case 'a9':
             // A9 Kennung für einstellbare Parameter
             $head = GetValueString($EinstellParID);
             $EinstellPar = $head . $stream;
             SetValueString($EinstellParID, $EinstellPar);
             break;
         case 'aa':
             // AA Einstellbare Parameter komplett übertragen
             IPS_LogMessage('Buderus Logamatic', 'Einstellbare Parameter ECO-CAN Adresse ' . $bus . ' komplett :' . strlen(GetValueString($EinstellParID)) . ' Bytes');
             EncodeEinstellParData(GetValueString($EinstellParID), $this->InstanceID, chr($this->ReadPropertyString('Bus')));
             $data = chr(Command::Normalmodus) . chr($this->ReadPropertyString('Bus')) . chr(Command::NUL) . chr(Command::NUL);
             $this->SendDataToParent($data);
             // Umschalten in Normalmodus senden
             break;
         case 'ab':
             // AB Monitordaten Direktmodus
             $head = GetValueString($monitorID);
             $Monitordaten = $head . $stream;
             SetValueString($monitorID, $Monitordaten);
             break;
         case 'ac':
             // AC Monitordaten komplett übertragen
             //$monitordaten = GetValueString($monitorID);
             IPS_LogMessage('Buderus Logamatic:', 'Monitordaten ECO-CAN Adresse ' . $bus . ' komplett :' . strlen(GetValueString($monitorID)) . ' Bytes\\n');
             EncodeMonitorDirektData(GetValueString($monitorID), $this->InstanceID, chr($this->ReadPropertyString('Bus')));
             $data = chr(Command::Normalmodus) . chr($this->ReadPropertyString('Bus')) . chr(Command::NUL) . chr(Command::NUL);
             $this->SendDataToParent($data);
             // Umschalten in Normalmodus senden
             break;
         case 'ad':
             // AD Datenblock empfangen
             IPS_LogMessage('Buderus Logamatic', 'Datenblock ' . $stream);
             break;
     }
     $stream = '';
     return true;
 }
 /**
  * Send commands to enable !Wire HMS Emulation
  */
 private function init_onewire()
 {
     $this->debug(__FUNCTION__, "Entered");
     //get message variable
     $lmid = $this->GetIDForIdent('AuxMessage');
     //$devid=getVid('OneWireDevices',$reg);
     #read OW-IDs
     IPS_Sleep(1000);
     $this->SendText("Of\r\n");
     IPS_Sleep(2000);
     $this->SendText("OHo\r\n");
     IPS_Sleep(2000);
     $res = substr(GetValueString($lmid), 0, 2);
     if ($res != "ON") {
         $this->SendText("OHo\r\n");
         IPS_Sleep(1500);
         $res = substr(GetValueString($lmid), 0, 2);
     }
     if ($res == "ON") {
         #set 180s intervall
         $this->SendText("OHt180\r\n");
         IPS_Sleep(1500);
         $res = GetValueString($lmid);
         $this->debug(__FUNCTION__, "Set OW HMS Timer 180s:{$res}");
     } else {
         IPS_LogMessage(__CLASS__, "Onewire: Failed to set HMS modus({$res})");
     }
     SetValueString($lmid, "");
 }
Esempio n. 14
0
 protected function DoUser($ModulID, $data)
 {
     $Tage = array("Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag");
     $Vorname = $data['firstname'];
     $Nachname = $data['lastname'];
     $Name = $Vorname . " " . $Nachname;
     $Geschlecht = $data['gender'];
     $Geburtstag = date('d.m.Y', $data['birthdate']);
     $Tag = $Tage[date("w", $data['birthdate'])];
     $Geburtstag = $Tag . " " . $Geburtstag;
     $id = @IPS_GetVariableIDByName("Name", $ModulID);
     if ($id > 0) {
         $v = GetValueString($id);
         if ($v != $Name) {
             SetValueString($id, $Name);
         }
     }
     $id = @IPS_GetVariableIDByName("Geburtstag", $ModulID);
     if ($id > 0) {
         $v = GetValueString($id);
         if ($v != $Geburtstag) {
             SetValueString($id, $Geburtstag);
         }
     }
     $id = @IPS_GetVariableIDByName("Geschlecht", $ModulID);
     if ($id > 0) {
         $v = GetValueInteger($id);
         if ($v != $Geschlecht) {
             SetValueInteger($id, $Geschlecht);
         }
     }
 }
 /**
  * handle incoming data along capabilities
  * @param array $data
  */
 private function ParseData($data)
 {
     //
     $caps = $this->GetCaps();
     //$this->debug(__FUNCTION__,print_r($this->all_caps,true));
     foreach (array_keys($caps) as $cap) {
         $ident = $caps[$cap];
         $vid = @$this->GetIDForIdent($ident);
         if ($vid == 0) {
             $this->debug(__FUNCTION__, "Cap {$cap} Ident {$ident}: Variable missed");
             continue;
         }
         if (!isset($data[$cap])) {
             continue;
         }
         $s = $data[$cap];
         switch ($cap) {
             //integer
             case 'TS':
                 //Timestamp
             //Timestamp
             case 'Signal':
                 //RSSI
             //RSSI
             case 'Timer':
                 //Duration code
             //Duration code
             case 'Dimmer':
                 //intensity 100%
             //intensity 100%
             case 'Shutter':
                 //intensity 100%
                 $iv = (int) $s;
                 SetValueInteger($vid, $iv);
                 break;
                 //String
             //String
             case 'Name':
                 //Duration code
                 $st = utf8_decode($s);
                 SetValueString($vid, $st);
                 break;
                 //special
             //special
             case 'Switch':
                 //Status
                 $state = $this->SwitchStatus($s);
                 SetValueBoolean($vid, $state);
                 break;
             case 'Lock':
                 //Status
                 $state = preg_match("/YES|CLOSE|OK/i", $s);
                 //reversed
                 SetValueBoolean($vid, $state);
                 break;
             case 'Alert':
                 //Status
                 $state = !preg_match("/YES|ALERT/i", $s);
                 //reversed
                 SetValueBoolean($vid, $state);
                 break;
             case 'Battery':
                 //battery
                 $state = !preg_match("/LOW|WARN/i", $s);
                 //reversed
                 SetValueBoolean($vid, $state);
                 break;
             case 'FS20':
                 //fs20 mode decoding
                 $state = false;
                 $intensity = 0;
                 $timer = 0;
                 $acode = '';
                 $actioncode = '';
                 $code = utf8_decode($s);
                 $this->debug(__FUNCTION__, "FS20 Code " . strToHex($code));
                 $action = $code[0];
                 $ext = ord($code[1]);
                 $tvid = @$this->GetIDForIdent($caps['Timer']);
                 $dvid = @$this->GetIDForIdent($caps['Dimmer']);
                 $swid = @$this->GetIDForIdent($caps['Switch']);
                 $avid = @$this->GetIDForIdent($caps['TimerActionCode']);
                 $this->debug(__FUNCTION__, "FS20 Vars S:{$swid},D:{$dvid},T:{$tvid},A:{$avid}");
                 if ($dvid) {
                     $intensity = GetValueInteger($dvid);
                 }
                 if ($swid) {
                     $state = GetValueBoolean($swid);
                 }
                 if ($tvid) {
                     $timer = GetValueInteger($tvid);
                 }
                 if ($avid) {
                     $acode = GetValueString($avid);
                 }
                 $ac = ord($action) & 0x1f;
                 $timed = ($action & 0x20) > 0;
                 $this->debug(__FUNCTION__, "FS20 AC:" . $ac . "PrevD:{$intensity}, PrevS:" . ($state ? "On" : "Off"));
                 switch ($ac) {
                     case 0:
                         //off
                         if ($timed) {
                             $actioncode = 'Switch:Off';
                         } else {
                             $state = false;
                         }
                         break;
                     case $ac < 0xf:
                         //Dim to value
                         $intensity = FHZ_helper::fs20_intensity_percent($action & 0xf);
                         $state = true;
                         if ($timed) {
                             $actioncode = 'Switch:Off';
                         }
                         break;
                     case 0x10:
                         //on full
                         $state = true;
                         $intensity = 100;
                         if ($timed) {
                             $actioncode = 'Switch:Off';
                         }
                         break;
                     case 0x11:
                         //on with old value
                         $state = true;
                         if ($intensity == 0) {
                             $intensity = 100;
                         }
                         if ($timed) {
                             $actioncode = 'Switch:Off';
                         }
                         break;
                     case 0x12:
                         $state = !GetValueBoolean($swid);
                         //toggle
                         break;
                     case 0x13:
                         //dimup
                         $steps = FHZ_helper::fs20_intensity_steps($intensity);
                         $intensity = FHZ_helper::fs20_intensity_percent($steps + 1);
                         $state = true;
                         break;
                     case 0x14:
                         //dimdown
                         if ($intensity == 0) {
                             $intensity = 100;
                         }
                         $steps = FHZ_helper::fs20_intensity_steps($intensity);
                         $intensity = FHZ_helper::fs20_intensity_percent($steps - 1);
                         if ($intensity == 0) {
                             $state = false;
                         }
                         break;
                     case 0x18:
                         //off-for-timer
                         $state = 'Off';
                         $actioncode = 'Switch:On';
                         break;
                     case 0x19:
                         //on-for-timer than out
                         $state = true;
                         $actioncode = 'Switch:Off';
                         break;
                     case 0x1a:
                         //on-old-for-timer than out
                         $state = true;
                         $actioncode = 'Switch:Off';
                         break;
                     case 0x1c:
                         //ramp-on-time (time to reach the desired dim value on dimmers)
                         $state = true;
                         $actioncode = "Dimmer:{$intensity}";
                         break;
                     case 0x1d:
                         //ramp-off-time (time to reach the off state on dimmers)
                         $actioncode = 'Switch:Off;Dimmer:0';
                         break;
                     case 0x1e:
                         //on-old-for-timer-prev", // old val for timer, then go to prev. state
                         $actioncode = "Switch:" . ($state ? 'On' : 'Off');
                         $state = true;
                         break;
                     case 0x1f:
                         //on-100-for-timer-prev", // 100% for timer, then go to previous state
                         //new intensity will be the old one
                         $action = "Switch:" . ($state ? 'On' : 'Off') . ";Dimmer:{$intensity}";
                         $intensity = 100;
                         $state = true;
                         break;
                     case 0x15:
                         //dimupdown, no value changes
                     //dimupdown, no value changes
                     case 0x16:
                         //Set Timer
                     //Set Timer
                     case 0x17:
                         //nop
                     //nop
                     case 0x1b:
                         //rese
                         break;
                 }
                 $new_timer = FHZ_helper::fs20_times($ext);
                 $this->debug(__FUNCTION__, "State:" . ($state ? "ON" : "OFF") . ", Dimmer:{$intensity}%,Timer: {$new_timer},ActionCode: '{$actioncode}'");
                 //state
                 if ($swid) {
                     SetValueBoolean($swid, $state);
                 }
                 //dimmer
                 if ($dvid) {
                     SetValueInteger($dvid, $intensity);
                 }
                 //timer
                 if ($tvid) {
                     $this->SetTimerInterval('DeviceTimer', $new_timer * 1000);
                     SetValueInteger($tvid, $new_timer);
                 }
                 //action
                 if ($avid && $acode != $actioncode) {
                     SetValueString($avid, $actioncode);
                 }
                 //log
                 $actiontext = FHZ_helper::$fs20_codes[strToHex($action)];
                 if ($ext > 0) {
                     $actiontext .= ', Timer:' . $timer;
                 }
                 $text = sprintf('%s (%s)', $actiontext, strToHex($code));
                 if ($vid) {
                     SetValueString($vid, $text);
                 }
                 $this->debug(__FUNCTION__, "Action:" . $text);
                 break;
             default:
                 $this->debug(__FUNCTION__, "{$cap} not handled");
         }
         $this->debug(__FUNCTION__, "{$cap}:({$vid})" . $s);
     }
 }
Esempio n. 16
0
 public function ReceiveData($JSONString)
 {
     $data = json_decode($JSONString);
     //        IPS_LogMessage('ReceiveDataFromSerialPort:'.$this->InstanceID,  print_r($data,1));
     $bufferID = $this->GetIDForIdent("BufferIN");
     // Empfangs Lock setzen
     if (!$this->lock("ReceiveLock")) {
         throw new Exception("ReceiveBuffer is locked");
     }
     // Datenstream zusammenfügen
     $head = GetValueString($bufferID);
     SetValueString($bufferID, '');
     // Stream in einzelne Pakete schneiden
     $stream = $head . utf8_decode($data->Buffer);
     $start = strpos($stream, chr(0x7e));
     //Anfang suchen
     if ($start === false) {
         //            IPS_LogMessage('XBeeZigBee Gateway', 'Frame without 0x7e');
         $stream = '';
     } elseif ($start > 0) {
         //            IPS_LogMessage('XBeeZigBee Gateway', 'Frame do not start with 0x7e');
         $stream = substr($stream, $start);
     }
     //Paket suchen
     if (strlen($stream) < 5) {
         //            IPS_LogMessage('XBeeZigBee Gateway', 'Frame to short');
         SetValueString($bufferID, $stream);
         $this->unlock("ReceiveLock");
         return;
     }
     $len = ord($stream[1]) * 256 + ord($stream[2]);
     if (strlen($stream) < $len + 4) {
         //            IPS_LogMessage('XBeeZigBee Gateway', 'Frame must have ' . $len . ' Bytes. ' . strlen($stream) . ' Bytes given.');
         SetValueString($bufferID, $stream);
         $this->unlock("ReceiveLock");
         return;
     }
     $packet = substr($stream, 3, $len + 1);
     // Ende wieder in den Buffer werfen
     $tail = substr($stream, $len + 4);
     if ($tail === false) {
         $tail = '';
     }
     SetValueString($bufferID, $tail);
     $this->unlock("ReceiveLock");
     $this->DecodeData($packet);
     // Ende war länger als 4 ? Dann nochmal Packet suchen.
     if (strlen($tail) > 4) {
         $this->ReceiveData(json_encode(array('Buffer' => '')));
     }
     return true;
 }
Esempio n. 17
0
 private function SetValueString($Ident, $value)
 {
     $id = $this->GetIDForIdent($Ident);
     if (GetValueString($id) != $value) {
         SetValueString($id, $value);
     }
 }
 /**
  * Get status variable Config
  * contains WS300PC config record in hex
  * @return String
  */
 private function GetConfig()
 {
     $id = $this->GetIDForIdent('Config');
     $val = GetValueString($id);
     return $val;
 }
function EncodeVariableData($parentID, $typ)
{
    $var = Buderus($typ, -1, 1);
    if ($var === '0') {
        return true;
    } else {
        $ID = IPS_GetVariableIDByName(Buderus($typ, -1, 0), $parentID);
        $value = GetValueString($ID);
        for ($x = 0; $x < Buderus($typ, -1, 1); $x++) {
            if (Buderus($typ, $x, 0) !== "") {
                switch (Buderus($typ, $x, 1)) {
                    case "Bit":
                        SetValue(CheckVariableTYP(Buderus($typ, $x, 0), 3, "~String", $ID), str_pad(base_convert(ord(hex2bin(substr($value, $x * 2, 2))), 16, 2), 8, "0", STR_PAD_LEFT));
                        break;
                    case "Temp":
                        SetValue(CheckVariableTYP(Buderus($typ, $x, 0), 2, "~Temperature", $ID), ord(hex2bin(substr($value, $x * 2, 2))) * Buderus($typ, $x, 2));
                        break;
                    case "Temp2":
                        SetValue(CheckVariableTYP(Buderus($typ, $x, 0), 2, "~Temperature", $ID), ord(hex2bin(substr($value, $x * 2, 2))) * Buderus($typ, $x, 2) + ord(hex2bin(substr($value, $x * 2 + 1, 2))) * Buderus($typ, $x + 1, 2));
                        $x++;
                        break;
                    case "Temp3":
                        SetValue(CheckVariableTYP(Buderus($typ, $x, 0), 2, "~Temperature", $ID), ord(hex2bin(substr($value, $x * 2, 2))) * Buderus($typ, $x, 2));
                        break;
                    case "Zeit":
                        SetValue(CheckVariableTYP(Buderus($typ, $x, 0), 1, "~Temperature", $ID), ord(hex2bin(substr($value, $x * 2, 2))));
                        //Minutes
                        break;
                    case "Prozent":
                        SetValue(CheckVariableTYP(Buderus($typ, $x, 0), 1, "~Valve", $ID), ord(hex2bin(substr($value, $x * 2, 2))));
                        break;
                    case "Betr":
                        SetValue(CheckVariableTYP(Buderus($typ, $x, 0), 2, "Hours", $ID), (ord(hex2bin(substr($value, $x * 2, 2))) * Buderus($typ, $x, 2) + ord(hex2bin(substr($value, $x * 2 + 1, 2))) * Buderus($typ, $x + 1, 2) + ord(hex2bin(substr($value, $x * 2 + 2, 2))) * Buderus($typ, $x + 2, 2)) / 60);
                        //
                        $x++;
                        $x++;
                        break;
                    case "Betr2":
                        SetValue(CheckVariableTYP(Buderus($typ, $x, 0), 2, "Minutes", $ID), (ord(hex2bin(substr($value, $x * 2, 2))) * Buderus($typ, $x, 2) + ord(hex2bin(substr($value, $x * 2 + 1, 2))) * Buderus($typ, $x + 1, 2) + ord(hex2bin(substr($value, $x * 2 + 2, 2))) * Buderus($typ, $x + 2, 2)) / 60);
                        //
                        $x++;
                        $x++;
                        break;
                    case "Waerme":
                        SetValue(CheckVariableTYP(Buderus($typ, $x, 0), 2, "Waerme", $ID), (ord(hex2bin(substr($value, $x * 2, 2))) * Buderus($typ, $x, 2) + ord(hex2bin(substr($value, $x * 2 + 1, 2))) * Buderus($typ, $x + 1, 2) + ord(hex2bin(substr($value, $x * 2 + 2, 2))) * Buderus($typ, $x + 2, 2)) / 100);
                        //
                        $x++;
                        $x++;
                        break;
                    case "Watt":
                        SetValue(CheckVariableTYP(Buderus($typ, $x, 0), 2, "Watt", $ID), ord(hex2bin(substr($value, $x * 2, 2))) * Buderus($typ, $x, 2) + ord(hex2bin(substr($value, $x + 1, 2))) * Buderus($typ, $x + 1, 2));
                        //
                        $x++;
                        break;
                    case "Flow":
                        SetValue(CheckVariableTYP(Buderus($typ, $x, 0), 2, "Flow", $ID), ord(hex2bin(substr($value, $x * 2, 2))) * Buderus($typ, $x, 2) + ord(hex2bin(substr($value, $x * 2 + 1, 2))) * Buderus($typ, $x + 1, 2));
                        // l/h
                        $x++;
                        break;
                    case "Version":
                        SetValue(CheckVariableTYP(Buderus($typ, $x, 0), 3, "Version", $ID), ord(hex2bin(substr($value, $x * 2, 2))) . "." . ord(hex2bin(substr($value, $x * 2 + 1, 2))));
                        //
                        $x++;
                        break;
                    case "Modul":
                        SetValue(CheckVariableTYP(Buderus($typ, $x, 0), 3, "~String", $ID), Buderus($typ, $x, ord(hex2bin(substr($value, $x * 2, 2))) + 2));
                        break;
                }
            }
        }
    }
}
Esempio n. 20
0
 private function WaitForResponse($APIData_Command)
 {
     $ReplyAPIDataID = $this->GetIDForIdent('ReplyAPIData');
     for ($i = 0; $i < 300; $i++) {
         if (GetValueString($ReplyAPIDataID) === '') {
             IPS_Sleep(5);
         } else {
             if ($this->lock('ReplyAPIData')) {
                 $ret = GetValueString($ReplyAPIDataID);
                 SetValueString($ReplyAPIDataID, '');
                 $this->unlock('ReplyAPIData');
                 $JSON = json_decode($ret);
                 $APIData = new ISCP_API_Data();
                 $APIData->GetDataFromJSONObject($JSON);
                 if ($APIData_Command == $APIData->APICommand) {
                     return $APIData;
                 } else {
                     $i = $i - 100;
                     if ($i < 0) {
                         $i = 0;
                     }
                 }
             }
         }
     }
     if ($this->lock('ReplyAPIData')) {
         SetValueString($ReplyAPIDataID, '');
         $this->unlock('ReplyAPIData');
     }
     return false;
 }
Esempio n. 21
0
 private function WriteResponse($Command, $Value)
 {
     if (is_array($Command)) {
         $Command = implode(' ', $Command);
     }
     if (is_array($Value)) {
         $Value = implode(' ', $Value);
     }
     $EventID = $this->GetIDForIdent('WaitForResponse');
     if (!GetValueBoolean($EventID)) {
         return false;
     }
     $BufferID = $this->GetIDForIdent('BufferOUT');
     if ($Command == GetValueString($BufferID)) {
         if ($this->lock('BufferOut')) {
             SetValueString($BufferID, trim($Value));
             SetValueBoolean($EventID, false);
             $this->unlock('BufferOut');
             return true;
         }
         return 'Error on write ResponseBuffer';
     }
     return false;
 }
Esempio n. 22
0
    public function ReceiveData($JSONString)
    {                                                                    // *************** Daten zusammen tragen ************
           $data = json_decode($JSONString);
           $BufferID = $this->GetIDForIdent("BufferIN");
           $DatasetID = $this->GetIDForIdent("Dataset");
           $SensorenID = $this->GetIDForIdent("Sensoren");
           $Head = GetValueString($BufferID);                            // holt sich die gespeicherten Restdaten aus der Variablen
           $dazu = utf8_decode($data->Buffer);                           // holen des neuen
           $all = $Head.$dazu;                                           // setzt alle zusammen
                                                                         // *************** Datensatz separieren *************
           $Startsequenz = chr(0x0D).chr(0x0A).chr(0x0D).chr(0x0A);      // damit fängt der Datensatz an
           $Datasets = explode ($Startsequenz, $all);                    // Nun zerlegen wir den Senf und basteln ein Array
           $AnzahlDatasets = count ($Datasets);
           if ($AnzahlDatasets > 1)                                      // checkt ob ein vollständiger da ist
           {
           SetValueString($BufferID, $Datasets[1]);                      // schreibt die Reste wieder zurück
           SetValueString($DatasetID, $Datasets[0]);                     // schreibt vollständigen Datensatz in Dataset, kann später wieder raus
           // ab hier zerlegen wir das Dataset 0                         // *************** Datensatz verarbeiten ************
           $AnzahlSensoren = substr_count($Datasets[0], 'ROM');          // hier zählen wir wieviele Sensoren vorhanden sind
           SetValueInteger($SensorenID, $AnzahlSensoren);                // und füllen damit die Variable

           $Sensoren = $Datasets[0];

           $Startsequenz1 = "ROM = ";                                    // damit fängt der Datensatz an
           $Ende1nachZeichen = 21;                                       // und ist xx Zeichen lang
           $Sensordaten[0] = explode ($Startsequenz1, $Sensoren);
            $SensorkorrROM = "Hardware ID des 1-W Bausteines";
            $Sensordaten[0][0] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[0][1];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende1nachZeichen);
            $Sensordaten[0][1] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[0][2];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende1nachZeichen);
            $Sensordaten[0][2] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[0][3];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende1nachZeichen);
            $Sensordaten[0][3] = $SensorkorrROM;
           SetValueString($this->GetIDForIdent("Sensor1_ROM"), $Sensordaten[0][1]);  // und füllen damit die Variable, und dann Befüllen aus dem Array
           SetValueString($this->GetIDForIdent("Sensor2_ROM"), $Sensordaten[0][2]);  // und füllen damit die Variable, und dann Befüllen aus dem Array
           SetValueString($this->GetIDForIdent("Sensor3_ROM"), $Sensordaten[0][3]);  // und füllen damit die Variable, und dann Befüllen aus dem Array

           $Startsequenz2 = "Chip = ";                                    // damit fängt der Datensatz an
           $Ende2nachZeichen = 8;                                         // und ist xx Zeichen lang
           $Sensordaten[1] = explode ($Startsequenz2, $Sensoren);
            $SensorkorrROM = "Typ des 1-W Bausteines";
            $Sensordaten[1][0] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[1][1];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende2nachZeichen);
            $Sensordaten[1][1] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[1][2];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende2nachZeichen);
            $Sensordaten[1][2] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[1][3];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende2nachZeichen);
            $Sensordaten[1][3] = $SensorkorrROM;
           SetValueString($this->GetIDForIdent("Sensor1_Typ"), $Sensordaten[1][1]);  // und füllen damit die Variable, und dann Befüllen aus dem Array
           SetValueString($this->GetIDForIdent("Sensor2_Typ"), $Sensordaten[1][2]);  // und füllen damit die Variable, und dann Befüllen aus dem Array
           SetValueString($this->GetIDForIdent("Sensor3_Typ"), $Sensordaten[1][3]);  // und füllen damit die Variable, und dann Befüllen aus dem Array

           $Startsequenz3 = "Temperature = ";                              // damit fängt der Datensatz an
           $Ende3nachZeichen = 5;                                          // und ist xx Zeichen lang
           $Sensordaten[2] = explode ($Startsequenz3, $Sensoren);
            $SensorkorrROM = "Temperatur des 1-W Bausteines in Celsius";
            $Sensordaten[2][0] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[2][1];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende3nachZeichen);
            $Sensordaten[2][1] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[2][2];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende3nachZeichen);
            $Sensordaten[2][2] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[2][3];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende3nachZeichen);
            $Sensordaten[2][3] = $SensorkorrROM;
           SetValueFloat($this->GetIDForIdent("Sensor1_Temp"), $Sensordaten[2][1]);  // und füllen damit die Variable, und dann Befüllen aus dem Array
           SetValueFloat($this->GetIDForIdent("Sensor2_Temp"), $Sensordaten[2][2]);  // und füllen damit die Variable, und dann Befüllen aus dem Array
           SetValueFloat($this->GetIDForIdent("Sensor3_Temp"), $Sensordaten[2][3]);  // und füllen damit die Variable, und dann Befüllen aus dem Array
           }
           else
           {
           SetValueString($BufferID, $all);                              // schreibt alles wieder zurück, weil es noch nicht vollständig war
           }
    }