Enhance MQTT publishing logic in SendTopic and ForceSendTopic methods to improve handling of child variables and update conditions; update library version to 2.9.
This commit is contained in:
@@ -121,6 +121,7 @@ class MonitoringClient extends IPSModule {
|
|||||||
} // MQTT_Publish
|
} // MQTT_Publish
|
||||||
|
|
||||||
public function SendTopic() {
|
public function SendTopic() {
|
||||||
|
|
||||||
$mqttId = $this->ReadPropertyInteger("MqttCLientID");
|
$mqttId = $this->ReadPropertyInteger("MqttCLientID");
|
||||||
$projectyear = $this->ReadPropertyInteger("Projectyear");
|
$projectyear = $this->ReadPropertyInteger("Projectyear");
|
||||||
$projectnumber = $this->ReadPropertyInteger("Projectnumber");
|
$projectnumber = $this->ReadPropertyInteger("Projectnumber");
|
||||||
@@ -147,47 +148,65 @@ class MonitoringClient extends IPSModule {
|
|||||||
|
|
||||||
$parname = IPS_GetName($catChild);
|
$parname = IPS_GetName($catChild);
|
||||||
|
|
||||||
$parname = str_replace("/","_", $parname);
|
if (IPS_VariableExists($catChild) != 1 && IPS_LinkExists($catChild) != 1){
|
||||||
|
|
||||||
IPS_SetName($catChild, $parname);
|
|
||||||
|
|
||||||
foreach ($childids as $childid){
|
foreach ($childids as $childid){
|
||||||
if (IPS_VariableExists($childid) != 1){
|
|
||||||
|
|
||||||
if(IPS_LinkExists($childid) == 1){
|
|
||||||
$linkInfo = IPS_GetLink($childid);
|
|
||||||
$linkTarget = $linkInfo["TargetID"];
|
foreach ($childids as $childid){
|
||||||
$childid = $linkTarget;
|
if (IPS_VariableExists($childid) != 1){
|
||||||
|
|
||||||
|
if(IPS_LinkExists($childid) == 1){
|
||||||
|
$linkInfo = IPS_GetLink($childid);
|
||||||
|
$linkTarget = $linkInfo["TargetID"];
|
||||||
|
$childid = $linkTarget;
|
||||||
|
$varInfo = IPS_GetVariable($childid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$varInfo = IPS_GetVariable($childid);
|
||||||
|
$varname = IPS_GetName($childid);
|
||||||
|
$topic = $catId["top"]. $parname."_".$varname;
|
||||||
|
$payload = round(getvalue($childid), 2);
|
||||||
|
|
||||||
|
if($changedtime > $time - $updatetime){
|
||||||
|
$this->MqttPublish($mqttId, $topic, $payload, false);
|
||||||
|
}
|
||||||
|
// IPS_LogMessage("Monitoring Client", "Force Update with Parent: " . $topic . " mit Payload: " . $payload);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$childid = $catChild;
|
||||||
|
if (IPS_VariableExists($childid) != 1){
|
||||||
|
|
||||||
|
if(IPS_LinkExists($childid) == 1){
|
||||||
|
$linkInfo = IPS_GetLink($childid);
|
||||||
|
$linkTarget = $linkInfo["TargetID"];
|
||||||
|
$childid = $linkTarget;
|
||||||
|
$varInfo = IPS_GetVariable($childid);
|
||||||
}
|
}
|
||||||
|
|
||||||
$varInfo = IPS_GetVariable($childid);
|
|
||||||
|
|
||||||
$changedtime = $varInfo["VariableChanged"];
|
|
||||||
$varname = IPS_GetName($childid);
|
|
||||||
|
|
||||||
|
|
||||||
$varname = str_replace("/","_", $varname);
|
|
||||||
|
|
||||||
IPS_SetName($childid, $varname);
|
|
||||||
|
|
||||||
$topic = $catId["top"]. $parname."_".$varname;
|
|
||||||
$time = time();
|
|
||||||
$payload = round(getvalue($childid), 2);
|
|
||||||
|
|
||||||
if($changedtime > $time - $updatetime){
|
|
||||||
SEMC_MqttPublish($this->InstanceID,$mqttId, $topic, $payload, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$varInfo = IPS_GetVariable($childid);
|
||||||
|
$varname = IPS_GetName($childid);
|
||||||
|
$topic = $catId["top"].$varname;
|
||||||
|
$payload = round(getvalue($childid), 2);
|
||||||
|
|
||||||
|
if($changedtime > $time - $updatetime){
|
||||||
|
$this->MqttPublish($mqttId, $topic, $payload, false);
|
||||||
|
}
|
||||||
|
// IPS_LogMessage("Monitoring Client", "Force Update none Parent: " . $topic . " mit Payload: " . $payload);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
$topic = "Projekte". $projectyear."/".$projectnumber. "/ISP" .$ispnumber. "/Name";
|
||||||
|
$this->MqttPublish($mqttId, $topic, $projectname, false);
|
||||||
|
|
||||||
|
}
|
||||||
public function ForceSendTopic() {
|
public function ForceSendTopic() {
|
||||||
|
|
||||||
$mqttId = $this->ReadPropertyInteger("MqttCLientID");
|
$mqttId = $this->ReadPropertyInteger("MqttCLientID");
|
||||||
@@ -239,7 +258,7 @@ class MonitoringClient extends IPSModule {
|
|||||||
$payload = round(getvalue($childid), 2);
|
$payload = round(getvalue($childid), 2);
|
||||||
|
|
||||||
$this->MqttPublish($mqttId, $topic, $payload, false);
|
$this->MqttPublish($mqttId, $topic, $payload, false);
|
||||||
IPS_LogMessage("Monitoring Client", "Force Update with Parent: " . $topic . " mit Payload: " . $payload);
|
// IPS_LogMessage("Monitoring Client", "Force Update with Parent: " . $topic . " mit Payload: " . $payload);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,7 +281,7 @@ class MonitoringClient extends IPSModule {
|
|||||||
$payload = round(getvalue($childid), 2);
|
$payload = round(getvalue($childid), 2);
|
||||||
|
|
||||||
$this->MqttPublish($mqttId, $topic, $payload, false);
|
$this->MqttPublish($mqttId, $topic, $payload, false);
|
||||||
IPS_LogMessage("Monitoring Client", "Force Update none Parent: " . $topic . " mit Payload: " . $payload);
|
// IPS_LogMessage("Monitoring Client", "Force Update none Parent: " . $topic . " mit Payload: " . $payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -7,7 +7,7 @@
|
|||||||
"version": "6.0",
|
"version": "6.0",
|
||||||
"date": 1491343200
|
"date": 1491343200
|
||||||
},
|
},
|
||||||
"version": "2.8",
|
"version": "2.9",
|
||||||
"build": 2,
|
"build": 1,
|
||||||
"date": 0
|
"date": 0
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user