diff --git a/Belevo_Server_Kommunikation/module.php b/Belevo_Server_Kommunikation/module.php index ef6003d..3af2272 100644 --- a/Belevo_Server_Kommunikation/module.php +++ b/Belevo_Server_Kommunikation/module.php @@ -75,11 +75,11 @@ class Belevo_Server_Kommunikation extends IPSModule throw new Exception("Invalid action"); } } -/* + public function GetAction() { $json = $this->MakeJson(); - //$baseURL = $this->ReadPropertyString("BaseURL"); - $baseURL = "http://192.168.20.140:5000/influx?nr="; + $baseURL = $this->ReadPropertyString("BaseURL"); + $anlagenummer = $this->ReadPropertyString("Anlagenummer"); if (!empty($anlagenummer) && !empty($json)) { @@ -92,15 +92,15 @@ class Belevo_Server_Kommunikation extends IPSModule IPS_LogMessage("Belevo_Server_Kommunikation", "Keine Aufzeichnung im Influx: Anlagenummer oder JSON-Daten fehlen->GetAction()"); } } -*/ +/* public function GetAction() { $netzbezug = GetValue($this->ReadPropertyInteger("Netzbezug")); $url = "http://192.168.20.140:5000/influx?id=test&E_PNB_5M_0=".$netzbezug; IPS_LogMessage("Belevo_Server_Kommunikation", "Sende Anfrage an URL: ".$url); $this->SendJsonToInfluxDB($url); -} +}*/ public function MakeJson() { @@ -115,19 +115,26 @@ $kontaktVolllast = $this->GetValue("Kontakt_Volllast"); $this->SetValue("G_SK_5M_4", $kontaktVolllast); */ $netzbezug = GetValue($this->ReadPropertyInteger("Netzbezug")); +$an_nummer = GetProperty($this->ReadPropertyString("Anlagenummer");) +$InfluxJaNein = $this->ReadPropertyBoolean("InfluxJaNein"); //$this->SetValue("E_PNB_5M_0", $netzbezug); // Werte in ein Array packen -$data = [ - +$influxData = array( + + "Value" => array( + "InfluxAllowed" => $InfluxJaNein // Setze InfluxAllowed auf true für den Test + ), //"Measurement" => $this->ReadPropertyString("Anlagenummer"), - "Field" =>[ + "Parameter" => array($an_nummer + ), + "Tracker" =array( //"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" => $netzbezug - ] -]; + ) + ); // Array in JSON konvertieren $json = json_encode($data); @@ -167,16 +174,21 @@ return $json; } } */ -private function SendJsonToInfluxDB($url) -{ +private function SendJsonToInfluxDB($url, $jsonData) { // cURL Initialisieren $curl = curl_init(); // Optionen für cURL-Request definieren - // Nur die erforderlichen Optionen setzen curl_setopt_array($curl, [ CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, + CURLOPT_POST => true, // POST-Methode verwenden + CURLOPT_HTTPHEADER => [ + 'Content-Type: application/json', // Header für JSON-Daten setzen + 'Accept: application/json' + 'id : test' + ], + CURLOPT_POSTFIELDS => $jsonData // JSON-Daten als POST-Feld senden ]); // cURL-Request ausführen diff --git a/library.json b/library.json index 89c8b82..3604747 100644 --- a/library.json +++ b/library.json @@ -6,7 +6,7 @@ "compatibility": { "version": "7.1" }, - "version": "0.65", + "version": "0.66", "build": 0, "date": 0 } \ No newline at end of file