From 7d90eae48114f7d263c5c4b5c9e8c60198b94819 Mon Sep 17 00:00:00 2001 From: "belevo\\mh" Date: Wed, 19 Nov 2025 13:28:23 +0100 Subject: [PATCH] no message --- VGT_Sub/module.php | 68 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/VGT_Sub/module.php b/VGT_Sub/module.php index bf5cd08..ca2ac1f 100644 --- a/VGT_Sub/module.php +++ b/VGT_Sub/module.php @@ -152,13 +152,28 @@ class VGT_Sub extends IPSModule * ------------------------------------------*/ public function ReceiveData($JSONString) { - $data = json_decode($JSONString, true); - if (!is_array($data)) { + // äußere Hülle vom MQTT-Client + $data = json_decode($JSONString); + if ($data === null) { + $this->SendDebug('MQTT', 'Ungültiges JSON: ' . $JSONString, 0); return; } - $topic = $data['Topic'] ?? ''; - $payload = $data['Payload'] ?? ''; + // aktuelles MQTT-Client-Format: Topic/Payload stecken in Buffer + if (isset($data->Buffer)) { + $buffer = json_decode($data->Buffer, true); + } else { + // Fallback auf direkte Struktur + $buffer = json_decode($JSONString, true); + } + + if (!is_array($buffer)) { + $this->SendDebug('MQTT', 'Buffer ist kein Array: ' . print_r($buffer, true), 0); + return; + } + + $topic = $buffer['Topic'] ?? ''; + $payload = $buffer['Payload'] ?? ''; $this->SendDebug('MQTT', 'Receive: Topic=' . $topic . ' Payload=' . $payload, 0); @@ -167,6 +182,51 @@ class VGT_Sub extends IPSModule return; } + // 1) feedback-request/ + if ($topic === "feedback-request/$device") { + + $this->SetValue('FeedbackRequestPayload', $payload); + + $json = json_decode($payload, true); + if (!is_array($json)) { + $json = []; + } + + $response = array_merge($json, [ + "power_production" => $this->GetValue('PowerProduction'), + "is_ready" => $this->GetValue('IsReady'), + "is_running" => $this->GetValue('IsRunning'), + "state_of_charge" => $this->GetValue('StateOfCharge'), + "min_soc" => $this->GetValue('MinSOC'), + "max_soc" => $this->GetValue('MaxSOC') + ]); + + $this->Publish("feedback-response/$device", json_encode($response)); + return; + } + + // 2) remote-control-request/ + if ($topic === "remote-control-request/$device") { + + $this->SetValue('RemoteControlPayload', $payload); + + $json = json_decode($payload, true); + if (is_array($json)) { + + if (array_key_exists('power_setpoint', $json)) { + $this->SetValue('PowerSetpoint', (int)$json['power_setpoint']); + } + + if (array_key_exists('strategy', $json)) { + $this->SetValue('Strategy', (string)$json['strategy']); + } + } + + $this->Publish("remote-control-response/$device", $payload); + return; + } + } + /** ------------------------------------------- * 1️⃣ FEEDBACK REQUEST * ------------------------------------------*/