From 4f1fabbb19bbd43686abfdfb736982e21bed518d Mon Sep 17 00:00:00 2001 From: DanielHaefliger Date: Fri, 28 Nov 2025 07:07:03 +0100 Subject: [PATCH] no message --- VGT_Sub/module.php | 83 ++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/VGT_Sub/module.php b/VGT_Sub/module.php index 293e985..a3da33a 100644 --- a/VGT_Sub/module.php +++ b/VGT_Sub/module.php @@ -30,77 +30,76 @@ class VGT_Sub extends IPSModule $this->RegisterVariableInteger("MaxSOC", "Max SOC", "", 60); $this->EnableAction("MaxSOC"); - // Remote-Control incoming (read-only) + // Remote control readonly values $this->RegisterVariableFloat("RC_PowerSetpoint", "RC Power Setpoint", "", 70); $this->RegisterVariableString("RC_Strategy", "RC Strategy", "", 80); - // Parent MQTT Splitter + // Attach to MQTT Client Splitter $this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}'); } + public function ApplyChanges() { parent::ApplyChanges(); + // Reconnect parent $this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}'); $device = $this->ReadPropertyString("DeviceID"); - // Subscribes + // Required incoming topics $topics = [ "feedback-request/" . $device, "remote-control-request/" . $device ]; + // Subscribe each topic using the CORRECT DataID foreach ($topics as $t) { $this->SendDataToParent(json_encode([ - "DataID" => "{043E0F88-B2B0-4DF4-B1A6-64FB1C385D3C}", - "PacketType" => 8, // SUBSCRIBE - "Topic" => $t + "DataID" => "{043EA491-0325-4ADD-8FC2-A30C8EEB4D3F}", // <- correct for subscribe + "Topic" => $t, + "Retain" => false ])); } } - // --------------------------------------------------------------------- - // ACTION HANDLER - // --------------------------------------------------------------------- public function RequestAction($Ident, $Value) { SetValue($this->GetIDForIdent($Ident), $Value); } - // --------------------------------------------------------------------- - // RECEIVE FROM MQTT - // --------------------------------------------------------------------- + public function ReceiveData($JSONString) { $data = json_decode($JSONString); + + // This format is correct for your MQTT client splitter: + // { "Topic": "...", "Payload": "..." } + if (!isset($data->Topic) || !isset($data->Payload)) { return; } - $topic = $data->Topic; + $topic = $data->Topic; $payload = $data->Payload; - $deviceID = $this->ReadPropertyString("DeviceID"); + $device = $this->ReadPropertyString("DeviceID"); - // Topics - $feedbackReq = "feedback-request/" . $deviceID; - $remoteReq = "remote-control-request/" . $deviceID; - - if ($topic === $feedbackReq) { + if ($topic === "feedback-request/" . $device) { $this->HandleFeedbackRequest(); } - if ($topic === $remoteReq) { + if ($topic === "remote-control-request/" . $device) { $this->HandleRemoteControlRequest($payload); } } - // --------------------------------------------------------------------- - // HANDLE FEEDBACK REQUEST -> SEND STATE JSON - // --------------------------------------------------------------------- + + // ---------------------------------------------------------------------------- + // FEEDBACK REQUEST → SEND STATE JSON + // ---------------------------------------------------------------------------- private function HandleFeedbackRequest() { $response = [ @@ -117,11 +116,10 @@ class VGT_Sub extends IPSModule $this->SendToMQTT($topic, json_encode($response)); } - // --------------------------------------------------------------------- - // HANDLE REMOTE CONTROL REQUEST - // payload: - // { "power_setpoint": 150, "strategy": "activation" } - // --------------------------------------------------------------------- + + // ---------------------------------------------------------------------------- + // REMOTE CONTROL REQUEST → WRITE VALUES + RESPOND + // ---------------------------------------------------------------------------- private function HandleRemoteControlRequest(string $payload) { $data = json_decode($payload, true); @@ -129,7 +127,6 @@ class VGT_Sub extends IPSModule return; } - // Write values to variables if (isset($data["power_setpoint"])) { SetValue($this->GetIDForIdent("RC_PowerSetpoint"), $data["power_setpoint"]); } @@ -138,40 +135,38 @@ class VGT_Sub extends IPSModule SetValue($this->GetIDForIdent("RC_Strategy"), $data["strategy"]); } - // Respond with same JSON + // Respond back $topic = "remote-control-response/" . $this->ReadPropertyString("DeviceID"); $this->SendToMQTT($topic, json_encode($data)); } - // --------------------------------------------------------------------- - // MQTT SEND HELPERS - // --------------------------------------------------------------------- + + // ---------------------------------------------------------------------------- + // MQTT PUBLISH (correct format for your splitter!) + // ---------------------------------------------------------------------------- private function SendToMQTT(string $topic, string $payload) { $this->SendDataToParent(json_encode([ - "DataID" => "{043E0F88-B2B0-4DF4-B1A6-64FB1C385D3C}", - "PacketType" => 3, - "QualityOfService" => 0, - "Retain" => false, - "Topic" => $topic, - "Payload" => $payload + "DataID" => "{043EA491-0325-4ADD-8FC2-A30C8EEB4D3F}", // CORRECT! + "Topic" => $topic, + "Payload" => $payload, + "Retain" => false ])); } - // --------------------------------------------------------------------- - // CONFIG FORM - // --------------------------------------------------------------------- + public function GetConfigurationForm() { return json_encode([ "elements" => [ [ - "type" => "ValidationTextBox", - "name" => "DeviceID", + "type" => "ValidationTextBox", + "name" => "DeviceID", "caption" => "Device ID" ] ] ]); } } + ?> \ No newline at end of file