From ab2bd464260181072f08669fc4b5d33efae0debd Mon Sep 17 00:00:00 2001 From: "belevo\\mh" Date: Wed, 19 Nov 2025 13:48:54 +0100 Subject: [PATCH] no message --- VGT_Sub/module.php | 73 +++++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/VGT_Sub/module.php b/VGT_Sub/module.php index ded3da1..a61ab1f 100644 --- a/VGT_Sub/module.php +++ b/VGT_Sub/module.php @@ -187,49 +187,64 @@ class VGT_Sub extends IPSModule * ------------------------------------------*/ public function ReceiveData($JSONString) { - // Äußeres JSON vom MQTT-Client + $this->SendDebug('MQTT', "RAW Incoming JSON: " . $JSONString, 0); + + // --------------------------------------------- + // 1) Äußeres JSON vom MQTT-Client + // --------------------------------------------- $data = json_decode($JSONString); if ($data === null) { - $this->SendDebug('MQTT', 'Ungültiges JSON: ' . $JSONString, 0); + $this->SendDebug('MQTT', '❌ JSON ungültig (outer decode)', 0); return; } - // Neuere MQTT-Client-Version: Topic/Payload stecken in Buffer als JSON-String + // --------------------------------------------- + // 2) Buffer extrahieren + // --------------------------------------------- if (isset($data->Buffer)) { + $this->SendDebug('MQTT', "Buffer gefunden (json-string): " . $data->Buffer, 0); $buffer = json_decode($data->Buffer, true); } else { - // Fallback: evtl. altes Format + $this->SendDebug('MQTT', "⚠️ Kein Buffer-Feld gefunden, versuche komplettes JSON", 0); $buffer = json_decode($JSONString, true); } if (!is_array($buffer)) { - $this->SendDebug('MQTT', 'Buffer ist kein Array: ' . print_r($buffer, true), 0); + $this->SendDebug('MQTT', '❌ Buffer ist kein Array: ' . print_r($buffer, true), 0); return; } + // --------------------------------------------- + // 3) Topic / Payload lesen + // --------------------------------------------- $topic = $buffer['Topic'] ?? ''; $payload = $buffer['Payload'] ?? ''; - $this->SendDebug('MQTT', 'Receive: Topic=' . $topic . ' Payload=' . $payload, 0); + $this->SendDebug('MQTT', "📩 Receive: Topic='$topic' Payload='$payload'", 0); $device = $this->ReadPropertyString('DeviceID'); if ($device === '') { - $this->SendDebug('MQTT', 'Keine DeviceID gesetzt, ignoriere Receive', 0); + $this->SendDebug('MQTT', '⚠️ DeviceID leer → ignoriert', 0); return; } - /** ------------------------------------------- - * 1️⃣ FEEDBACK REQUEST - * ------------------------------------------*/ + $this->SendDebug('MQTT', "DeviceID aktiv: $device", 0); + + // ===================================================================== + // 4) FEEDBACK REQUEST + // ===================================================================== if ($topic === "feedback-request/$device") { + $this->SendDebug('MQTT', "➡️ Feedback-Request erkannt!", 0); $this->SetValue('FeedbackRequestPayload', $payload); $json = json_decode($payload, true); if (!is_array($json)) { + $this->SendDebug('MQTT', "⚠️ payload JSON ungültig → verwende leeres array", 0); $json = []; } + // Antwort erzeugen $response = array_merge($json, [ "power_production" => $this->GetValue('PowerProduction'), "is_ready" => $this->GetValue('IsReady'), @@ -239,31 +254,43 @@ class VGT_Sub extends IPSModule "max_soc" => $this->GetValue('MaxSOC') ]); - $this->Publish("feedback-response/$device", json_encode($response)); + $jsonOut = json_encode($response); + $this->SendDebug('MQTT', "⬆️ Sende Feedback-Response: " . $jsonOut, 0); + $this->Publish("feedback-response/$device", $jsonOut); return; } - /** ------------------------------------------- - * 2️⃣ REMOTE CONTROL REQUEST - * ------------------------------------------*/ + // ===================================================================== + // 5) REMOTE CONTROL REQUEST + // ===================================================================== if ($topic === "remote-control-request/$device") { + $this->SendDebug('MQTT', "➡️ Remote-Control-Request erkannt!", 0); $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']); - } + if (!is_array($json)) { + $this->SendDebug('MQTT', "⚠️ payload JSON ungültig → keine RC-Daten", 0); + return; } + if (array_key_exists('power_setpoint', $json)) { + $this->SendDebug('MQTT', "Set power_setpoint: " . $json['power_setpoint'], 0); + $this->SetValue('PowerSetpoint', (int)$json['power_setpoint']); + } + if (array_key_exists('strategy', $json)) { + $this->SendDebug('MQTT', "Set strategy: " . $json['strategy'], 0); + $this->SetValue('Strategy', (string)$json['strategy']); + } + + $this->SendDebug('MQTT', "⬆️ Sende Remote-Control-Response: " . $payload, 0); $this->Publish("remote-control-response/$device", $payload); return; } + + // ===================================================================== + // 6) Unbekanntes Topic + // ===================================================================== + $this->SendDebug('MQTT', "⚠️ Unbekanntes Topic empfangen → ignoriert", 0); } }