Einbau von Wetterdatenerfassung in Server_kommunikations_Modul
AT und Wolken
This commit is contained in:
@@ -9,7 +9,7 @@ class Belevo_Server_Kommunikation extends IPSModule
|
|||||||
parent::Create();
|
parent::Create();
|
||||||
|
|
||||||
// Registrierung der Eigenschaften
|
// Registrierung der Eigenschaften
|
||||||
$this->RegisterPropertyString("BaseURL", "http://192.168.20.140:5000/influx");
|
$this->RegisterPropertyString("BaseURL", "https://brain.belevo.ch/storedata");
|
||||||
$this->RegisterPropertyString("Anlagenummer", "0");
|
$this->RegisterPropertyString("Anlagenummer", "0");
|
||||||
$this->RegisterPropertyBoolean("InfluxJaNein", false);
|
$this->RegisterPropertyBoolean("InfluxJaNein", false);
|
||||||
|
|
||||||
@@ -18,6 +18,11 @@ class Belevo_Server_Kommunikation extends IPSModule
|
|||||||
$this->RegisterPropertyString("Variable","0"); // Datenpunkt kann im Syncom ausgewählt werden
|
$this->RegisterPropertyString("Variable","0"); // Datenpunkt kann im Syncom ausgewählt werden
|
||||||
$this->RegisterPropertyString("Variablenname","0"); // Name für Influxaufzeichnung
|
$this->RegisterPropertyString("Variablenname","0"); // Name für Influxaufzeichnung
|
||||||
$this->RegisterPropertyString("Gerätenummer","0");
|
$this->RegisterPropertyString("Gerätenummer","0");
|
||||||
|
$this->RegisterPropertyString("Ortschaft","0");
|
||||||
|
|
||||||
|
$this->RegisterVariableInteger("Wolkenwarscheinlichkeit", "Wolkenwarscheinlichkeit");
|
||||||
|
$this->RegisterVariableInteger("Temperatur", "Temperatur");
|
||||||
|
|
||||||
|
|
||||||
// Timer registrieren
|
// Timer registrieren
|
||||||
$this->RegisterTimer("Timer_Influx", 0, 'IPS_RequestAction(' . $this->InstanceID . ', "GetAction", "");');
|
$this->RegisterTimer("Timer_Influx", 0, 'IPS_RequestAction(' . $this->InstanceID . ', "GetAction", "");');
|
||||||
@@ -32,7 +37,7 @@ class Belevo_Server_Kommunikation extends IPSModule
|
|||||||
|
|
||||||
if ($InfluxJaNein) {
|
if ($InfluxJaNein) {
|
||||||
// Timer auf 5 Minuten setzen
|
// Timer auf 5 Minuten setzen
|
||||||
$this->SetTimerInterval("Timer_Influx", 5000); // Alle 5 Minuten -> 5*60*1000=300000
|
$this->SetTimerInterval("Timer_Influx", 300); // Alle 5 Minuten -> 5*60*1000=300000
|
||||||
IPS_LogMessage("Belevo_Server_Kommunikation", "Influx Ja");
|
IPS_LogMessage("Belevo_Server_Kommunikation", "Influx Ja");
|
||||||
|
|
||||||
|
|
||||||
@@ -44,6 +49,40 @@ class Belevo_Server_Kommunikation extends IPSModule
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getWetter($bn, $pw, $loc) {
|
||||||
|
// URL mit Parametern zusammenstellen
|
||||||
|
$url = "https://brain.belevo.ch/v2wetter?loc=" . urlencode($loc) . "&nr=" . urlencode($bn);
|
||||||
|
|
||||||
|
// HTTP-Anfrage-Header einstellen
|
||||||
|
$headers = [
|
||||||
|
"id: $pw"
|
||||||
|
];
|
||||||
|
|
||||||
|
// cURL-Initialisierung
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
|
||||||
|
// HTTP-Anfrage ausführen und Antwort erhalten
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
// Antwort in ein Array dekodieren
|
||||||
|
$data = json_decode($response, true);
|
||||||
|
|
||||||
|
// Überprüfen, ob die benötigten Felder vorhanden sind und zurückgeben
|
||||||
|
if (isset($data['forecast']['forecastday'][0]['hour'][5]['temp_c']) && isset($data['forecast']['forecastday'][0]['hour'][8]['cloud'])) {
|
||||||
|
return [
|
||||||
|
'temp' => $data['forecast']['forecastday'][0]['hour'][5]['temp_c'],
|
||||||
|
'cloud' => $data['forecast']['forecastday'][0]['hour'][8]['cloud']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fehlerbehandlung
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private function ProcessZusatzVariablen()
|
private function ProcessZusatzVariablen()
|
||||||
{
|
{
|
||||||
// Abrufen der ZusatzVariablen-Liste
|
// Abrufen der ZusatzVariablen-Liste
|
||||||
@@ -106,7 +145,13 @@ class Belevo_Server_Kommunikation extends IPSModule
|
|||||||
$baseURL = $this->ReadPropertyString("BaseURL");
|
$baseURL = $this->ReadPropertyString("BaseURL");
|
||||||
|
|
||||||
$anlagenummer = $this->ReadPropertyString("Anlagenummer");
|
$anlagenummer = $this->ReadPropertyString("Anlagenummer");
|
||||||
|
|
||||||
|
$answer = getWetter($anlagenummer, $this->ReadPropertyString("Gerätenummer"), $this->ReadPropertyString("Ortschaft"));
|
||||||
|
|
||||||
|
$this->SetValue("Temperatur", $answer[0]);
|
||||||
|
$this->SetValue("Wolkenwarscheinlichkeit", $answer[1]);
|
||||||
|
|
||||||
|
|
||||||
if (!empty($json)) {
|
if (!empty($json)) {
|
||||||
// Kombiniere die URL mit der Anlagenummer
|
// Kombiniere die URL mit der Anlagenummer
|
||||||
$fullURL = $baseURL;
|
$fullURL = $baseURL;
|
||||||
|
|||||||
Reference in New Issue
Block a user