no message
This commit is contained in:
@@ -8,6 +8,6 @@
|
|||||||
"{7F8A48DD-F8AD-4F9C-8E6B-9E4D92DDB8F9}"
|
"{7F8A48DD-F8AD-4F9C-8E6B-9E4D92DDB8F9}"
|
||||||
],
|
],
|
||||||
"childRequirements": [],
|
"childRequirements": [],
|
||||||
"implemented": ["MQTTSERVER"],
|
"implemented": [],
|
||||||
"prefix": "INTVGT"
|
"prefix": "INTVGT"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,85 +7,73 @@ class Int_VGT extends IPSModule
|
|||||||
public function Create()
|
public function Create()
|
||||||
{
|
{
|
||||||
parent::Create();
|
parent::Create();
|
||||||
|
|
||||||
$this->RegisterPropertyString("DeviceID", "");
|
$this->RegisterPropertyString("DeviceID", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ApplyChanges()
|
public function ApplyChanges()
|
||||||
{
|
{
|
||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
|
// Verbindung zur ausgewählten Gateway-Instanz
|
||||||
// MQTT-Server verbinden
|
|
||||||
$this->ConnectParent("{7F8A48DD-F8AD-4F9C-8E6B-9E4D92DDB8F9}");
|
$this->ConnectParent("{7F8A48DD-F8AD-4F9C-8E6B-9E4D92DDB8F9}");
|
||||||
|
$deviceID = $this->ReadPropertyString("DeviceID");
|
||||||
|
|
||||||
// Status prüfen
|
if ($deviceID === "") {
|
||||||
if ($this->ReadPropertyString("DeviceID") == "") {
|
|
||||||
$this->SetStatus(104);
|
$this->SetStatus(104);
|
||||||
} else {
|
} else {
|
||||||
$this->SetStatus(102);
|
$this->SetStatus(102);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Wird vom MQTT Server aufgerufen */
|
public function ReceiveData(string $JSONString)
|
||||||
public function ReceiveData($JSONString)
|
|
||||||
{
|
{
|
||||||
$data = json_decode($JSONString, true);
|
$data = json_decode($JSONString, true);
|
||||||
|
if ($data === null) {
|
||||||
// Beispiel MQTT-Datenformat:
|
return;
|
||||||
// [
|
}
|
||||||
// "Topic" => "...",
|
|
||||||
// "Payload" => "..."
|
|
||||||
// ]
|
|
||||||
|
|
||||||
if (!isset($data["Topic"]) || !isset($data["Payload"])) {
|
if (!isset($data["Topic"]) || !isset($data["Payload"])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$topic = $data["Topic"];
|
$topic = $data["Topic"];
|
||||||
$value = $data["Payload"];
|
$payload = $data["Payload"];
|
||||||
|
|
||||||
IPS_LogMessage("Int_VGT", "MQTT RX: $topic → $value");
|
IPS_LogMessage("Int_VGT", "Received topic: {$topic}, payload: {$payload}");
|
||||||
|
$this->HandleIncoming($topic, $payload);
|
||||||
$this->HandleIncoming($topic, $value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Deine Logik */
|
private function HandleIncoming(string $topic, string $payload)
|
||||||
private function HandleIncoming(string $topic, string $value)
|
|
||||||
{
|
{
|
||||||
$deviceID = $this->ReadPropertyString("DeviceID");
|
$deviceID = $this->ReadPropertyString("DeviceID");
|
||||||
$gateway = $this->InstanceID;
|
|
||||||
|
|
||||||
// Feedback Request
|
|
||||||
if ($topic === "feedback-request/$deviceID") {
|
|
||||||
|
|
||||||
|
if ($topic === "feedback-request/{$deviceID}") {
|
||||||
$response = json_encode([
|
$response = json_encode([
|
||||||
"status" => "ok",
|
"status" => "ok",
|
||||||
"timestamp" => time()
|
"timestamp" => time()
|
||||||
]);
|
]);
|
||||||
|
$this->Publish("feedback-response/{$deviceID}", $response);
|
||||||
$this->Publish("feedback-response/$deviceID", $response);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remote Control
|
if ($topic === "remote-control-response/{$deviceID}") {
|
||||||
if ($topic === "remote-control-response/$deviceID") {
|
// Echo same payload
|
||||||
$this->Publish("remote-control-feedback/$deviceID", $value);
|
$this->Publish("remote-control-feedback/{$deviceID}", $payload);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** MQTT Publish Wrapper */
|
|
||||||
private function Publish(string $topic, string $payload)
|
private function Publish(string $topic, string $payload)
|
||||||
{
|
{
|
||||||
$msg = [
|
$message = [
|
||||||
"Topic" => $topic,
|
"Topic" => $topic,
|
||||||
"Payload" => $payload,
|
"Payload" => $payload,
|
||||||
"Retain" => false,
|
"Retain" => false,
|
||||||
"QoS" => 0
|
"QoS" => 0
|
||||||
];
|
];
|
||||||
|
$data = [
|
||||||
$this->SendDataToParent(json_encode(["DataID" => "{7F8A48DD-F8AD-4F9C-8E6B-9E4D92DDB8F9}", "Packet" => $msg]));
|
"DataID" => "{7F8A48DD-F8AD-4F9C-8E6B-9E4D92DDB8F9}",
|
||||||
|
"Packet" => $message
|
||||||
|
];
|
||||||
|
$this->SendDataToParent(json_encode($data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user