diff --git a/Belevo_Server_Kommunikation/module.json b/Belevo_Server_Kommunikation/module.json index d736773..3c37d4c 100644 --- a/Belevo_Server_Kommunikation/module.json +++ b/Belevo_Server_Kommunikation/module.json @@ -1,5 +1,5 @@ { - "id": "{21F800F4-A506-62C9-CF26-9CA652629C22}", + "id": "{9449616A-D571-8D4A-E917-A3DD338F00A6}", "name": "Belevo_Server_Kommunikation", "type": 3, "vendor": "Belevo AG", diff --git a/Belevo_Server_Kommunikation/module.php b/Belevo_Server_Kommunikation/module.php index 1f6c055..ad1e66a 100644 --- a/Belevo_Server_Kommunikation/module.php +++ b/Belevo_Server_Kommunikation/module.php @@ -11,7 +11,7 @@ class Belevo_Server_Kommunikation extends IPSModule parent::Create(); //Netzbezug $this->RegisterPropertyFloat("E_PNB_5M_0", 0); - $this->RegisterVariableFloat("Netzbezug", "Netzbezug", "",0); + $this->RegisterPropertyFloat("Netzbezug", "", "",0); /*//Boilerstatus $this->RegisterPropertyInteger("G_BS_5M_0", 0); $this->RegisterVariableInteger("Boilerstatus", 0); @@ -41,6 +41,7 @@ class Belevo_Server_Kommunikation extends IPSModule $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 @@ -52,10 +53,12 @@ class Belevo_Server_Kommunikation extends IPSModule $InfluxJaNein = $this->ReadPropertyBoolean("InfluxJaNein"); if ($InfluxJaNein) { // Timer auf 5 Minuten setzen - $this->SetTimerInterval("Timer_Influx", 300000); + $this->SetTimerInterval("Timer_Influx", 10000);//Alle 10 Sekunden + IPS_LogMessage("Belevo_Server_Kommunikation", "Influx Ja"); } else { // Timer stoppen $this->SetTimerInterval("Timer_Influx", 0); + IPS_LogMessage("Belevo_Server_Kommunikation", "Influx Nein"); } } @@ -72,22 +75,19 @@ class Belevo_Server_Kommunikation extends IPSModule } } - public function GetAction() { - - $jaNeinAuswahl = $this->ReadPropertyBoolean("JaNeinAuswahl"); - - if ($jaNeinAuswahl) { + public function GetAction() { $json = $this->MakeJson(); $baseURL = $this->ReadPropertyString("BaseURL"); $anlagenummer = $this->ReadPropertyString("Anlagenummer"); - // Kombiniere die URL mit der Anlagenummer - $fullURL = $baseURL . $anlagenummer; - $this->SendJsonToInfluxDB($fullURL, $json); - - } else { - IPS_LogMessage("Belevo_Server_Kommunikation", "Keine Aufzeichnung im Influx"); + + if (!empty($anlagenummer) && !empty($json)) { + // Kombiniere die URL mit der Anlagenummer + $fullURL = $baseURL . $anlagenummer; + $this->SendJsonToInfluxDB($fullURL, $json); + } else { + IPS_LogMessage("Belevo_Server_Kommunikation", "Keine Aufzeichnung im Influx: Anlagenummer oder JSON-Daten fehlen->GetAction()"); + } } - } public function MakeJson() { @@ -106,12 +106,12 @@ $this->SetValue("E_PNB_5M_0", $netzbezug); // Werte in ein Array packen $data = [ - "_measurement" => $this->ReadPropertyString("Anlagenummer"), - "_field" =>[ + "measurement" => $this->ReadPropertyString("Anlagenummer"), + "field" =>[ //"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"), + "E_PNB_5M_0" => $netzbezug, ] ]; @@ -126,13 +126,19 @@ return $json; private function SendJsonToInfluxDB($url, $json) { - $token = "iFNTONC5UvST8GT5itWqxiO6m4O1yHt5hus54J8eqotk5IZiq0Wjd0_Xi6dozmo32QR3esJqk6hJAvJ8X2SxtQ=="; + // $token = "Token iFNTONC5UvST8GT5itWqxiO6m4O1yHt5hus54J8eqotk5IZiq0Wjd0_Xi6dozmo32QR3esJqk6hJAvJ8X2SxtQ=="; + /* + if (empty($token)) { + IPS_LogMessage("Belevo_Server_Kommunikation", "InfluxDB-Token fehlt->SendJsonToInfluxDB"); + return; + }*/ $options = [ 'http' => [ 'header' => "Content-Type: application/json\r\n". - "Authorization: Bearer $token\r\n", + "daten: $json". + "id: test\r\n", 'method' => 'POST', - 'content' => $json, + ], ]; $context = stream_context_create($options); @@ -140,9 +146,9 @@ return $json; if ($result === FALSE) { - IPS_LogMessage("Belevo_Server_Kommunikation", "Fehler beim senden an Influx"); + IPS_LogMessage("Belevo_Server_Kommunikation", "Fehler beim senden an Influx->SendJsonToInfluxDB()"); } else { - IPS_LogMessage("Belevo_Server_Kommunikation", "Daten erfolgreich an Influx gesendet"); + IPS_LogMessage("Belevo_Server_Kommunikation", "Daten erfolgreich an Influx gesendet->SendJsonToInfluxDB()"); } } diff --git a/Michisplayground/form.json b/Michisplayground/form.json index 0915032..29f50ec 100644 --- a/Michisplayground/form.json +++ b/Michisplayground/form.json @@ -10,7 +10,7 @@ "onClick": "ZAEHL_AdditionMethode($id);" }, { - "type": "Suptrahierer", + "type": "Button", "caption": "Zähler zurücksetzen", "onClick": "ZAEHL_Subtraktionsmethode($id);" } diff --git a/Michisplayground/module.json b/Michisplayground/module.json index 0e0dcd2..4c8cfe8 100644 --- a/Michisplayground/module.json +++ b/Michisplayground/module.json @@ -1,3 +1,11 @@ { - + "id": "{{097D2D9F-2144-C47B-7755-6A0F93B24325}}", + "name": "Michisplayground", + "type": 3, + "vendor": "Belevo AG", + "parentRequirements": [], + "childRequirements": [], + "implemented": [], + "url": "", + "prefix": "ZAEHL" } \ No newline at end of file diff --git a/Michisplayground/module.php b/Michisplayground/module.php index 87f1c03..bbe02f8 100644 --- a/Michisplayground/module.php +++ b/Michisplayground/module.php @@ -2,7 +2,47 @@ class Michisplayground extends IPSModule { + // Konstruktor + public function __construct($InstanceID) + { + parent::__construct($InstanceID); + } + public function ApplyChanges() + { + parent::ApplyChanges(); + + // Registriere die Zählervariable, wenn sie nicht bereits existiert + if (!IPS_VariableExists($this->GetIDForIdent("Counter"))) { + $this->RegisterVariableInteger("Counter", "Zähler", "", 1); + SetValue($this->GetIDForIdent("Counter"), 0); // Setze den Zähler auf 0 + } + } + + // Methode zum Erhöhen des Zählers + public function AdditionMethode() + { + $currentValue = GetValue($this->GetIDForIdent("Counter")); + $newValue = $currentValue + 1; + SetValue($this->GetIDForIdent("Counter"), $newValue); + IPS_LogMessage("ErweiterterZaehlerModul", "Zähler erhöht: " . $newValue); + } + + // Methode zum Zurücksetzen des Zählers + public function Subtraktionsmethode() + { + SetValue($this->GetIDForIdent("Counter"), 0); + IPS_LogMessage("ErweiterterZaehlerModul", "Zähler zurückgesetzt."); + } + + // Methode zum Abfragen des Zählers + public function GetCounter() + { + $currentValue = GetValue($this->GetIDForIdent("Counter")); + IPS_LogMessage("ErweiterterZaehlerModul", "Aktueller Zählerstand: " . $currentValue); + return $currentValue; // Gibt den aktuellen Zählerstand zurück + } + } ?> diff --git a/library.json b/library.json index 03d1050..b0a9280 100644 --- a/library.json +++ b/library.json @@ -6,7 +6,7 @@ "compatibility": { "version": "7.1" }, - "version": "0.33", + "version": "0.34", "build": 0, "date": 0 } \ No newline at end of file