no message

This commit is contained in:
2025-11-13 09:39:48 +01:00
parent 96496a65c4
commit 28f2130056
2 changed files with 38 additions and 49 deletions

View File

@@ -5,8 +5,9 @@
"vendor": "Belevo", "vendor": "Belevo",
"prefix": "VGT", "prefix": "VGT",
"parentRequirements": [ "parentRequirements": [
"{A5D7A5C5-F2BD-4DA3-9C28-DB6C24A34F3C}" "{C6D2AEB3-6E1F-4B2E-8E69-3A1A00246850}"
], ],
"childRequirements": [], "childRequirements": [],
"implemented": [] "implemented": [],
"aliases": []
} }

View File

@@ -10,11 +10,11 @@ class Int_VGT extends IPSModule
$this->RegisterPropertyString('DeviceID', ''); $this->RegisterPropertyString('DeviceID', '');
// Variable für empfangene Remote-Control-Daten // Speicherung empfangener Remote-Payloads
$this->RegisterVariableString('RemoteControlPayload', 'Remote Control Payload', '', 1); $this->RegisterVariableString('RemoteControlPayload', 'Remote Control Payload', '', 1);
// MQTT Splitter (richtiger Parent) // Direkte Verbindung zum MQTT-Server herstellen
$this->ConnectParent("{A5D7A5C5-F2BD-4DA3-9C28-DB6C24A34F3C}"); $this->ConnectParent("{C6D2AEB3-6E1F-4B2E-8E69-3A1A00246850}");
} }
public function ApplyChanges() public function ApplyChanges()
@@ -22,43 +22,49 @@ class Int_VGT extends IPSModule
parent::ApplyChanges(); parent::ApplyChanges();
$device = $this->ReadPropertyString('DeviceID'); $device = $this->ReadPropertyString('DeviceID');
if ($device === '') {
if ($device == '') {
return; return;
} }
// DEBUG: Was wird abonniert? // Subscriptions einrichten — wie beim Shelly Modul
$this->SendDebug("Subscribe", "Subscribing to feedback-request/$device", 0); $this->Subscribe("feedback-request/$device");
$this->SendDebug("Subscribe", "Subscribing to remote-control-response/$device", 0); $this->Subscribe("remote-control-response/$device");
}
// Subscription: Feedback-Request private function Subscribe(string $topic)
$this->SendDataToParent(json_encode([ {
"DataID" => "{A339BCF8-68B7-4A41-A4EF-6A9C55A2B4E3}", $this->SendDebug("Subscribe", "Subscribing to Topic: $topic", 0);
"Topic" => "feedback-request/$device",
"Retain" => false
]));
// Subscription: Remote-Control-Response
$this->SendDataToParent(json_encode([ $this->SendDataToParent(json_encode([
"DataID" => "{A339BCF8-68B7-4A41-A4EF-6A9C55A2B4E3}", "DataID" => "{04346E0A-99B3-4D6C-8F00-7E7A5C32A54B}", // MQTT_Subscribe
"Topic" => "remote-control-response/$device", "Topic" => $topic
"Retain" => false ]));
}
private function Publish(string $topic, string $payload)
{
$this->SendDebug("Publish", "Topic: $topic Payload: $payload", 0);
$this->SendDataToParent(json_encode([
"DataID" => "{04346E0A-99B3-4D6C-8F00-7E7A5C32A54B}", // MQTT_Publish
"Topic" => $topic,
"Payload" => $payload
])); ]));
} }
// Wird aufgerufen wenn MQTT-Daten hereinkommen
public function ReceiveData($JSONString) public function ReceiveData($JSONString)
{ {
$data = json_decode($JSONString, true); $data = json_decode($JSONString, true);
$topic = $data['Topic'] ?? ''; $topic = $data['Topic'] ?? '';
$payload = $data['Payload'] ?? ''; $message = $data['Message'] ?? '';
$device = $this->ReadPropertyString('DeviceID'); $device = $this->ReadPropertyString('DeviceID');
// 1⃣ Client fragt Feedback an → Modul sendet feste Antwort zurück $this->SendDebug("Receive", "Topic: $topic Message: $message", 0);
if ($topic === "feedback-request/$device") {
$this->SendDebug("Receive", "Feedback request received", 0); /** 1⃣ FEEDBACK REQUEST → Starre JSON Antwort senden */
if ($topic === "feedback-request/$device") {
$response = [ $response = [
"power_production" => 123, "power_production" => 123,
@@ -73,37 +79,19 @@ class Int_VGT extends IPSModule
return; return;
} }
// 2⃣ Remote-Control-Response empfangen /** 2⃣ Remote-Control-Response empfangen */
if ($topic === "remote-control-response/$device") { if ($topic === "remote-control-response/$device") {
$this->SendDebug("Receive", "Remote control payload received", 0); $this->SetValue('RemoteControlPayload', $message);
// In Variable speichern $this->HandleRemoteControl($message);
$this->SetValue('RemoteControlPayload', $payload);
// Optional weiterverarbeiten
$this->HandleRemoteControl($payload);
} }
} }
private function Publish(string $topic, string $payload)
{
$this->SendDebug("Publish", "Topic: $topic Payload: $payload", 0);
// MQTT Publish an Splitter senden
$this->SendDataToParent(json_encode([
"DataID" => "{7F7632D9-A122-4C43-8C21-A4943C1BFB79}",
"Topic" => $topic,
"Payload" => $payload,
"Retain" => false
]));
}
// Methode für spätere Aktion
protected function HandleRemoteControl(string $payload) protected function HandleRemoteControl(string $payload)
{ {
$this->SendDebug("RemoteControl", "Processing payload: $payload", 0); $this->SendDebug("RemoteControl", "Payload received: $payload", 0);
// → Hier kann später custom Code rein // → Hier kannst du später Custom Logic einbauen
} }
} }