genrisch dynamisch viele Punkte. Erweiterung vorgenommen
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"elements": [
|
||||
{
|
||||
"type" : "Label",
|
||||
"caption" : "Influx Punkte"
|
||||
"type": "Label",
|
||||
"caption": "Influx Punkte"
|
||||
},
|
||||
{
|
||||
"type": "Select",
|
||||
@@ -20,11 +20,29 @@
|
||||
"suffix": "",
|
||||
"validate": "^An_\\d{4}$"
|
||||
},
|
||||
{
|
||||
"type": "SelectVariable",
|
||||
"name":"Netzbezug",
|
||||
"caption": "Variable mit dem zu regelnden Netzbezug",
|
||||
"suffix": ""
|
||||
{
|
||||
"type": "List",
|
||||
"name": "ZusatzVariablen",
|
||||
"caption": "Zusätzliche Variablen für Influx",
|
||||
"add": true,
|
||||
"delete": true,
|
||||
"columns": [
|
||||
{
|
||||
"caption": "Variablenname",
|
||||
"name": "Variablenname",
|
||||
"width": "200px",
|
||||
"add": ""
|
||||
},
|
||||
{
|
||||
"caption": "Variable",
|
||||
"name": "Variable",
|
||||
"width": "300px",
|
||||
"add": 0,
|
||||
"edit": {
|
||||
"type": "SelectVariable"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class Belevo_Server_Kommunikation extends IPSModule
|
||||
$this->RegisterPropertyString("BaseURL","http://192.168.20.140:5000/influx");
|
||||
$this->RegisterPropertyString("Anlagenummer",0);
|
||||
$this->RegisterPropertyBoolean("InfluxJaNein", false);
|
||||
|
||||
$this->RegisterPropertyArray("ZusatzVariablen",[]);
|
||||
|
||||
|
||||
$this->RegisterTimer("Timer_Influx", 0, 'IPS_RequestAction(' . $this->InstanceID . ', "GetAction", "");');// 5min = 1000 * 60 * 5 = 300'000ms
|
||||
@@ -51,11 +51,18 @@ class Belevo_Server_Kommunikation extends IPSModule
|
||||
public function ApplyChanges()
|
||||
{
|
||||
parent::ApplyChanges();
|
||||
|
||||
// Holen Sie sich die Einstellung, ob Influx aktiviert ist
|
||||
$InfluxJaNein = $this->ReadPropertyBoolean("InfluxJaNein");
|
||||
|
||||
if ($InfluxJaNein) {
|
||||
// Timer auf 5 Minuten setzen
|
||||
$this->SetTimerInterval("Timer_Influx", 5000);//Alle 5 Sekunden
|
||||
$this->SetTimerInterval("Timer_Influx", 5000); // Alle 5 Sekunden
|
||||
IPS_LogMessage("Belevo_Server_Kommunikation", "Influx Ja");
|
||||
|
||||
// Verarbeite die ZusatzVariablen
|
||||
$this->ProcessZusatzVariablen();
|
||||
|
||||
} else {
|
||||
// Timer stoppen
|
||||
$this->SetTimerInterval("Timer_Influx", 0);
|
||||
@@ -63,6 +70,30 @@ class Belevo_Server_Kommunikation extends IPSModule
|
||||
}
|
||||
}
|
||||
|
||||
private function ProcessZusatzVariablen()
|
||||
{
|
||||
// Abrufen der ZusatzVariablen-Liste
|
||||
$zusatzVariablen = $this->ReadPropertyArray("ZusatzVariablen");
|
||||
|
||||
// Verarbeitung der Variablen
|
||||
if (!empty($zusatzVariablen)) {
|
||||
foreach ($zusatzVariablen as $variable) {
|
||||
$variablenname = $variable['Variablenname'];
|
||||
$variableID = $variable['Variable'];
|
||||
|
||||
// Überprüfen, ob die Variable existiert
|
||||
if (IPS_VariableExists($variableID)) {
|
||||
$wert = GetValue($variableID);
|
||||
IPS_LogMessage("ZusatzVariable", "Name: $variablenname, ID: $variableID, Wert: $wert");
|
||||
|
||||
// Hier können Sie den Wert in die InfluxDB schreiben oder weiterverarbeiten
|
||||
// Beispiel: $this->WriteToInfluxDB($variablenname, $wert);
|
||||
} else {
|
||||
IPS_LogMessage("ZusatzVariable", "Variable mit ID $variableID existiert nicht.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function RequestAction($Ident, $Value)
|
||||
@@ -102,27 +133,55 @@ class Belevo_Server_Kommunikation extends IPSModule
|
||||
//$this->SetValue("E_PNB_5M_0", $netzbezug);
|
||||
|
||||
// Werte in ein Array packen
|
||||
$influxData = array(
|
||||
|
||||
"Value" => array(
|
||||
"InfluxAllowed" => $InfluxJaNein // Setze InfluxAllowed auf true für den Test
|
||||
),
|
||||
|
||||
"Parameter" => array(
|
||||
"Influxadr" => $an_nummer
|
||||
),
|
||||
"Tracker" => array(
|
||||
"E_PNB_5M_0" => $netzbezug
|
||||
)
|
||||
public function MakeJson()
|
||||
{
|
||||
$an_nummer = $this->ReadPropertyString("Anlagenummer"); // Verwende ReadPropertyString, um die Anlagenummer zu lesen
|
||||
$InfluxJaNein = $this->ReadPropertyBoolean("InfluxJaNein");
|
||||
|
||||
// Werte in ein Array packen
|
||||
$influxData = array(
|
||||
"Value" => array(
|
||||
"InfluxAllowed" => $InfluxJaNein // Setze InfluxAllowed auf true für den Test
|
||||
),
|
||||
"Parameter" => array(
|
||||
"Influxadr" => $an_nummer
|
||||
),
|
||||
"Tracker" => array() // Initialisiere Tracker als leeres Array
|
||||
);
|
||||
|
||||
// Array in JSON konvertieren
|
||||
$json = json_encode($influxData);
|
||||
IPS_LogMessage("Belevo_Server_Kommunikation", "Erstelltes JSON: " . $json);
|
||||
// JSON zurückgeben oder weiterverarbeiten
|
||||
return $json;
|
||||
// Zusatzvariablen aus den Instanzeigenschaften abrufen
|
||||
$zusatzVariablen = $this->ReadPropertyArray("ZusatzVariablen");
|
||||
|
||||
// Protokolliere den Inhalt der Zusatzvariablen
|
||||
IPS_LogMessage("MakeJson", "Zusatzvariablen Array: " . json_encode($zusatzVariablen));
|
||||
|
||||
// Dynamisch Zusatzvariablen zum Tracker hinzufügen
|
||||
if (!empty($zusatzVariablen)) {
|
||||
foreach ($zusatzVariablen as $variable) {
|
||||
$variablenname = $variable['Variablenname'];
|
||||
$variableID = $variable['Variable'];
|
||||
|
||||
// Überprüfen, ob die Variable existiert
|
||||
if (IPS_VariableExists($variableID)) {
|
||||
$wert = GetValue($variableID); // Den aktuellen Wert der Zusatzvariable abrufen
|
||||
$influxData['Tracker'][$variablenname] = $wert; // Wert zum Tracker hinzufügen
|
||||
} else {
|
||||
IPS_LogMessage("MakeJson", "Variable mit ID $variableID existiert nicht.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Protokolliere den Inhalt des influxData-Arrays vor der JSON-Konvertierung
|
||||
IPS_LogMessage("MakeJson", "InfluxData Array vor JSON-Konvertierung: " . json_encode($influxData));
|
||||
|
||||
// Array in JSON konvertieren
|
||||
$json = json_encode($influxData);
|
||||
IPS_LogMessage("Belevo_Server_Kommunikation", "Erstelltes JSON: " . $json);
|
||||
|
||||
// JSON zurückgeben oder weiterverarbeiten
|
||||
return $json;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function SendJsonToInfluxDB($url, $jsonData) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"compatibility": {
|
||||
"version": "7.1"
|
||||
},
|
||||
"version": "0.76",
|
||||
"version": "0.77",
|
||||
"build": 0,
|
||||
"date": 0
|
||||
}
|
||||
Reference in New Issue
Block a user