no message

This commit is contained in:
2025-11-13 08:29:49 +01:00
parent e6d41583cd
commit 694e74e9ca

View File

@@ -7,7 +7,6 @@ class Int_VGT extends IPSModule
public function Create() public function Create()
{ {
parent::Create(); parent::Create();
$this->RegisterPropertyString("DeviceID", ""); $this->RegisterPropertyString("DeviceID", "");
} }
@@ -15,99 +14,64 @@ class Int_VGT extends IPSModule
{ {
parent::ApplyChanges(); parent::ApplyChanges();
// MQTT Server als Parent verbinden // mit dem Parent verbinden (MQTT Server)
$this->ConnectParent("{7F8A48DD-F8AD-4F9C-8E6B-9E4D92DDB8F9}"); $this->ConnectParent("{7F8A48DD-F8AD-4F9C-8E6B-9E4D92DDB8F9}");
if ($this->ReadPropertyString("DeviceID") == "") { if ($this->ReadPropertyString("DeviceID") == "") {
$this->SetStatus(104); // config error $this->SetStatus(104);
} else { } else {
$this->SetStatus(102); // OK $this->SetStatus(102);
} }
} }
/**
* Required when using RequestAction
*/
public function RequestAction($Ident, $Value)
{
// Im Moment haben wir keine Action-Variablen
// Wird aber von Symcon benötigt → also leer implementiert
return;
}
/**
* Wird vom MQTT Server aufgerufen wenn Daten ankommen
*/
public function ReceiveData(string $JSONString) public function ReceiveData(string $JSONString)
{ {
$buffer = json_decode($JSONString, true); $data = json_decode($JSONString, true);
if ($buffer === null) {
IPS_LogMessage("Int_VGT", "Invalid JSON received.");
return;
}
if (!isset($buffer['Topic']) || !isset($buffer['Payload'])) { $topic = $data["Topic"] ?? "";
IPS_LogMessage("Int_VGT", "Missing keys in buffer."); $payload = $data["Payload"] ?? "";
return;
}
$topic = $buffer['Topic']; IPS_LogMessage("Int_VGT", "RX: $topic$payload");
$payload = $buffer['Payload'];
IPS_LogMessage("Int_VGT", "MQTT RX: {$topic}{$payload}");
$this->HandleIncoming($topic, $payload); $this->HandleIncoming($topic, $payload);
} }
/**
* Verarbeitet eingehende MQTT-Nachrichten
*/
private function HandleIncoming(string $topic, string $payload) private function HandleIncoming(string $topic, string $payload)
{ {
$deviceID = $this->ReadPropertyString("DeviceID"); $device = $this->ReadPropertyString("DeviceID");
if ($deviceID == "") { if ($topic === "feedback-request/$device") {
return; // no config
}
// 1) Feedback Request $resp = json_encode([
if ($topic === "feedback-request/{$deviceID}") {
$response = json_encode([
"status" => "ok", "status" => "ok",
"timestamp" => time() "ts" => time()
]); ]);
$this->Publish("feedback-response/{$deviceID}", $response); $this->Publish("feedback-response/$device", $resp);
return;
} }
// 2) Remote Control Echo if ($topic === "remote-control-response/$device") {
if ($topic === "remote-control-response/{$deviceID}") { $this->Publish("remote-control-feedback/$device", $payload);
$this->Publish("remote-control-feedback/{$deviceID}", $payload);
return;
} }
} }
/**
* Publisht MQTT-Daten über das Gateway
*/
private function Publish(string $topic, string $payload) private function Publish(string $topic, string $payload)
{ {
$data = [ $msg = [
"DataID" => "{7F8A48DD-F8AD-4F9C-8E6B-9E4D92DDB8F9}", "DataID" => "{043EA491-84DA-4DFD-B9D4-44B4E63F23D1}",
"Packet" => [
"Topic" => $topic, "Topic" => $topic,
"Payload" => $payload, "Payload" => $payload
"QoS" => 0,
"Retain" => false
]
]; ];
IPS_LogMessage("Int_VGT", "MQTT TX: $topic$payload"); IPS_LogMessage("Int_VGT", "TX: $topic$payload");
$this->SendDataToParent(json_encode($data)); $this->SendDataToParent(json_encode($msg));
}
public function RequestAction($Ident, $Value)
{
return;
// Erforderlich auch wenn leer
} }
} }