no message
This commit is contained in:
@@ -8,8 +8,10 @@ class VGT_Sub extends IPSModule
|
|||||||
{
|
{
|
||||||
parent::Create();
|
parent::Create();
|
||||||
|
|
||||||
|
// Konfig
|
||||||
$this->RegisterPropertyString("DeviceID", "");
|
$this->RegisterPropertyString("DeviceID", "");
|
||||||
|
|
||||||
|
// Editable Variablen (werden in feedback-response gesendet)
|
||||||
$this->RegisterVariableFloat("PowerProduction", "Power Production", "", 10);
|
$this->RegisterVariableFloat("PowerProduction", "Power Production", "", 10);
|
||||||
$this->EnableAction("PowerProduction");
|
$this->EnableAction("PowerProduction");
|
||||||
|
|
||||||
@@ -28,29 +30,37 @@ class VGT_Sub extends IPSModule
|
|||||||
$this->RegisterVariableInteger("MaxSOC", "Max SOC", "", 60);
|
$this->RegisterVariableInteger("MaxSOC", "Max SOC", "", 60);
|
||||||
$this->EnableAction("MaxSOC");
|
$this->EnableAction("MaxSOC");
|
||||||
|
|
||||||
|
// Remote-Control Input Variablen (nur lesen)
|
||||||
$this->RegisterVariableFloat("RC_PowerSetpoint", "RC Power Setpoint", "", 70);
|
$this->RegisterVariableFloat("RC_PowerSetpoint", "RC Power Setpoint", "", 70);
|
||||||
$this->RegisterVariableString("RC_Strategy", "RC Strategy", "", 80);
|
$this->RegisterVariableString("RC_Strategy", "RC Strategy", "", 80);
|
||||||
|
|
||||||
|
// Parent verbinden
|
||||||
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}');
|
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function ApplyChanges()
|
public function ApplyChanges()
|
||||||
{
|
{
|
||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
|
|
||||||
// Child darf NICHT subscriben!
|
// Sicherstellen, dass Parent gesetzt ist
|
||||||
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}');
|
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function RequestAction($Ident, $Value)
|
public function RequestAction($Ident, $Value)
|
||||||
{
|
{
|
||||||
SetValue($this->GetIDForIdent($Ident), $Value);
|
SetValue($this->GetIDForIdent($Ident), $Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Eingehende Daten vom MQTT-Client
|
||||||
public function ReceiveData($JSONString)
|
public function ReceiveData($JSONString)
|
||||||
{
|
{
|
||||||
$data = json_decode($JSONString);
|
$data = json_decode($JSONString);
|
||||||
|
|
||||||
|
// Format wird vom MQTT-Client-Splitter geliefert:
|
||||||
|
// { "Topic": "...", "Payload": "..." }
|
||||||
if (!isset($data->Topic) || !isset($data->Payload)) {
|
if (!isset($data->Topic) || !isset($data->Payload)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -60,15 +70,18 @@ class VGT_Sub extends IPSModule
|
|||||||
|
|
||||||
$device = $this->ReadPropertyString("DeviceID");
|
$device = $this->ReadPropertyString("DeviceID");
|
||||||
|
|
||||||
|
// Feedback-Request
|
||||||
if ($topic === "feedback-request/" . $device) {
|
if ($topic === "feedback-request/" . $device) {
|
||||||
$this->HandleFeedbackRequest();
|
$this->HandleFeedbackRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remote-Control Request
|
||||||
if ($topic === "remote-control-request/" . $device) {
|
if ($topic === "remote-control-request/" . $device) {
|
||||||
$this->HandleRemoteControlRequest($payload);
|
$this->HandleRemoteControlRequest($payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function HandleFeedbackRequest()
|
private function HandleFeedbackRequest()
|
||||||
{
|
{
|
||||||
$response = [
|
$response = [
|
||||||
@@ -80,9 +93,13 @@ class VGT_Sub extends IPSModule
|
|||||||
"max_soc" => GetValue($this->GetIDForIdent("MaxSOC"))
|
"max_soc" => GetValue($this->GetIDForIdent("MaxSOC"))
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->SendToMQTT("feedback-response/" . $this->ReadPropertyString("DeviceID"), json_encode($response));
|
$this->SendToMQTT(
|
||||||
|
"feedback-response/" . $this->ReadPropertyString("DeviceID"),
|
||||||
|
json_encode($response)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function HandleRemoteControlRequest(string $payload)
|
private function HandleRemoteControlRequest(string $payload)
|
||||||
{
|
{
|
||||||
$data = json_decode($payload, true);
|
$data = json_decode($payload, true);
|
||||||
@@ -90,6 +107,7 @@ class VGT_Sub extends IPSModule
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Werte setzen
|
||||||
if (isset($data["power_setpoint"])) {
|
if (isset($data["power_setpoint"])) {
|
||||||
SetValue($this->GetIDForIdent("RC_PowerSetpoint"), $data["power_setpoint"]);
|
SetValue($this->GetIDForIdent("RC_PowerSetpoint"), $data["power_setpoint"]);
|
||||||
}
|
}
|
||||||
@@ -98,14 +116,20 @@ class VGT_Sub extends IPSModule
|
|||||||
SetValue($this->GetIDForIdent("RC_Strategy"), $data["strategy"]);
|
SetValue($this->GetIDForIdent("RC_Strategy"), $data["strategy"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->SendToMQTT("remote-control-response/" . $this->ReadPropertyString("DeviceID"), json_encode($data));
|
// Antwort zurück
|
||||||
|
$this->SendToMQTT(
|
||||||
|
"remote-control-response/" . $this->ReadPropertyString("DeviceID"),
|
||||||
|
json_encode($data)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MQTT Publish (korrektes Format für deinen MQTT-Client-Splitter)
|
||||||
private function SendToMQTT(string $topic, string $payload)
|
private function SendToMQTT(string $topic, string $payload)
|
||||||
{
|
{
|
||||||
$this->SendDataToParent(json_encode([
|
$this->SendDataToParent(json_encode([
|
||||||
"DataID" => "{043EA491-0325-4ADD-8FC2-A30C8EEB4D3F}",
|
"DataID" => "{043EA491-0325-4ADD-8FC2-A30C8EEB4D3F}",
|
||||||
"PacketType" => 3,
|
"PacketType" => 3, // Publish
|
||||||
"QualityOfService" => 0,
|
"QualityOfService" => 0,
|
||||||
"Retain" => false,
|
"Retain" => false,
|
||||||
"Topic" => $topic,
|
"Topic" => $topic,
|
||||||
@@ -113,11 +137,16 @@ class VGT_Sub extends IPSModule
|
|||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function GetConfigurationForm()
|
public function GetConfigurationForm()
|
||||||
{
|
{
|
||||||
return json_encode([
|
return json_encode([
|
||||||
"elements" => [
|
"elements" => [
|
||||||
[ "type" => "ValidationTextBox", "name" => "DeviceID", "caption" => "Device ID" ]
|
[
|
||||||
|
"type" => "ValidationTextBox",
|
||||||
|
"name" => "DeviceID",
|
||||||
|
"caption" => "Device ID"
|
||||||
|
]
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user