Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8719dec2de | ||
|
|
5deebeffd5 | ||
|
|
4f7a2b8199 | ||
|
|
1855868435 | ||
|
|
9bb1636ddf | ||
|
|
d17e81a5ab | ||
|
|
444b6a2a8d | ||
|
|
1bb10e2bc7 | ||
|
|
1cd8bb5547 | ||
|
|
08e55c604c |
@@ -9,8 +9,8 @@ class MonitoringClient extends IPSModule {
|
|||||||
$this->RegisterPropertyInteger("ParseNotifyCategoryID","0");
|
$this->RegisterPropertyInteger("ParseNotifyCategoryID","0");
|
||||||
$this->RegisterPropertyInteger("ParseAlarmCategoryID","0");
|
$this->RegisterPropertyInteger("ParseAlarmCategoryID","0");
|
||||||
$this->RegisterPropertyInteger("ParseAnalogCategoryID","0");
|
$this->RegisterPropertyInteger("ParseAnalogCategoryID","0");
|
||||||
$this->RegisterPropertyInteger("ParseSetpointCategoryID","0");
|
$this->RegisterPropertyInteger("ParseSetpointCategoryID",-1);
|
||||||
$this->RegisterPropertyInteger("ParseSetpointCacheCategoryID","0");
|
$this->RegisterPropertyInteger("ParseSetpointCacheCategoryID",-1);
|
||||||
|
|
||||||
$this->RegisterPropertyInteger("MqttCLientID","0");
|
$this->RegisterPropertyInteger("MqttCLientID","0");
|
||||||
$this->RegisterPropertyInteger("Projectnumber","230001");
|
$this->RegisterPropertyInteger("Projectnumber","230001");
|
||||||
@@ -123,23 +123,28 @@ class MonitoringClient extends IPSModule {
|
|||||||
} // MQTT_Publish
|
} // MQTT_Publish
|
||||||
|
|
||||||
public function MqttSync($server_id, $topic, $payload, $retain, $ident, $source) {
|
public function MqttSync($server_id, $topic, $payload, $retain, $ident, $source) {
|
||||||
|
IPS_LogMessage("Monitoring Client", "MQTT Sync called with Topic: " . $topic . " Payload: " . $payload. " Source: " . $source . " Ident: " . $ident);
|
||||||
$cacheCat = $this->ReadPropertyInteger("ParseSetpointCacheCategoryID");
|
$cacheCat = $this->ReadPropertyInteger("ParseSetpointCacheCategoryID");
|
||||||
|
|
||||||
if ($cacheCat == 0){
|
if ($cacheCat < 1){
|
||||||
|
IPS_LogMessage("Monitoring Client", "No Cache Category defined for Setpoint Sync. Please define a Cache Category to use this feature.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IPS_CategoryExists($cacheCat) == false){
|
if (IPS_CategoryExists($cacheCat) == false){
|
||||||
|
IPS_LogMessage("Monitoring Client", "Cache Category does not exist for Setpoint Sync.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IPS_VariableExists($source) == false){
|
if (IPS_VariableExists($source) == false){
|
||||||
|
IPS_LogMessage("Monitoring Client", "Source variable does not exist for Setpoint Sync.");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure server instance exists
|
// ensure server instance exists
|
||||||
if(!IPS_InstanceExists($server_id)) {
|
if(!IPS_InstanceExists($server_id)) {
|
||||||
|
IPS_LogMessage("Monitoring Client", "Server instance does not exist for Setpoint Sync.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +160,9 @@ class MonitoringClient extends IPSModule {
|
|||||||
$ips_var_type = 0;
|
$ips_var_type = 0;
|
||||||
} else { // unsupported
|
} else { // unsupported
|
||||||
return false;
|
return false;
|
||||||
|
IPS_LogMessage("Monitoring Client", "Unsupported data type for Setpoint Sync.");
|
||||||
}
|
}
|
||||||
|
IPS_LogMessage("Monitoring Client", "Data type for Setpoint Sync determined as: " . $ips_var_type);
|
||||||
|
|
||||||
$module_id = "{01C00ADD-D04E-452E-B66A-D253278743FE}" /* Module ID of MQTT Server Device */;
|
$module_id = "{01C00ADD-D04E-452E-B66A-D253278743FE}" /* Module ID of MQTT Server Device */;
|
||||||
|
|
||||||
@@ -169,7 +176,7 @@ class MonitoringClient extends IPSModule {
|
|||||||
IPS_SetParent($id, $cacheCat);
|
IPS_SetParent($id, $cacheCat);
|
||||||
IPS_SetIdent($id, $ident);
|
IPS_SetIdent($id, $ident);
|
||||||
// name object to help with debugging
|
// name object to help with debugging
|
||||||
IPS_SetName($id, "CS_" . $name);
|
IPS_SetName($id, "CS_" . $ident);
|
||||||
|
|
||||||
// configure temporary device
|
// configure temporary device
|
||||||
$config_arr = array(
|
$config_arr = array(
|
||||||
@@ -186,6 +193,7 @@ class MonitoringClient extends IPSModule {
|
|||||||
// ensure the specified server instance is actually compatible
|
// ensure the specified server instance is actually compatible
|
||||||
if(!IPS_IsInstanceCompatible($id, $server_id)) {
|
if(!IPS_IsInstanceCompatible($id, $server_id)) {
|
||||||
return false;
|
return false;
|
||||||
|
IPS_LogMessage("Monitoring Client", "Device is not compatible with server instance for Setpoint Sync.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$inst_config = IPS_GetInstance($id);
|
$inst_config = IPS_GetInstance($id);
|
||||||
@@ -193,11 +201,17 @@ class MonitoringClient extends IPSModule {
|
|||||||
IPS_DisconnectInstance($id);
|
IPS_DisconnectInstance($id);
|
||||||
if(!@IPS_ConnectInstance($id, $server_id)) {
|
if(!@IPS_ConnectInstance($id, $server_id)) {
|
||||||
return false;
|
return false;
|
||||||
|
IPS_LogMessage("Monitoring Client", "Could not connect device to server instance for Setpoint Sync.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
IPS_LogMessage("Monitoring Client", "Parentid was :".$id);
|
||||||
|
$id = IPS_GetChildrenIDs($id)[0];
|
||||||
|
IPS_LogMessage("Monitoring Client", "ID was :".$id);
|
||||||
|
|
||||||
$valSelf = $this->GetValue($id);
|
$valSelf = GetValue($id);
|
||||||
$valSource = $this->GetValue($source);
|
$valSource = GetValue($source);
|
||||||
|
|
||||||
|
IPS_LogMessage("Monitoring Client", "Self value: " . $valSelf . " Source value: " . $valSource);
|
||||||
|
|
||||||
$varInfoSelf = IPS_GetVariable($id);
|
$varInfoSelf = IPS_GetVariable($id);
|
||||||
$changedtimeSelf = $varInfoSelf["VariableChanged"];
|
$changedtimeSelf = $varInfoSelf["VariableChanged"];
|
||||||
@@ -210,11 +224,13 @@ class MonitoringClient extends IPSModule {
|
|||||||
//self is newer than source, so update source with self value
|
//self is newer than source, so update source with self value
|
||||||
if ($changedtimeSelf > $changedtimeSource) {
|
if ($changedtimeSelf > $changedtimeSource) {
|
||||||
RequestAction($source, $valSelf);
|
RequestAction($source, $valSelf);
|
||||||
|
IPS_LogMessage("Monitoring Client", "Source variable updated with self value for Setpoint Sync. Source: " . $source . " Value: " . $valSelf);
|
||||||
}
|
}
|
||||||
|
|
||||||
//source is newer than self, so update self with source value
|
//source is newer than self, so update self with source value
|
||||||
if ($changedtimeSource > $changedtimeSelf) {
|
if ($changedtimeSource > $changedtimeSelf) {
|
||||||
RequestAction($id, $valSource);
|
RequestAction($id, $valSource);
|
||||||
|
IPS_LogMessage("Monitoring Client", "Self variable updated with source value for Setpoint Sync. Self: " . $id . " Value: " . $valSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -235,10 +251,13 @@ class MonitoringClient extends IPSModule {
|
|||||||
|
|
||||||
$catIds[0]["id"] = $this->ReadPropertyInteger("ParseNotifyCategoryID");
|
$catIds[0]["id"] = $this->ReadPropertyInteger("ParseNotifyCategoryID");
|
||||||
$catIds[0]["top"] = "Projekte". $projectyear."/P".$projectnumber. "/ISP" .$ispnumber. "/Notify/";
|
$catIds[0]["top"] = "Projekte". $projectyear."/P".$projectnumber. "/ISP" .$ispnumber. "/Notify/";
|
||||||
|
$catIds[0]["setpoint"] = false;
|
||||||
$catIds[1]["id"] = $this->ReadPropertyInteger("ParseAlarmCategoryID");
|
$catIds[1]["id"] = $this->ReadPropertyInteger("ParseAlarmCategoryID");
|
||||||
$catIds[1]["top"] = "Projekte". $projectyear."/P".$projectnumber. "/ISP" .$ispnumber. "/Alarm/";
|
$catIds[1]["top"] = "Projekte". $projectyear."/P".$projectnumber. "/ISP" .$ispnumber. "/Alarm/";
|
||||||
|
$catIds[1]["setpoint"] = false;
|
||||||
$catIds[2]["id"] = $this->ReadPropertyInteger("ParseAnalogCategoryID");
|
$catIds[2]["id"] = $this->ReadPropertyInteger("ParseAnalogCategoryID");
|
||||||
$catIds[2]["top"] = "Projekte". $projectyear."/P".$projectnumber. "/ISP" .$ispnumber. "/Analog/";
|
$catIds[2]["top"] = "Projekte". $projectyear."/P".$projectnumber. "/ISP" .$ispnumber. "/Analog/";
|
||||||
|
$catIds[2]["setpoint"] = false;
|
||||||
$catIds[3]["id"] = $this->ReadPropertyInteger("ParseSetpointCategoryID");
|
$catIds[3]["id"] = $this->ReadPropertyInteger("ParseSetpointCategoryID");
|
||||||
$catIds[3]["top"] = "Projekte". $projectyear."/P".$projectnumber. "/ISP" .$ispnumber. "/Setpoint/";
|
$catIds[3]["top"] = "Projekte". $projectyear."/P".$projectnumber. "/ISP" .$ispnumber. "/Setpoint/";
|
||||||
$catIds[3]["setpoint"] = true;
|
$catIds[3]["setpoint"] = true;
|
||||||
@@ -246,6 +265,8 @@ class MonitoringClient extends IPSModule {
|
|||||||
|
|
||||||
foreach ($catIds as $catId){
|
foreach ($catIds as $catId){
|
||||||
|
|
||||||
|
$isSetpoint = isset($catId["setpoint"]) ? $catId["setpoint"] : false;
|
||||||
|
|
||||||
$catChilds = IPS_GetChildrenIDs($catId["id"]);
|
$catChilds = IPS_GetChildrenIDs($catId["id"]);
|
||||||
|
|
||||||
foreach ($catChilds as $catChild) {
|
foreach ($catChilds as $catChild) {
|
||||||
@@ -273,13 +294,16 @@ class MonitoringClient extends IPSModule {
|
|||||||
$changedtime = $varInfo["VariableChanged"];
|
$changedtime = $varInfo["VariableChanged"];
|
||||||
$varname = IPS_GetName($childid);
|
$varname = IPS_GetName($childid);
|
||||||
$topic = $catId["top"]. $parname."_".$varname;
|
$topic = $catId["top"]. $parname."_".$varname;
|
||||||
|
$syncname = $parname."_".$varname;
|
||||||
$payload = round(getvalue($childid), 2);
|
$payload = round(getvalue($childid), 2);
|
||||||
$time = time();
|
$time = time();
|
||||||
|
|
||||||
$isSetpoint = isset($catId["setpoint"]) ? $catId["setpoint"] : false;
|
$isSetpoint = isset($catId["setpoint"]) ? $catId["setpoint"] : false;
|
||||||
|
|
||||||
if ($isSetpoint == true){
|
if ($isSetpoint == true){
|
||||||
$this->MqttSync($mqttId, $topic, $payload, false, $parname."_".$varname, $childid);
|
IPS_LogMessage("Monitoring Client", "Sync Setpoint: " . $topic . " mit Payload: " . $payload. " und Source: " . $childid . " und Ident: " . $syncname);
|
||||||
|
$this->MqttSync($mqttId, $topic, $payload, false, $syncname, $childid);
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
if($changedtime > $time - $updatetime){
|
if($changedtime > $time - $updatetime){
|
||||||
$this->MqttPublish($mqttId, $topic, $payload, false);
|
$this->MqttPublish($mqttId, $topic, $payload, false);
|
||||||
@@ -311,7 +335,9 @@ class MonitoringClient extends IPSModule {
|
|||||||
$isSetpoint = isset($catId["setpoint"]) ? $catId["setpoint"] : false;
|
$isSetpoint = isset($catId["setpoint"]) ? $catId["setpoint"] : false;
|
||||||
|
|
||||||
if ($isSetpoint == true){
|
if ($isSetpoint == true){
|
||||||
|
IPS_LogMessage("Monitoring Client", "Sync Setpoint: " . $topic . " mit Payload: " . $payload. " und Source: " . $childid . " und Ident: " . $syncname);
|
||||||
$this->MqttSync($mqttId, $topic, $payload, false, $parname."_".$varname, $childid);
|
$this->MqttSync($mqttId, $topic, $payload, false, $parname."_".$varname, $childid);
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
if($changedtime > $time - $updatetime){
|
if($changedtime > $time - $updatetime){
|
||||||
$this->MqttPublish($mqttId, $topic, $payload, false);
|
$this->MqttPublish($mqttId, $topic, $payload, false);
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ class MonitoringServer extends IPSModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetValueInteger($this->GetIDForIdent("SetpointVarCount"),$numberofvalues);
|
SetValueInteger($this->GetIDForIdent("AnalogVarCount"),$numberofvalues);
|
||||||
$numberofvalues = 0;
|
$numberofvalues = 0;
|
||||||
|
|
||||||
if ($catSetpointId > 0){
|
if ($catSetpointId > 0){
|
||||||
@@ -367,7 +367,7 @@ class MonitoringServer extends IPSModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetValueInteger($this->GetIDForIdent("AnalogVarCount"),$numberofvalues);
|
SetValueInteger($this->GetIDForIdent("SetpointVarCount"),$numberofvalues);
|
||||||
$numberofvalues = 0;
|
$numberofvalues = 0;
|
||||||
|
|
||||||
if ($catNotifyId > 0){
|
if ($catNotifyId > 0){
|
||||||
|
|||||||
Reference in New Issue
Block a user