Skip to main content
1-Visitor
December 13, 2020
Solved

Bind property tags programatically

  • December 13, 2020
  • 2 replies
  • 1545 views

Hi Everyone,

 

I'm trying to write a service that can bind properties in my thing to data in an edge device. here's my code:

 

 

 

// get all properties from the thing
propertyDefs = Things[assetThing].GetPropertyDefinitions({
category: undefined /* STRING */,
type: undefined /* BASETYPENAME */,
dataShape: undefined /* DATASHAPENAME */
});
numberOfProperties = propertyDefs.getRowCount();

var params = {
infoTableName: "PropertiesToAdd" /* STRING */,
dataShapeName: "PropertyNamesForBindings" /* DATASHAPENAME */
};
var allProperties = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

for each(var property in propertyDefs.rows){
// Only add properties starting with "Fan"
if (property.name.substr(0,3) == "Fan"){
var newRow = new Object();
newRow.name = property.name;
newRow.description = "";//property.description;
allProperties.AddRow(newRow);
}
}

// loop through properties, and add source to each property.

sourceNamePrefix = edgeChannelName + "." + edgeDeviceName + "." ;

for each (var prop in allProperties.rows){
Things[assetThing].SetRemotePropertyBinding({
propertyName: prop.name /* STRING */,
sourcePropertyName: sourceNamePrefix+prop.name /* STRING */,
timeout: undefined /* INTEGER */,
pushType: undefined,
pushThreshold: 0.1 /* NUMBER */,
aspects: undefined /* JSON */,
cacheTime: undefined /* INTEGER */,
foldType: undefined
});
}

Things[assetThing].RestartThing();

 

 

 

Before this, I would go to manage bindings tab on the thing and drag and drop the tags in KepserverEX onto the properties in my thing. Using that method shows the tag like in the screenshot below:

 

HaiderZia_0-1607821311683.png

 

However when I run my service, the tag looks like this and doesnt get the data from the edge:

HaiderZia_1-1607821364237.png

 

Any ideas how this can be fixed? The tags are added but the data doesnt come through. 

Thanks.

 

Best answer by anarwal

Hi @HaiderZia , This article will help https://www.ptc.com/en/support/article/CS276903

2 replies

anarwal5-Regular MemberAnswer
5-Regular Member
December 14, 2020

Hi @HaiderZia , This article will help https://www.ptc.com/en/support/article/CS276903

HaiderZia1-VisitorAuthor
1-Visitor
December 22, 2020

Thanks. This helped.

Community Manager
December 22, 2020

Hi @HaiderZia.

 

If the previous response answered your question, please mark it as the Accepted Solution for the benefit of others with the same question.

 

Regards.

 

--Sharon