no message

This commit is contained in:
dh
2025-11-13 09:04:15 +01:00
parent c1e989ef3c
commit d3bf44dc65
2 changed files with 68 additions and 43 deletions
+4 -4
View File
@@ -3,11 +3,11 @@
"name": "Int_VGT", "name": "Int_VGT",
"type": 3, "type": 3,
"vendor": "Belevo", "vendor": "Belevo",
"aliases": ["INT VGT Integration"], "aliases": [],
"parentRequirements": [ "parentRequirements": [
"{7F8A48DD-F8AD-4F9C-8E6B-9E4D92DDB8F9}" "{EE0D345A-CF31-428A-A613-06B90F6C5C57}"
], ],
"childRequirements": [], "childRequirements": [],
"implemented": ["MQTT"], "implemented": [],
"prefix": "INTVGT" "prefix": "VGT"
} }
+66 -41
View File
@@ -7,72 +7,97 @@ class Int_VGT extends IPSModule
public function Create() public function Create()
{ {
parent::Create(); parent::Create();
$this->RegisterPropertyString("DeviceID", "");
$this->RegisterPropertyString('DeviceID', '');
// Variable für empfangene Remote-Control-Daten
$this->RegisterVariableString('RemoteControlPayload', 'Remote Control Payload', '', 1);
// Splitter (MQTT Server)
$this->ConnectParent("{EE0D345A-CF31-428A-A613-06B90F6C5C57}");
} }
public function ApplyChanges() public function ApplyChanges()
{ {
parent::ApplyChanges(); parent::ApplyChanges();
// mit dem Parent verbinden (MQTT Server) $device = $this->ReadPropertyString('DeviceID');
$this->ConnectParent("{7F8A48DD-F8AD-4F9C-8E6B-9E4D92DDB8F9}");
if ($this->ReadPropertyString("DeviceID") == "") { if ($device == '') {
$this->SetStatus(104); return;
} else {
$this->SetStatus(102);
}
} }
public function ReceiveData(string $JSONString) // Routen abonnieren
$this->SendDebug("Subscribe", "Subscribing to feedback-request/$device", 0);
$this->SendDebug("Subscribe", "Subscribing to /remote-control-response/$device", 0);
// Subscription 1
$this->SendDataToParent(json_encode([
"DataID" => "{A339BCF8-68B7-4A41-A4EF-6A9C55A2B4E3}",
"Topic" => "feedback-request/$device",
"Retain" => false
]));
// Subscription 2
$this->SendDataToParent(json_encode([
"DataID" => "{A339BCF8-68B7-4A41-A4EF-6A9C55A2B4E3}",
"Topic" => "/remote-control-response/$device",
"Retain" => false
]));
}
// Wird aufgerufen wenn MQTT-Daten reinkommen
public function ReceiveData($JSONString)
{ {
$data = json_decode($JSONString, true); $data = json_decode($JSONString, true);
$topic = $data['Topic'] ?? '';
$payload = $data['Payload'] ?? '';
$topic = $data["Topic"] ?? ""; $device = $this->ReadPropertyString('DeviceID');
$payload = $data["Payload"] ?? "";
IPS_LogMessage("Int_VGT", "RX: $topic → $payload");
$this->HandleIncoming($topic, $payload);
}
private function HandleIncoming(string $topic, string $payload)
{
$device = $this->ReadPropertyString("DeviceID");
// 1️⃣ REQUEST von Client → fixe Antwort senden
if ($topic === "feedback-request/$device") { if ($topic === "feedback-request/$device") {
$this->SendDebug("Receive", "Feedback request received", 0);
$resp = json_encode([ $response = [
"status" => "ok", "power_production" => 123,
"ts" => time() "is_ready" => true,
]); "is_running" => true,
"state_of_charge" => 50,
"min_soc" => 10,
"max_soc" => 90
];
$this->Publish("feedback-response/$device", $resp); $this->Publish("feedback-response/$device", json_encode($response));
return;
} }
if ($topic === "remote-control-response/$device") { // 2️⃣ REMOTE CONTROL PAYLOAD speichern & weiterreichen
$this->Publish("remote-control-feedback/$device", $payload); if ($topic === "/remote-control-response/$device") {
$this->SetValue('RemoteControlPayload', $payload);
$this->HandleRemoteControl($payload);
} }
} }
private function Publish(string $topic, string $payload) private function Publish(string $topic, string $payload)
{ {
$msg = [ $this->SendDebug("Publish", "Topic: $topic Payload: $payload", 0);
"DataID" => "{043EA491-84DA-4DFD-B9D4-44B4E63F23D1}",
$this->SendDataToParent(json_encode([
"DataID" => "{7F7632D9-A122-4C43-8C21-A4943C1BFB79}", // Publish MQTT
"Topic" => $topic, "Topic" => $topic,
"Payload" => $payload "Payload" => $payload,
]; "Retain" => false
]));
IPS_LogMessage("Int_VGT", "TX: $topic → $payload");
$this->SendDataToParent(json_encode($msg));
} }
public function RequestAction($Ident, $Value) // Leere Methode — kannst du später programmieren
protected function HandleRemoteControl(string $payload)
{ {
return; $this->SendDebug("RemoteControl", "Received RC payload: $payload", 0);
// Erforderlich – auch wenn leer
}
}
?> // → HIER deinen Code später einfügen
}
}