genrisch dynamisch viele Punkte. Erweiterung vorgenommen
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"elements": [
|
"elements": [
|
||||||
{
|
{
|
||||||
"type" : "Label",
|
"type": "Label",
|
||||||
"caption" : "Influx Punkte"
|
"caption": "Influx Punkte"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "Select",
|
"type": "Select",
|
||||||
@@ -20,11 +20,29 @@
|
|||||||
"suffix": "",
|
"suffix": "",
|
||||||
"validate": "^An_\\d{4}$"
|
"validate": "^An_\\d{4}$"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "SelectVariable",
|
"type": "List",
|
||||||
"name":"Netzbezug",
|
"name": "ZusatzVariablen",
|
||||||
"caption": "Variable mit dem zu regelnden Netzbezug",
|
"caption": "Zusätzliche Variablen für Influx",
|
||||||
"suffix": ""
|
"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("BaseURL","http://192.168.20.140:5000/influx");
|
||||||
$this->RegisterPropertyString("Anlagenummer",0);
|
$this->RegisterPropertyString("Anlagenummer",0);
|
||||||
$this->RegisterPropertyBoolean("InfluxJaNein", false);
|
$this->RegisterPropertyBoolean("InfluxJaNein", false);
|
||||||
|
$this->RegisterPropertyArray("ZusatzVariablen",[]);
|
||||||
|
|
||||||
|
|
||||||
$this->RegisterTimer("Timer_Influx", 0, 'IPS_RequestAction(' . $this->InstanceID . ', "GetAction", "");');// 5min = 1000 * 60 * 5 = 300'000ms
|
$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()
|
public function ApplyChanges()
|
||||||
{
|
{
|
||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
|
|
||||||
|
// Holen Sie sich die Einstellung, ob Influx aktiviert ist
|
||||||
$InfluxJaNein = $this->ReadPropertyBoolean("InfluxJaNein");
|
$InfluxJaNein = $this->ReadPropertyBoolean("InfluxJaNein");
|
||||||
|
|
||||||
if ($InfluxJaNein) {
|
if ($InfluxJaNein) {
|
||||||
// Timer auf 5 Minuten setzen
|
// 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");
|
IPS_LogMessage("Belevo_Server_Kommunikation", "Influx Ja");
|
||||||
|
|
||||||
|
// Verarbeite die ZusatzVariablen
|
||||||
|
$this->ProcessZusatzVariablen();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Timer stoppen
|
// Timer stoppen
|
||||||
$this->SetTimerInterval("Timer_Influx", 0);
|
$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)
|
public function RequestAction($Ident, $Value)
|
||||||
@@ -102,27 +133,55 @@ class Belevo_Server_Kommunikation extends IPSModule
|
|||||||
//$this->SetValue("E_PNB_5M_0", $netzbezug);
|
//$this->SetValue("E_PNB_5M_0", $netzbezug);
|
||||||
|
|
||||||
// Werte in ein Array packen
|
// Werte in ein Array packen
|
||||||
$influxData = array(
|
public function MakeJson()
|
||||||
|
{
|
||||||
|
$an_nummer = $this->ReadPropertyString("Anlagenummer"); // Verwende ReadPropertyString, um die Anlagenummer zu lesen
|
||||||
|
$InfluxJaNein = $this->ReadPropertyBoolean("InfluxJaNein");
|
||||||
|
|
||||||
"Value" => array(
|
// Werte in ein Array packen
|
||||||
"InfluxAllowed" => $InfluxJaNein // Setze InfluxAllowed auf true für den Test
|
$influxData = array(
|
||||||
),
|
"Value" => array(
|
||||||
|
"InfluxAllowed" => $InfluxJaNein // Setze InfluxAllowed auf true für den Test
|
||||||
"Parameter" => array(
|
),
|
||||||
"Influxadr" => $an_nummer
|
"Parameter" => array(
|
||||||
),
|
"Influxadr" => $an_nummer
|
||||||
"Tracker" => array(
|
),
|
||||||
"E_PNB_5M_0" => $netzbezug
|
"Tracker" => array() // Initialisiere Tracker als leeres Array
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Array in JSON konvertieren
|
// Zusatzvariablen aus den Instanzeigenschaften abrufen
|
||||||
$json = json_encode($influxData);
|
$zusatzVariablen = $this->ReadPropertyArray("ZusatzVariablen");
|
||||||
IPS_LogMessage("Belevo_Server_Kommunikation", "Erstelltes JSON: " . $json);
|
|
||||||
// JSON zurückgeben oder weiterverarbeiten
|
// Protokolliere den Inhalt der Zusatzvariablen
|
||||||
return $json;
|
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) {
|
private function SendJsonToInfluxDB($url, $jsonData) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"compatibility": {
|
"compatibility": {
|
||||||
"version": "7.1"
|
"version": "7.1"
|
||||||
},
|
},
|
||||||
"version": "0.76",
|
"version": "0.77",
|
||||||
"build": 0,
|
"build": 0,
|
||||||
"date": 0
|
"date": 0
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user