Server Kommunikation zu influx V1
This commit is contained in:
@@ -5,15 +5,137 @@ class Belevo_Server_Kommunikation extends IPSModule
|
||||
|
||||
public function Create()
|
||||
{
|
||||
// Zweite Gleiche Variable wird in der Benutzeroberfläche von Symcon angezeigt
|
||||
//Variable: dynamische Daten
|
||||
//Property: statische Konfigurationsdaten
|
||||
parent::Create();
|
||||
|
||||
//Netzbezug
|
||||
$this->RegisterVariableFloat("E_PNB_5M_0", "E_PNB_5M_0", "",0);
|
||||
$this->RegisterVariableFloat("Netzbezug", "Netzbezug", "",0);
|
||||
//Boilerstatus
|
||||
$this->RegisterVariableInteger("G_BS_5M_0", "G_BS_5M_0", "",0);
|
||||
//Boilertemperatur
|
||||
$this->RegisterVariableFloat("G_BT_5M_0", "G_BT_5M_0", "",0); // Wird an Influx Server gesendet
|
||||
$this->RegisterVariableFloat("Boilertemperatur", 0); // Ist, Jetzige Boilertemperatur
|
||||
//Schaltkontake des Boilers
|
||||
$this->RegisterVariableInteger("G_SK_5M_1", "G_SK_5M_1", "",0);
|
||||
$this->RegisterVariableInteger("G_SK_5M_2", "G_SK_5M_2", "",0);
|
||||
//Schaltkontake des Boilers
|
||||
$this->RegisterVariableInteger("G_SK_5M_3", "G_SK_5M_3", "",0);
|
||||
$this->RegisterVariableInteger("Kontakt_Teillast", 0);
|
||||
$this->RegisterVariableInteger("G_SK_5M_4", "G_SK_5M_4", "",0);
|
||||
$this->RegisterVariableInteger("Kontakt_Volllast", 0);
|
||||
//Wärmepumpe Status
|
||||
$this->RegisterVariableFloat("G_WPS_5M_0", "G_WPS_5M_0", "",0);
|
||||
//Wolkenwahrscheinlichkeit
|
||||
$this->RegisterVariableFloat("G_WW_5M_0", "G_WW_5M_0", "",0);
|
||||
//Aussentemperatur
|
||||
$this->RegisterVariableFloat("G_AT_5M_0", "G_AT_5M_0", "",0);
|
||||
|
||||
$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
|
||||
}
|
||||
|
||||
public function ApplyChanges()
|
||||
{
|
||||
return;
|
||||
parent::ApplyChanges();
|
||||
$jaNeinAuswahl = $this->ReadPropertyBoolean("JaNeinAuswahl");
|
||||
if ($jaNeinAuswahl) {
|
||||
// Timer auf 5 Minuten setzen
|
||||
$this->SetTimerInterval("Timer_Influx", 300000);
|
||||
} else {
|
||||
// Timer stoppen
|
||||
$this->SetTimerInterval("Timer_Influx", 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function RequestAction($Ident, $Value)
|
||||
{
|
||||
switch ($Ident) {
|
||||
case "GetAction":
|
||||
$this->GetAction();
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid action");
|
||||
}
|
||||
}
|
||||
|
||||
public function GetAction() {
|
||||
|
||||
$jaNeinAuswahl = $this->ReadPropertyBoolean("JaNeinAuswahl");
|
||||
|
||||
if ($jaNeinAuswahl) {
|
||||
$json = $this->MakeJson();
|
||||
$baseURL = $this->ReadPropertyString("BaseURL");
|
||||
$anlagenummer = $this->ReadPropertyString("Anlagenummer");
|
||||
// Kombiniere die URL mit der Anlagenummer
|
||||
$fullURL = $baseURL . $anlagenummer;
|
||||
$this->SendJsonToInfluxDB($fullURL, $json);
|
||||
echo "Aufzeichnung im Influx";
|
||||
} else {
|
||||
echo "Keine Aufzeichnung im Influx";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 = $this->GetValue("Netzbezug");
|
||||
$this->SetValue("E_PNB_5M_0", $netzbezug);
|
||||
|
||||
// Werte in ein Array packen
|
||||
$data = [
|
||||
"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
|
||||
$json = json_encode($data);
|
||||
|
||||
// JSON zurückgeben oder weiterverarbeiten
|
||||
return $json;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function SendJsonToInfluxDB($url, $json)
|
||||
{
|
||||
$options = [
|
||||
'http' => [
|
||||
'header' => "Content-Type: application/json\r\n",
|
||||
'method' => 'POST',
|
||||
'content' => $json,
|
||||
],
|
||||
];
|
||||
$context = stream_context_create($options);
|
||||
$result = file_get_contents($url, false, $context);
|
||||
|
||||
if ($result === FALSE) {
|
||||
|
||||
echo "Fehler beim Senden der Daten an InfluxDB.";
|
||||
} else {
|
||||
echo "Daten erfolgreich an InfluxDB gesendet.";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user