Refactor MQTT publishing logic to handle linked variables and improve code clarity
This commit is contained in:
@@ -153,11 +153,13 @@ class MonitoringClient extends IPSModule {
|
||||
|
||||
foreach ($childids as $childid){
|
||||
if (IPS_VariableExists($childid) != 1){
|
||||
|
||||
if(IPS_LinkExists($childid) == 1){
|
||||
$linkInfo = IPS_GetLink($childid);
|
||||
$linkTarget = $linkInfo["TargetID"];
|
||||
$childid = $linkTarget;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$varInfo = IPS_GetVariable($childid);
|
||||
@@ -173,6 +175,7 @@ class MonitoringClient extends IPSModule {
|
||||
$topic = $catId["top"]. $parname."_".$varname;
|
||||
$time = time();
|
||||
$payload = round(getvalue($childid), 2);
|
||||
|
||||
if($changedtime > $time - $updatetime){
|
||||
SEMC_MqttPublish($this->InstanceID,$mqttId, $topic, $payload, false);
|
||||
}
|
||||
@@ -215,6 +218,8 @@ class MonitoringClient extends IPSModule {
|
||||
|
||||
foreach ($childids as $childid){
|
||||
|
||||
if (IPS_VariableExists($childid) != 1 && IPS_LinkExists($childid) != 1){
|
||||
|
||||
foreach ($childids as $childid){
|
||||
if (IPS_VariableExists($childid) != 1){
|
||||
|
||||
@@ -231,17 +236,34 @@ class MonitoringClient extends IPSModule {
|
||||
$topic = $catId["top"]. $parname."_".$varname;
|
||||
$payload = round(getvalue($childid), 2);
|
||||
|
||||
SEMC_MqttPublish($this->InstanceID,$mqttId, $topic, $payload, false);
|
||||
$this->MqttPublish($this->InstanceID,$mqttId, $topic, $payload, false);
|
||||
|
||||
}
|
||||
}else{
|
||||
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);
|
||||
|
||||
$this->MqttPublish($this->InstanceID,$mqttId, $topic, $payload, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
$topic = "Projekte". $projectyear."/".$projectnumber. "/ISP" .$ispnumber. "/Name";
|
||||
SEMC_MqttPublish($this->InstanceID,$mqttId, $topic, $projectname, false);
|
||||
$this->MqttPublish($this->InstanceID,$mqttId, $topic, $projectname, false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user