diff --git a/VGT_Sub/module.php b/VGT_Sub/module.php index ea5a116..f6c41b8 100644 --- a/VGT_Sub/module.php +++ b/VGT_Sub/module.php @@ -10,7 +10,7 @@ class VGT_Sub extends IPSModule $this->RegisterPropertyString('DeviceID', ''); - // Status Variablen + // Status Variablen (editable) $this->RegisterVariableFloat('PowerProduction', 'Power Production', '', 10); $this->EnableAction('PowerProduction'); @@ -29,7 +29,7 @@ class VGT_Sub extends IPSModule $this->RegisterVariableFloat('MaxSoc', 'Max SoC', '', 15); $this->EnableAction('MaxSoc'); - // Remote-control readonly Variablen + // Remote control readonly variables $this->RegisterVariableInteger('PowerSetpoint', 'Power Setpoint', '', 30); IPS_SetVariableCustomAction($this->GetIDForIdent('PowerSetpoint'), 0); @@ -41,7 +41,7 @@ class VGT_Sub extends IPSModule { parent::ApplyChanges(); - // Richtiger Parent + // Correct Parent: MQTTClientSplitter $this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}'); $this->SubscribeTopics(); @@ -60,11 +60,11 @@ class VGT_Sub extends IPSModule ]; foreach ($topics as $topic) { - $this->SendDebug("Subscribe", $topic, 0); + $this->SendDebug("SUBSCRIBE", $topic, 0); $this->SendDataToParent(json_encode([ "DataID" => "{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}", - "PacketType" => 8, // Subscribe + "PacketType" => 8, // SUBSCRIBE "Topic" => $topic, "QoS" => 0 ])); @@ -82,19 +82,17 @@ class VGT_Sub extends IPSModule $topic = $data['Topic']; $payload = $data['Payload']; - $this->SendDebug("RX Topic", $topic, 0); - $this->SendDebug("RX Payload", $payload, 0); + $this->SendDebug("RX TOPIC", $topic, 0); + $this->SendDebug("RX PAYLOAD", $payload, 0); $device = $this->ReadPropertyString('DeviceID'); if ($topic === "feedback-request/$device") { $this->HandleFeedbackRequest($device); - return; } if ($topic === "remote-control-request/$device") { $this->HandleRemoteControlRequest($device, $payload); - return; } } @@ -109,15 +107,14 @@ class VGT_Sub extends IPSModule "max_soc" => GetValue($this->GetIDForIdent('MaxSoc')) ]; - $json = json_encode($response); + $json = json_encode($response); $topic = "feedback-response/$device"; - $this->SendDebug("TX Feedback", $json, 0); + $this->SendDebug("TX FEEDBACK", $json, 0); - // RAW MQTT Publish $this->SendDataToParent(json_encode([ "DataID" => "{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}", - "PacketType" => 3, // Publish + "PacketType" => 3, // PUBLISH "Topic" => $topic, "Payload" => $json, "QoS" => 0, @@ -129,7 +126,7 @@ class VGT_Sub extends IPSModule { $json = @json_decode($payload, true); if (!is_array($json)) { - $this->SendDebug("Error", "Ungültiges JSON", 0); + $this->SendDebug("ERROR", "Ungültiges JSON", 0); return; } @@ -141,12 +138,11 @@ class VGT_Sub extends IPSModule SetValueString($this->GetIDForIdent('Strategy'), (string)$json['strategy']); } - $topic = "remote-control-response/$device"; $payloadOut = json_encode($json); + $topic = "remote-control-response/$device"; - $this->SendDebug("TX RemoteControl", $payloadOut, 0); + $this->SendDebug("TX REMOTE", $payloadOut, 0); - // RAW MQTT Publish $this->SendDataToParent(json_encode([ "DataID" => "{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}", "PacketType" => 3,