From 3587b27a04068ddafef389f9a08436e636604124 Mon Sep 17 00:00:00 2001 From: "belevo\\mh" Date: Tue, 15 Oct 2024 10:12:48 +0200 Subject: [PATCH] Server Kommunikation zu influx V1 --- Belevo_Server_Kommunikation/form.json | 74 +++++++++++++++ Belevo_Server_Kommunikation/module.php | 126 ++++++++++++++++++++++++- Michisplayground/README.md | 67 +++++++++++++ Michisplayground/form.json | 20 ++++ Michisplayground/locale.json | 7 ++ Michisplayground/module.json | 3 + Michisplayground/module.php | 8 ++ 7 files changed, 303 insertions(+), 2 deletions(-) create mode 100644 Belevo_Server_Kommunikation/form.json create mode 100644 Michisplayground/README.md create mode 100644 Michisplayground/form.json create mode 100644 Michisplayground/locale.json create mode 100644 Michisplayground/module.json create mode 100644 Michisplayground/module.php diff --git a/Belevo_Server_Kommunikation/form.json b/Belevo_Server_Kommunikation/form.json new file mode 100644 index 0000000..26f7fed --- /dev/null +++ b/Belevo_Server_Kommunikation/form.json @@ -0,0 +1,74 @@ +{ + "elements": [ + { + "type" : "Label", + "caption" : "Influx Punkte" + }, + { + "type": "List", + "name": "Keine", + "caption": "Keine Auswahl", + "suffix": "" + }, + { + "type": "List", + "name": "G_BS_5M_0", + "caption": "Netzbezug", + "suffix": "" + }, + { + "type": "List", + "name": "G_BS_5M_0", + "caption": "Boilerstatus", + "suffix": "" + }, + { + "type": "List", + "name": "G_BT_5M_0", + "caption": "Boilertemperatur", + "suffix": "" + }, + { + "type": "List", + "name": "G_SK_5M_1", + "caption": "Schaltkontakt 1", + "suffix": "" + }, + { + "type": "List", + "name": "G_SK_5M_2", + "caption": "Schaltkontakt 2", + "suffix": "" + }, + { + "type": "List", + "name": "G_SK_5M_3", + "caption": "Schaltkontakt 3", + "suffix": "" + }, + { + "type": "List", + "name": "G_SK_5M_4", + "caption": "Schaltkontakt 4", + "suffix": "" + }, + { + "type": "List", + "name": "G_WPS_5M_0", + "caption": "Wärmepumpe Status", + "suffix": "" + }, + { + "type": "List", + "name": "G_WW_5M_0", + "caption": "Wolkenwahrscheinlichkeit", + "suffix": "" + }, + { + "type": "List", + "name": "G_AT_5M_0", + "caption": "Aussentemperatur", + "suffix": "" + } + ] +} diff --git a/Belevo_Server_Kommunikation/module.php b/Belevo_Server_Kommunikation/module.php index 5d22763..d8b92ce 100644 --- a/Belevo_Server_Kommunikation/module.php +++ b/Belevo_Server_Kommunikation/module.php @@ -5,15 +5,137 @@ class Belevo_Server_Kommunikation extends IPSModule public function Create() { + // Zweite Gleiche Variable wird in der Benutzeroberfläche von Symcon angezeigt + //Variable: dynamische Daten + //Property: statische Konfigurationsdaten parent::Create(); - + //Netzbezug + $this->RegisterVariableFloat("E_PNB_5M_0", "E_PNB_5M_0", "",0); + $this->RegisterVariableFloat("Netzbezug", "Netzbezug", "",0); + //Boilerstatus + $this->RegisterVariableInteger("G_BS_5M_0", "G_BS_5M_0", "",0); + //Boilertemperatur + $this->RegisterVariableFloat("G_BT_5M_0", "G_BT_5M_0", "",0); // Wird an Influx Server gesendet + $this->RegisterVariableFloat("Boilertemperatur", 0); // Ist, Jetzige Boilertemperatur + //Schaltkontake des Boilers + $this->RegisterVariableInteger("G_SK_5M_1", "G_SK_5M_1", "",0); + $this->RegisterVariableInteger("G_SK_5M_2", "G_SK_5M_2", "",0); + //Schaltkontake des Boilers + $this->RegisterVariableInteger("G_SK_5M_3", "G_SK_5M_3", "",0); + $this->RegisterVariableInteger("Kontakt_Teillast", 0); + $this->RegisterVariableInteger("G_SK_5M_4", "G_SK_5M_4", "",0); + $this->RegisterVariableInteger("Kontakt_Volllast", 0); + //Wärmepumpe Status + $this->RegisterVariableFloat("G_WPS_5M_0", "G_WPS_5M_0", "",0); + //Wolkenwahrscheinlichkeit + $this->RegisterVariableFloat("G_WW_5M_0", "G_WW_5M_0", "",0); + //Aussentemperatur + $this->RegisterVariableFloat("G_AT_5M_0", "G_AT_5M_0", "",0); + + $this->RegisterPropertyString("BaseURL","https://brain.belevo.ch/status?nr="); + $this->RegisterPropertyString("Anlagenummer",0); + $this->RegisterPropertyBoolean("InfluxJaNein", false); + + + $this->RegisterTimer("Timer_Influx", 0, 'IPS_RequestAction(' . $this->InstanceID . ', "GetAction", "");');// 5min = 1000 * 60 * 5 = 300'000ms } public function ApplyChanges() { - return; + parent::ApplyChanges(); + $jaNeinAuswahl = $this->ReadPropertyBoolean("JaNeinAuswahl"); + if ($jaNeinAuswahl) { + // Timer auf 5 Minuten setzen + $this->SetTimerInterval("Timer_Influx", 300000); + } else { + // Timer stoppen + $this->SetTimerInterval("Timer_Influx", 0); + } } + + + public function RequestAction($Ident, $Value) + { + switch ($Ident) { + case "GetAction": + $this->GetAction(); + break; + default: + throw new Exception("Invalid action"); + } + } + + public function GetAction() { + + $jaNeinAuswahl = $this->ReadPropertyBoolean("JaNeinAuswahl"); + + if ($jaNeinAuswahl) { + $json = $this->MakeJson(); + $baseURL = $this->ReadPropertyString("BaseURL"); + $anlagenummer = $this->ReadPropertyString("Anlagenummer"); + // Kombiniere die URL mit der Anlagenummer + $fullURL = $baseURL . $anlagenummer; + $this->SendJsonToInfluxDB($fullURL, $json); + echo "Aufzeichnung im Influx"; + } else { + echo "Keine Aufzeichnung im Influx"; + } + } + + + public function MakeJson() { + +$boilertemperatur = $this->GetValue("Boilertemperatur"); +$this->SetValue("G_BT_5M_0", $boilertemperatur); + +$kontaktTeillast = $this->GetValue("Kontakt_Teillast"); +$this->SetValue("G_SK_5M_3", $kontaktTeillast); + +$kontaktVolllast = $this->GetValue("Kontakt_Volllast"); +$this->SetValue("G_SK_5M_4", $kontaktVolllast); + +$netzbezug = $this->GetValue("Netzbezug"); +$this->SetValue("E_PNB_5M_0", $netzbezug); + +// Werte in ein Array packen +$data = [ + "G_BT_5M_0" => $this->GetValue("G_BT_5M_0"), + "G_SK_5M_3" => $this->GetValue("G_SK_5M_3"), + "G_SK_5M_4" => $this->GetValue("G_SK_5M_4"), + "E_PNB_5M_0" => $this->GetValue("E_PNB_5M_0"), +]; + +// Array in JSON konvertieren +$json = json_encode($data); + +// JSON zurückgeben oder weiterverarbeiten +return $json; + + } + + + private function SendJsonToInfluxDB($url, $json) +{ + $options = [ + 'http' => [ + 'header' => "Content-Type: application/json\r\n", + 'method' => 'POST', + 'content' => $json, + ], + ]; + $context = stream_context_create($options); + $result = file_get_contents($url, false, $context); + + if ($result === FALSE) { + + echo "Fehler beim Senden der Daten an InfluxDB."; + } else { + echo "Daten erfolgreich an InfluxDB gesendet."; + } +} + + } ?> \ No newline at end of file diff --git a/Michisplayground/README.md b/Michisplayground/README.md new file mode 100644 index 0000000..b059e3a --- /dev/null +++ b/Michisplayground/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/Michisplayground/form.json b/Michisplayground/form.json new file mode 100644 index 0000000..0915032 --- /dev/null +++ b/Michisplayground/form.json @@ -0,0 +1,20 @@ +{ + "elements": [ + { + "type": "Label", + "caption": "Verwende die Buttons, um den Zähler zu steuern." + }, + { + "type": "Button", + "caption": "Addierer", + "onClick": "ZAEHL_AdditionMethode($id);" + }, + { + "type": "Suptrahierer", + "caption": "Zähler zurücksetzen", + "onClick": "ZAEHL_Subtraktionsmethode($id);" + } + + ], + "actions": [] +} diff --git a/Michisplayground/locale.json b/Michisplayground/locale.json new file mode 100644 index 0000000..4aefba5 --- /dev/null +++ b/Michisplayground/locale.json @@ -0,0 +1,7 @@ +{ + "translations": { + "de": { + + } + } +} \ No newline at end of file diff --git a/Michisplayground/module.json b/Michisplayground/module.json new file mode 100644 index 0000000..0e0dcd2 --- /dev/null +++ b/Michisplayground/module.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/Michisplayground/module.php b/Michisplayground/module.php new file mode 100644 index 0000000..87f1c03 --- /dev/null +++ b/Michisplayground/module.php @@ -0,0 +1,8 @@ +