From 085c8a8567ec1698aab5bcb57d9a3226f583e9bf Mon Sep 17 00:00:00 2001 From: "belevo\\mh" Date: Tue, 15 Oct 2024 14:44:43 +0200 Subject: [PATCH] =?UTF-8?q?Server=20Kommunilation=20Influx=20verbindung=20?= =?UTF-8?q?erg=C3=A4nzt=20LodMessage=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Belevo_Server_Kommunikation/module.php | 15 ++++++++++----- library.json | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Belevo_Server_Kommunikation/module.php b/Belevo_Server_Kommunikation/module.php index 36412f6..1f6c055 100644 --- a/Belevo_Server_Kommunikation/module.php +++ b/Belevo_Server_Kommunikation/module.php @@ -83,9 +83,9 @@ class Belevo_Server_Kommunikation extends IPSModule // Kombiniere die URL mit der Anlagenummer $fullURL = $baseURL . $anlagenummer; $this->SendJsonToInfluxDB($fullURL, $json); - echo "Aufzeichnung im Influx"; + } else { - echo "Keine Aufzeichnung im Influx"; + IPS_LogMessage("Belevo_Server_Kommunikation", "Keine Aufzeichnung im Influx"); } } @@ -106,10 +106,13 @@ $this->SetValue("E_PNB_5M_0", $netzbezug); // Werte in ein Array packen $data = [ + "_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"), + ] ]; // Array in JSON konvertieren @@ -123,9 +126,11 @@ return $json; private function SendJsonToInfluxDB($url, $json) { + $token = "iFNTONC5UvST8GT5itWqxiO6m4O1yHt5hus54J8eqotk5IZiq0Wjd0_Xi6dozmo32QR3esJqk6hJAvJ8X2SxtQ=="; $options = [ 'http' => [ - 'header' => "Content-Type: application/json\r\n", + 'header' => "Content-Type: application/json\r\n". + "Authorization: Bearer $token\r\n", 'method' => 'POST', 'content' => $json, ], @@ -135,9 +140,9 @@ return $json; if ($result === FALSE) { - echo "Fehler beim Senden der Daten an InfluxDB."; + IPS_LogMessage("Belevo_Server_Kommunikation", "Fehler beim senden an Influx"); } else { - echo "Daten erfolgreich an InfluxDB gesendet."; + IPS_LogMessage("Belevo_Server_Kommunikation", "Daten erfolgreich an Influx gesendet"); } } diff --git a/library.json b/library.json index 54e6c6c..03d1050 100644 --- a/library.json +++ b/library.json @@ -6,7 +6,7 @@ "compatibility": { "version": "7.1" }, - "version": "0.32", + "version": "0.33", "build": 0, "date": 0 } \ No newline at end of file