Skip to main content
Dec 13, 2020 1:04 AM UTC
Solved

Bind property tags programatically

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.

 

anarwalAnswer
Dec 14, 2020 7:38 AM UTC

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

3 replies

anarwalAnswer
Dec 14, 2020 7:38 AM UTC

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

HaiderZiaAuthor
Dec 22, 2020 9:35 PM UTC

Thanks. This helped.

Dec 22, 2020 6:39 PM UTC

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