Add Setpoint category support in Monitoring Client and Server; update library version to 3.0
This commit is contained in:
@@ -4,6 +4,8 @@
|
|||||||
{ "type": "SelectCategory", "name": "ParseNotifyCategoryID", "caption": "Notify Target ID" },
|
{ "type": "SelectCategory", "name": "ParseNotifyCategoryID", "caption": "Notify Target ID" },
|
||||||
{ "type": "SelectCategory", "name": "ParseAlarmCategoryID", "caption": "Alarm Target ID" },
|
{ "type": "SelectCategory", "name": "ParseAlarmCategoryID", "caption": "Alarm Target ID" },
|
||||||
{ "type": "SelectCategory", "name": "ParseAnalogCategoryID", "caption": "Analog Target ID" },
|
{ "type": "SelectCategory", "name": "ParseAnalogCategoryID", "caption": "Analog Target ID" },
|
||||||
|
{ "type": "SelectCategory", "name": "ParseSetpointCategoryID", "caption": "Setpoint Target ID" },
|
||||||
|
{ "type": "SelectCategory", "name": "ParseSetpointCacheCategoryID", "caption": "Setpoint Cache Target ID" },
|
||||||
|
|
||||||
{ "type": "SelectObject", "name": "MqttCLientID", "caption": "MQTT-Client" },
|
{ "type": "SelectObject", "name": "MqttCLientID", "caption": "MQTT-Client" },
|
||||||
{ "type": "NumberSpinner", "name": "Projectyear", "caption": "Projectyear" },
|
{ "type": "NumberSpinner", "name": "Projectyear", "caption": "Projectyear" },
|
||||||
|
|||||||
+120
-16
@@ -9,6 +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("ParseSetpointCacheCategoryID","0");
|
||||||
|
|
||||||
$this->RegisterPropertyInteger("MqttCLientID","0");
|
$this->RegisterPropertyInteger("MqttCLientID","0");
|
||||||
$this->RegisterPropertyInteger("Projectnumber","230001");
|
$this->RegisterPropertyInteger("Projectnumber","230001");
|
||||||
@@ -120,6 +122,96 @@ class MonitoringClient extends IPSModule {
|
|||||||
return true;
|
return true;
|
||||||
} // MQTT_Publish
|
} // MQTT_Publish
|
||||||
|
|
||||||
|
public function MqttSync($server_id, $topic, $payload, $retain, $ident, $source) {
|
||||||
|
|
||||||
|
$cacheCat = $this->ReadPropertyInteger("ParseSetpointCacheCategoryID");
|
||||||
|
|
||||||
|
// ensure server instance exists
|
||||||
|
if(!IPS_InstanceExists($server_id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// determine data type
|
||||||
|
if(is_string($payload)) {
|
||||||
|
|
||||||
|
$ips_var_type = 3;
|
||||||
|
} else if(is_float($payload)) {
|
||||||
|
$ips_var_type = 2;
|
||||||
|
} else if(is_int($payload)) {
|
||||||
|
$ips_var_type = 1;
|
||||||
|
} else if(is_bool($payload)) {
|
||||||
|
$ips_var_type = 0;
|
||||||
|
} else { // unsupported
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$module_id = "{01C00ADD-D04E-452E-B66A-D253278743FE}" /* Module ID of MQTT Server Device */;
|
||||||
|
|
||||||
|
// get temporary MQTT Server Device or create if needed
|
||||||
|
$id = @IPS_GetObjectIDByIdent($ident, $cacheCat);
|
||||||
|
if($id === false) {
|
||||||
|
$id = @IPS_CreateInstance($module_id);
|
||||||
|
if($id === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
IPS_SetParent($id, $cacheCat);
|
||||||
|
IPS_SetIdent($id, $ident);
|
||||||
|
// name object to help with debugging
|
||||||
|
IPS_SetName($id, "CS_" . $name);
|
||||||
|
|
||||||
|
// configure temporary device
|
||||||
|
$config_arr = array(
|
||||||
|
"Retain" => $retain,
|
||||||
|
"Topic" => $topic,
|
||||||
|
"Type" => $ips_var_type
|
||||||
|
);
|
||||||
|
|
||||||
|
$config_str = json_encode($config_arr);
|
||||||
|
IPS_SetConfiguration($id, $config_str);
|
||||||
|
IPS_ApplyChanges($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure the specified server instance is actually compatible
|
||||||
|
if(!IPS_IsInstanceCompatible($id, $server_id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$inst_config = IPS_GetInstance($id);
|
||||||
|
if($inst_config["ConnectionID"] != $server_id) {
|
||||||
|
IPS_DisconnectInstance($id);
|
||||||
|
if(!@IPS_ConnectInstance($id, $server_id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$valSelf = $this->GetValue($id);
|
||||||
|
$valSource = $this->GetValue($source);
|
||||||
|
|
||||||
|
$varInfoSelf = IPS_GetVariable($id);
|
||||||
|
$changedtimeSelf = $varInfoSelf["VariableChanged"];
|
||||||
|
|
||||||
|
$varInfoSource = IPS_GetVariable($source);
|
||||||
|
$changedtimeSource = $varInfoSource["VariableChanged"];
|
||||||
|
|
||||||
|
if($valSelf != $valSource) {
|
||||||
|
|
||||||
|
//self is newer than source, so update source with self value
|
||||||
|
if ($changedtimeSelf > $changedtimeSource) {
|
||||||
|
RequestAction($source, $valSelf);
|
||||||
|
}
|
||||||
|
|
||||||
|
//source is newer than self, so update self with source value
|
||||||
|
if ($changedtimeSource > $changedtimeSelf) {
|
||||||
|
RequestAction($id, $valSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} // MQTT_Sync
|
||||||
|
|
||||||
public function SendTopic() {
|
public function SendTopic() {
|
||||||
|
|
||||||
$mqttId = $this->ReadPropertyInteger("MqttCLientID");
|
$mqttId = $this->ReadPropertyInteger("MqttCLientID");
|
||||||
@@ -135,7 +227,9 @@ class MonitoringClient extends IPSModule {
|
|||||||
$catIds[1]["top"] = "Projekte". $projectyear."/P".$projectnumber. "/ISP" .$ispnumber. "/Alarm/";
|
$catIds[1]["top"] = "Projekte". $projectyear."/P".$projectnumber. "/ISP" .$ispnumber. "/Alarm/";
|
||||||
$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[3]["id"] = $this->ReadPropertyInteger("ParseSetpointCategoryID");
|
||||||
|
$catIds[3]["top"] = "Projekte". $projectyear."/P".$projectnumber. "/ISP" .$ispnumber. "/Setpoint/";
|
||||||
|
$catIds[3]["setpoint"] = true;
|
||||||
|
|
||||||
|
|
||||||
foreach ($catIds as $catId){
|
foreach ($catIds as $catId){
|
||||||
@@ -152,8 +246,6 @@ class MonitoringClient extends IPSModule {
|
|||||||
|
|
||||||
foreach ($childids as $childid){
|
foreach ($childids as $childid){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach ($childids as $childid){
|
foreach ($childids as $childid){
|
||||||
if (IPS_VariableExists($childid) != 1){
|
if (IPS_VariableExists($childid) != 1){
|
||||||
|
|
||||||
@@ -171,10 +263,16 @@ class MonitoringClient extends IPSModule {
|
|||||||
$topic = $catId["top"]. $parname."_".$varname;
|
$topic = $catId["top"]. $parname."_".$varname;
|
||||||
$payload = round(getvalue($childid), 2);
|
$payload = round(getvalue($childid), 2);
|
||||||
$time = time();
|
$time = time();
|
||||||
if($changedtime > $time - $updatetime){
|
|
||||||
$this->MqttPublish($mqttId, $topic, $payload, false);
|
$isSetpoint = isset($catId["setpoint"]) ? $catId["setpoint"] : false;
|
||||||
|
|
||||||
|
if ($isSetpoint == true){
|
||||||
|
$this->MqttSync($mqttId, $topic, $payload, false, $parname."_".$varname, $childid);
|
||||||
|
}else{
|
||||||
|
if($changedtime > $time - $updatetime){
|
||||||
|
$this->MqttPublish($mqttId, $topic, $payload, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// IPS_LogMessage("Monitoring Client", "Force Update with Parent: " . $topic . " mit Payload: " . $payload);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,16 +289,22 @@ class MonitoringClient extends IPSModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$varInfo = IPS_GetVariable($childid);
|
$varInfo = IPS_GetVariable($childid);
|
||||||
$changedtime = $varInfo["VariableChanged"];
|
$changedtime = $varInfo["VariableChanged"];
|
||||||
$varname = IPS_GetName($childid);
|
$varname = IPS_GetName($childid);
|
||||||
$topic = $catId["top"].$varname;
|
$topic = $catId["top"]. $parname."_".$varname;
|
||||||
$payload = round(getvalue($childid), 2);
|
$payload = round(getvalue($childid), 2);
|
||||||
$time = time();
|
$time = time();
|
||||||
if($changedtime > $time - $updatetime){
|
|
||||||
$this->MqttPublish($mqttId, $topic, $payload, false);
|
$isSetpoint = isset($catId["setpoint"]) ? $catId["setpoint"] : false;
|
||||||
}
|
|
||||||
// IPS_LogMessage("Monitoring Client", "Force Update none Parent: " . $topic . " mit Payload: " . $payload);
|
if ($isSetpoint == true){
|
||||||
|
$this->MqttSync($mqttId, $topic, $payload, false, $parname."_".$varname, $childid);
|
||||||
|
}else{
|
||||||
|
if($changedtime > $time - $updatetime){
|
||||||
|
$this->MqttPublish($mqttId, $topic, $payload, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
{ "type": "SelectCategory", "name": "ParseNotifyCategoryID", "caption": "Digital-Objects Target ID" },
|
{ "type": "SelectCategory", "name": "ParseNotifyCategoryID", "caption": "Digital-Objects Target ID" },
|
||||||
{ "type": "SelectCategory", "name": "ParseAlarmCategoryID", "caption": "Alarm-Objects Target ID" },
|
{ "type": "SelectCategory", "name": "ParseAlarmCategoryID", "caption": "Alarm-Objects Target ID" },
|
||||||
{ "type": "SelectCategory", "name": "ParseAnalogCategoryID", "caption": "Analog-Objects Target ID" },
|
{ "type": "SelectCategory", "name": "ParseAnalogCategoryID", "caption": "Analog-Objects Target ID" },
|
||||||
|
{ "type": "SelectCategory", "name": "ParseSetpointCategoryID", "caption": "Setpoint-Objects Target ID" },
|
||||||
|
|
||||||
{ "type": "NumberSpinner", "name": "Projectnumber", "caption": "Projectnumber without leading P Character" },
|
{ "type": "NumberSpinner", "name": "Projectnumber", "caption": "Projectnumber without leading P Character" },
|
||||||
{ "type": "ValidationTextBox", "name": "Projectname", "caption": "Projectname" },
|
{ "type": "ValidationTextBox", "name": "Projectname", "caption": "Projectname" },
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ class MonitoringServer 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("ISP",1);
|
$this->RegisterPropertyInteger("ISP",1);
|
||||||
$this->RegisterPropertyInteger("SqlId",28137);
|
$this->RegisterPropertyInteger("SqlId",28137);
|
||||||
@@ -71,6 +72,9 @@ class MonitoringServer extends IPSModule {
|
|||||||
$this->RegisterVariableInteger("DigitalVarCount", "Number of DigitalValues", "", 3);
|
$this->RegisterVariableInteger("DigitalVarCount", "Number of DigitalValues", "", 3);
|
||||||
$this->RegisterAttributeInteger("DigitalVarCountOld", 0);
|
$this->RegisterAttributeInteger("DigitalVarCountOld", 0);
|
||||||
|
|
||||||
|
$this->RegisterVariableInteger("SetpointVarCount", "Number of SetpointValues", "", 4);
|
||||||
|
$this->RegisterAttributeInteger("SetpointVarCountOld", 0);
|
||||||
|
|
||||||
$this->RegisterVariableString("Alarmtable", "Alarmhistorie", "~HTMLBox", 30);
|
$this->RegisterVariableString("Alarmtable", "Alarmhistorie", "~HTMLBox", 30);
|
||||||
$this->RegisterAttributeString("AtAlarmtable", "");
|
$this->RegisterAttributeString("AtAlarmtable", "");
|
||||||
|
|
||||||
@@ -239,6 +243,14 @@ class MonitoringServer extends IPSModule {
|
|||||||
$this->clearNames();
|
$this->clearNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$actSetpointCount = GetValueInteger($this->GetIDForIdent("SetpointVarCount"));
|
||||||
|
$oldSetpointCount = $this->ReadAttributeInteger("SetpointVarCountOld");
|
||||||
|
if($actSetpointCount <> $oldSetpointCount){
|
||||||
|
$this->WriteAttributeInteger("SetpointVarCountOld", $actSetpointCount);
|
||||||
|
$this->clearNames();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public function checkValues($force) {
|
public function checkValues($force) {
|
||||||
|
|
||||||
@@ -333,9 +345,30 @@ class MonitoringServer extends IPSModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetValueInteger($this->GetIDForIdent("AnalogVarCount"),$numberofvalues);
|
SetValueInteger($this->GetIDForIdent("SetpointVarCount"),$numberofvalues);
|
||||||
$numberofvalues = 0;
|
$numberofvalues = 0;
|
||||||
|
|
||||||
|
if ($catSetpointId > 0){
|
||||||
|
|
||||||
|
$catChilds = IPS_GetChildrenIDs($catSetpointId);
|
||||||
|
|
||||||
|
foreach ($catChilds as $catChild) { //for each object in category
|
||||||
|
|
||||||
|
|
||||||
|
$objchildids = IPS_GetChildrenIDs($catChild); //get variables of objects
|
||||||
|
$parname = IPS_GetName($catChild);
|
||||||
|
|
||||||
|
foreach ($objchildids as $objchildid){
|
||||||
|
|
||||||
|
$numberofvalues++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SetValueInteger($this->GetIDForIdent("AnalogVarCount"),$numberofvalues);
|
||||||
|
$numberofvalues = 0;
|
||||||
|
|
||||||
if ($catNotifyId > 0){
|
if ($catNotifyId > 0){
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
"version": "6.0",
|
"version": "6.0",
|
||||||
"date": 1491343200
|
"date": 1491343200
|
||||||
},
|
},
|
||||||
"version": "2.9",
|
"version": "3.0",
|
||||||
"build": 1,
|
"build": 1,
|
||||||
"date": 0
|
"date": 0
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user