ka
This commit is contained in:
@@ -24,6 +24,11 @@
|
||||
"type": "ValidationTextBox",
|
||||
"name": "Topic",
|
||||
"caption": "MQTT Topic"
|
||||
},
|
||||
{
|
||||
"type": "ValidationTextBox",
|
||||
"name": "client_id",
|
||||
"caption": "Klient Id"
|
||||
},
|
||||
{
|
||||
"type": "NumberSpinner",
|
||||
|
||||
@@ -12,7 +12,7 @@ class Symcon_Publish_to_Shelly_MQTT extends IPSModule
|
||||
$this->RegisterPropertyString("username", "");
|
||||
$this->RegisterPropertyString("password", "");
|
||||
$this->RegisterPropertyString("Topic", "");
|
||||
$this->RegisterPropertyInteger("mqtt_instance_id", 0); // ID der MQTT-Instanz als Konfig-Feld
|
||||
$this->RegisterPropertyString("client_id", "");
|
||||
|
||||
// Nachricht-Payload-Parameter als Properties
|
||||
$this->RegisterPropertyInteger("msg_id", 100);
|
||||
@@ -56,7 +56,7 @@ class Symcon_Publish_to_Shelly_MQTT extends IPSModule
|
||||
$pass = $this->ReadPropertyString("password");
|
||||
$topic = $this->ReadPropertyString("Topic");
|
||||
$mqttInstanceID = $this->ReadPropertyInteger("mqtt_instance_id");
|
||||
|
||||
$client_id = $this->ReadPropertyString("client_id");
|
||||
$msg_id = $this->ReadPropertyInteger("msg_id");
|
||||
$src = $this->ReadPropertyString("src");
|
||||
$method = $this->ReadPropertyString("method");
|
||||
@@ -89,22 +89,15 @@ class Symcon_Publish_to_Shelly_MQTT extends IPSModule
|
||||
$json = json_encode($payload);
|
||||
IPS_LogMessage("ShellySwitchSender", "MQTT Payload: $json");
|
||||
|
||||
if ($mqttInstanceID > 0 && IPS_InstanceExists($mqttInstanceID)) {
|
||||
$instanceInfo = IPS_GetInstance($mqttInstanceID);
|
||||
$moduleID = $instanceInfo['ModuleInfo']['ModuleID'];
|
||||
IPS_LogMessage("ShellySwitchSender", "MQTT Instanz gefunden: ID $mqttInstanceID, ModuleID $moduleID");
|
||||
$mqtt = new phpMQTT($broker, $port, $client_id);
|
||||
|
||||
if (
|
||||
$moduleID == "{C03937E3-5F86-EACA-B4A2-39A24ACF945A}" || // Alter MQTTClient
|
||||
$moduleID == "{C8792760-65CF-4C53-B5C7-A30FCC84FEFE}" // Offizieller MQTTClient
|
||||
) {
|
||||
MQTTClient_Publish($mqttInstanceID, $topic, $json, 0, false);
|
||||
IPS_LogMessage("ShellySwitchSender", "Nachricht an Topic '$topic' gesendet.");
|
||||
} else {
|
||||
IPS_LogMessage("ShellySwitchSender", "FEHLER: MQTT Instanz ist kein gültiges MQTT-Modul.");
|
||||
}
|
||||
if ($mqtt->connect(true, NULL, $username, $password)) {
|
||||
IPS_LogMessage("ShellySwitchSender", "Verbunden mit dem MQTT-Broker");
|
||||
$mqtt->publish($topic, $payload, 0);
|
||||
IPS_LogMessage("ShellySwitchSender", "Nachricht gesende");
|
||||
$mqtt->close();
|
||||
} else {
|
||||
IPS_LogMessage("ShellySwitchSender", "FEHLER: MQTT Instanz nicht gefunden oder ungültig (ID: $mqttInstanceID).");
|
||||
IPS_LogMessage("ShellySwitchSender", "Verbindung fehlgeschlagen");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user