RegisterPropertyFloat("E_PNB_5M_0", 0); $this->RegisterPropertyInteger("Netzbezug", 0); /*//Boilerstatus $this->RegisterPropertyInteger("G_BS_5M_0", 0); $this->RegisterPropertyInteger("Boilerstatus", 0); //Boilertemperatur $this->RegisterPropertyFloat("G_BT_5M_0",0); // Wird an Influx Server gesendet $this->RegisterPropertyInteger("Boilertemperatur", 0); // Ist, Jetzige Boilertemperatur //Schaltkontake des Boilers $this->RegisterPropertyInteger("G_SK_5M_1",0); $this->RegisterPropertyInteger("Schaltkontakt_1", 0); $this->RegisterPropertyInteger("G_SK_5M_2",0); $this->RegisterPropertyInteger("Schaltkontakt_2", 0); //Schaltkontake des Boilers $this->RegisterPropertyInteger("G_SK_5M_3",0); $this->RegisterPropertyInteger("Kontakt_Teillast", 0); $this->RegisterPropertyInteger("G_SK_5M_4",0); $this->RegisterPropertyInteger("Kontakt_Volllast", 0); //Wärmepumpe Status $this->RegisterPropertyFloat("G_WPS_5M_0",0); $this->RegisterPropertyInteger("Waermepumpe_Status", 0); //Wolkenwahrscheinlichkeit $this->RegisterPropertyFloat("G_WW_5M_0",0); $this->RegisterPropertyInteger("Wolkenwahrscheinlichkeit", 0); //Aussentemperatur $this->RegisterPropertyFloat("G_AT_5M_0",0); $this->RegisterPropertyInteger("Aussentemperatur", 0); */ //$this->RegisterPropertyString("BaseURL","https://brain.belevo.ch/status?nr="); $this->RegisterPropertyString("BaseURL","192.168.20.140:5000/influx?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() { parent::ApplyChanges(); $InfluxJaNein = $this->ReadPropertyBoolean("InfluxJaNein"); if ($InfluxJaNein) { // Timer auf 5 Minuten setzen $this->SetTimerInterval("Timer_Influx", 5000);//Alle 5 Sekunden IPS_LogMessage("Belevo_Server_Kommunikation", "Influx Ja"); } else { // Timer stoppen $this->SetTimerInterval("Timer_Influx", 0); IPS_LogMessage("Belevo_Server_Kommunikation", "Influx Nein"); } } public function RequestAction($Ident, $Value) { switch ($Ident) { case "GetAction": $this->GetAction(); break; default: throw new Exception("Invalid action"); } } /* public function GetAction() { $json = $this->MakeJson(); //$baseURL = $this->ReadPropertyString("BaseURL"); $baseURL = "http://192.168.20.140:5000/influx?nr="; $anlagenummer = $this->ReadPropertyString("Anlagenummer"); if (!empty($anlagenummer) && !empty($json)) { // Kombiniere die URL mit der Anlagenummer $fullURL = $baseURL . $anlagenummer; IPS_LogMessage("Belevo_Server_Kommunikation", "URL: ".$fullURL); IPS_LogMessage("Belevo_Server_Kommunikation", "JSON: " . $json); $this->SendJsonToInfluxDB($fullURL, $json); } else { IPS_LogMessage("Belevo_Server_Kommunikation", "Keine Aufzeichnung im Influx: Anlagenummer oder JSON-Daten fehlen->GetAction()"); } } */ public function GetAction() { $url = "http://192.168.20.140:5000/influx?id=test&E_PNB_5M_0=1000"; IPS_LogMessage("Belevo_Server_Kommunikation", "Sende Anfrage an URL: ".$url); $this->SendJsonToInfluxDB($url); } 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 = GetValue($this->ReadPropertyInteger("Netzbezug")); //$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" => $netzbezug ] ]; // Array in JSON konvertieren $json = json_encode($data); // JSON zurückgeben oder weiterverarbeiten return $json; } /* private function SendJsonToInfluxDB($url, $json) { // Header für die Anfrage definieren $headers = [ "Content-Type: application/json", "id: test" // Die ID, die vom Flask-Server überprüft wird ]; // Optionen für den HTTP-Request definieren $options = [ 'http' => [ 'header' => implode("\r\n", $headers), 'method' => 'POST', 'content' => $json // JSON-Inhalt im Body der Anfrage ], ]; IPS_LogMessage("Belevo_Server_Kommunikation", "Options: " . print_r($options, true)); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); IPS_LogMessage("Belevo_Server_Kommunikation", "Result: " . print_r($result , true)); if ($result === FALSE) { IPS_LogMessage("Belevo_Server_Kommunikation", "Fehler beim senden an Influx->SendJsonToInfluxDB()"); } else { IPS_LogMessage("Belevo_Server_Kommunikation", "Daten erfolgreich an Influx gesendet->SendJsonToInfluxDB()"); } } */ private function SendJsonToInfluxDB($url) { // 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, ]); // cURL-Request ausführen $result = curl_exec($curl); $error = curl_error($curl); // cURL beenden curl_close($curl); // Logging der Antwort und eventueller Fehler if ($error) { IPS_LogMessage("Belevo_Server_Kommunikation", "Fehler beim Senden an Influx: " . $error); } else { IPS_LogMessage("Belevo_Server_Kommunikation", "Antwort von Influx: " . $result); } } } ?>