diff --git a/.gitignore b/.gitignore index 787ac15..6079a58 100644 --- a/.gitignore +++ b/.gitignore @@ -28,5 +28,4 @@ # Module für vorlagen, Testzwecke... /User_Template -/Wechselrichter -/CC100_HW \ No newline at end of file +/Wechselrichter \ No newline at end of file diff --git a/CC100_HW/README.md b/CC100_HW/README.md new file mode 100644 index 0000000..b059e3a --- /dev/null +++ b/CC100_HW/README.md @@ -0,0 +1,67 @@ +# Manager_1 +Beschreibung des Moduls. + +### Inhaltsverzeichnis + +1. [Funktionsumfang](#1-funktionsumfang) +2. [Voraussetzungen](#2-voraussetzungen) +3. [Software-Installation](#3-software-installation) +4. [Einrichten der Instanzen in IP-Symcon](#4-einrichten-der-instanzen-in-ip-symcon) +5. [Statusvariablen und Profile](#5-statusvariablen-und-profile) +6. [WebFront](#6-webfront) +7. [PHP-Befehlsreferenz](#7-php-befehlsreferenz) + +### 1. Funktionsumfang + +* + +### 2. Voraussetzungen + +- IP-Symcon ab Version 7.1 + +### 3. Software-Installation + +* Über den Module Store das 'Manager_1'-Modul installieren. +* Alternativ über das Module Control folgende URL hinzufügen + +### 4. Einrichten der Instanzen in IP-Symcon + + Unter 'Instanz hinzufügen' kann das 'Manager_1'-Modul mithilfe des Schnellfilters gefunden werden. + - Weitere Informationen zum Hinzufügen von Instanzen in der [Dokumentation der Instanzen](https://www.symcon.de/service/dokumentation/konzepte/instanzen/#Instanz_hinzufügen) + +__Konfigurationsseite__: + +Name | Beschreibung +-------- | ------------------ + | + | + +### 5. Statusvariablen und Profile + +Die Statusvariablen/Kategorien werden automatisch angelegt. Das Löschen einzelner kann zu Fehlfunktionen führen. + +#### Statusvariablen + +Name | Typ | Beschreibung +------ | ------- | ------------ + | | + | | + +#### Profile + +Name | Typ +------ | ------- + | + | + +### 6. WebFront + +Die Funktionalität, die das Modul im WebFront bietet. + +### 7. PHP-Befehlsreferenz + +`boolean GEF_BeispielFunktion(integer $InstanzID);` +Erklärung der Funktion. + +Beispiel: +`GEF_BeispielFunktion(12345);` \ No newline at end of file diff --git a/CC100_HW/locale.json b/CC100_HW/locale.json new file mode 100644 index 0000000..294e2a3 --- /dev/null +++ b/CC100_HW/locale.json @@ -0,0 +1,9 @@ + +{ + "translations": { + "de": { + "Translation 1": "Übersetzung 1", + "Translation 2": "Übersetzung 2" + } + } +} \ No newline at end of file diff --git a/CC100_HW/module.json b/CC100_HW/module.json new file mode 100644 index 0000000..af02547 --- /dev/null +++ b/CC100_HW/module.json @@ -0,0 +1,12 @@ +{ + "id": "{21F800F4-A506-62C9-CF26-9CA152629C22}", + "name": "CC100_HW", + "type": 3, + "vendor": "Belevo AG", + "aliases": [], + "parentRequirements": [], + "childRequirements": [], + "implemented": [], + "prefix": "GEF", + "url": "" +} \ No newline at end of file diff --git a/CC100_HW/module.php b/CC100_HW/module.php new file mode 100644 index 0000000..8b53328 --- /dev/null +++ b/CC100_HW/module.php @@ -0,0 +1,121 @@ +RegisterPropertyString('FilePath', $this->DigOutPID); + $this->RegisterVariableBoolean('Bit1', 'DO 1', '~Switch', 1); + $this->RegisterVariableBoolean('Bit2', 'DO 2', '~Switch', 2); + $this->RegisterVariableBoolean('Bit3', 'DO 3', '~Switch', 3); + $this->RegisterVariableBoolean('Bit4', 'DO 4', '~Switch', 4); + $this->RegisterVariableFloat('PT1', 'PT1 Temperatur', '~Temperature', 5); + $this->RegisterVariableFloat('PT2', 'PT2 Temperatur', '~Temperature', 6); + $this->EnableAction('Bit1'); + $this->EnableAction('Bit2'); + $this->EnableAction('Bit3'); + $this->EnableAction('Bit4'); + + // Timer für PT1 und PT2 einrichten + $this->RegisterTimer("ReadPTValues", 30000, 'IPS_RequestAction(' . $this->InstanceID . ', "DOUT_ReadPTValues", "");'); + + } + + public function ApplyChanges() + { + parent::ApplyChanges(); + // Timer aktivieren + $this->SetTimerInterval('ReadPTValues', 30000); + } + + public function RequestAction($Ident, $Value) { + switch ($Ident) { + case "DOUT_ReadPTValues": + $this->DOUT_ReadPTValues(); + break; + + default: + throw new Exception("Invalid Ident"); + } + } + + private function UpdateFile() + { + $starttime = microtime(true) * 1000; + $this->TryWriteFile($starttime); + } + + private function TryWriteFile($starttime) + { + $currentTime = microtime(true) * 1000; + if (($currentTime - $starttime) <= $this->maxTime) { + $file = $this->ReadPropertyString('FilePath'); + if (is_writable($file)) { + $bit1 = GetValueBoolean($this->GetIDForIdent('Bit1')); + $bit2 = GetValueBoolean($this->GetIDForIdent('Bit2')); + $bit3 = GetValueBoolean($this->GetIDForIdent('Bit3')); + $bit4 = GetValueBoolean($this->GetIDForIdent('Bit4')); + + $value = ($bit4 ? 8 : 0) + ($bit3 ? 4 : 0) + ($bit2 ? 2 : 0) + ($bit1 ? 1 : 0); + + if (@file_put_contents($file, $value) === false) { + IPS_LogMessage("DOUTModule", "Fehler: Datei $file konnte nicht beschrieben werden. Möglicherweise gesperrt."); + usleep($this->waitingTime * 1000); + $this->TryWriteFile($starttime); + } else { + IPS_LogMessage("DOUTModule", "Wert $value erfolgreich in die Datei $file geschrieben."); + } + } else { + IPS_LogMessage("DOUTModule", "Fehler: Datei $file ist nicht schreibbar."); + usleep($this->waitingTime * 1000); + $this->TryWriteFile($starttime); + } + } else { + IPS_LogMessage("DOUTModule", "Fehler: Schreibvorgang für Datei $file hat zu lange gedauert."); + } + } + + public function DOUT_ReadPTValues() + { + $pt1Value = $this->ReadPTValue($this->PT1PID); + $pt2Value = $this->ReadPTValue($this->PT2PID); + + SetValue($this->GetIDForIdent('PT1'), $pt1Value); + SetValue($this->GetIDForIdent('PT2'), $pt2Value); + } + + private function ReadPTValue($file) + { + if (file_exists($file)) { + $data = @file_get_contents($file); + if ($data !== false) { + $data = intval($data); + $scale = 0; + if ($data >= 600 && $data < 3600) { $scale = 37;} + else if ($data >= 3600 && $data < 6700) { $scale = 43;} + else if ($data >= 6700 && $data < 9750) { $scale = 45;} + else if ($data >= 9750 && $data < 12740) { $scale = 49;} + else if ($data >= 12740 && $data < 15700) { $scale = 50.6;} + else if ($data >= 15700 && $data < 21000) { $scale = 52.4;} + else if ($data > 21000) { $scale = 53.7;} + + $numb = $data / $scale - 200; + return round($numb, 1); + } else { + IPS_LogMessage("DOUTModule", "Fehler: Datei $file konnte nicht gelesen werden."); + } + } else { + IPS_LogMessage("DOUTModule", "Fehler: Datei $file existiert nicht."); + } + return 0; + } +} + +?>