diff --git a/Belevo_Server_Kommunikation/form.json b/Belevo_Server_Kommunikation/form.json index e83a582..129bf2a 100644 --- a/Belevo_Server_Kommunikation/form.json +++ b/Belevo_Server_Kommunikation/form.json @@ -20,16 +20,21 @@ "suffix": "", "validate": "^An_\\d{4}$" }, + { + "type": "ValidationTextBox", + "name": "GeräteNummer", + "caption": "Gerätenummer" + }, { "type": "List", "name": "ZusatzVariablen", - "caption": "Zusätzliche Variablen für Influx", + "caption": "Zusätzliche Datenpunkte für Influxaufzeichnung", "add": true, "delete": true, "columns": [ { - "caption": "Variablenname", + "caption": "Influx Name", "name": "Variablenname", "width": "200px", "add": "", @@ -38,7 +43,7 @@ } }, { - "caption": "Variable", + "caption": "Datenpunkt", "name": "Variable", "width": "300px", "add": 0, diff --git a/Belevo_Server_Kommunikation/module.php b/Belevo_Server_Kommunikation/module.php index 9670fe2..91686b6 100644 --- a/Belevo_Server_Kommunikation/module.php +++ b/Belevo_Server_Kommunikation/module.php @@ -14,9 +14,10 @@ class Belevo_Server_Kommunikation extends IPSModule $this->RegisterPropertyBoolean("InfluxJaNein", false); // JSON-String für Zusatzvariablen - $this->RegisterPropertyString("ZusatzVariablen", json_encode([])); - $this->RegisterPropertyString("Variable","0"); - $this->RegisterPropertyString("Variablenname","0"); + $this->RegisterPropertyString("ZusatzVariablen", json_encode([]));// Bezeichnung der Liste + $this->RegisterPropertyString("Variable","0"); // Datenpunkt kann im Syncom ausgewählt werden + $this->RegisterPropertyString("Variablenname","0"); // Name für Influxaufzeichnung + $this->RegisterPropertyString("GeräteNummer","0"); // Timer registrieren $this->RegisterTimer("Timer_Influx", 0, 'IPS_RequestAction(' . $this->InstanceID . ', "GetAction", "");'); @@ -31,7 +32,7 @@ class Belevo_Server_Kommunikation extends IPSModule if ($InfluxJaNein) { // Timer auf 5 Minuten setzen - $this->SetTimerInterval("Timer_Influx", 5000); // Alle 5 Sekunden + $this->SetTimerInterval("Timer_Influx", 5000); // Alle 5 Minuten -> 5*60*1000=300000 IPS_LogMessage("Belevo_Server_Kommunikation", "Influx Ja"); @@ -67,7 +68,7 @@ class Belevo_Server_Kommunikation extends IPSModule // Überprüfen, ob die Variable existiert if (IPS_VariableExists($variableID)) { $wert = GetValue($variableID); // Den aktuellen Wert der Zusatzvariable abrufen - IPS_LogMessage("Belevo_Server_Kommunikation", "Name: $variablenname, ID: $variableID, Wert: $wert"); + // Wert dem Variablenname zuweisen $output[$variablenname] = $wert; @@ -108,9 +109,7 @@ class Belevo_Server_Kommunikation extends IPSModule if (!empty($json)) { // Kombiniere die URL mit der Anlagenummer - $fullURL = $baseURL; - IPS_LogMessage("Belevo_Server_Kommunikation", "URL: ".$fullURL); - IPS_LogMessage("Belevo_Server_Kommunikation", "JSON: " . $json); + $fullURL = $baseURL $this->SendJsonToInfluxDB($fullURL, $json); } else { IPS_LogMessage("Belevo_Server_Kommunikation", "Keine Aufzeichnung im Influx: Anlagenummer oder JSON-Daten fehlen->GetAction()"); @@ -118,7 +117,7 @@ class Belevo_Server_Kommunikation extends IPSModule } // Werte in ein Array packen -public function MakeJson($a) +public function MakeJson($json) { $an_nummer = $this->ReadPropertyString("Anlagenummer"); // Anlagenummer lesen $InfluxJaNein = $this->ReadPropertyBoolean("InfluxJaNein"); @@ -131,14 +130,14 @@ public function MakeJson($a) "Parameter" => array( "Influxadr" => $an_nummer ), - "Tracker" => $a // Initialisiere Tracker als leeres Array + "Tracker" => $json // Initialisiere Tracker als leeres Array ); // Array in JSON konvertieren $json = json_encode($influxData); - IPS_LogMessage("MakeJson", "Erstelltes JSON: " . $json); + IPS_LogMessage("Belevo_Server_Kommunikation", "Erstelltes JSON: " . $json); // JSON zurückgeben oder weiterverarbeiten return $json; @@ -149,7 +148,7 @@ public function MakeJson($a) private function SendJsonToInfluxDB($url, $jsonData) { // cURL Initialisieren $curl = curl_init(); - + $pw =$this->ReadPropertyString("Passwort"); // Optionen für cURL-Request definieren curl_setopt_array($curl, [ CURLOPT_URL => $url, @@ -158,7 +157,7 @@ private function SendJsonToInfluxDB($url, $jsonData) { CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', // Header für JSON-Daten setzen 'Accept: application/json', - 'id: test' + 'id:'.$pw ], CURLOPT_POSTFIELDS => $jsonData // JSON-Daten als POST-Feld senden ]); diff --git a/library.json b/library.json index 6e244d7..907d173 100644 --- a/library.json +++ b/library.json @@ -6,7 +6,7 @@ "compatibility": { "version": "7.1" }, - "version": "0.84", + "version": "0.85", "build": 0, "date": 0 } \ No newline at end of file