Skip to main content
1-Visitor
September 20, 2019
Question

Set Cache Method of remote thing via service

  • September 20, 2019
  • 1 reply
  • 2385 views

Hi everybody,

 

I am not able to set the Cache Method of a Remote Thing Template created via services.

I am using the AddPropertyDefinition function. Since there is no option to set cacheTime directly, I included it in the remoteBindingAspects option, but I am not sure the syntax is correct or whether I can even do that or not:

 

var remoteAspects={
 cacheTime:-1,
};
var params = {
// defaultValue: undefined /* STRING */,
 remoteBindingAspects: remoteAspects /* JSON */,
// description: undefined /* STRING */,
// readOnly: undefined /* BOOLEAN */,
 type: me.PressProps.rows[i].DataType /* BASETYPENAME */,
 remote: true /* BOOLEAN */,
// remotePropertyName: undefined /* STRING */,
// timeout: undefined /* INTEGER */,
// pushType: undefined /* STRING */,
// dataChangeThreshold: undefined /* NUMBER */,
// logged: undefined /* BOOLEAN */,
 name: me.PressProps.rows[i].PropertyName /* STRING */,
// pushThreshold: undefined /* NUMBER */,
 dataChangeType: "ALWAYS" /* STRING */,
// category: undefined /* STRING */,
// persistent: undefined /* BOOLEAN */,
// dataShape: undefined /* DATASHAPENAME */
 };

result= params;
ThingTemplates["Press_T"].AddPropertyDefinition(params);
}

 

I have also tried to set the cacheTime in the binding service I am using:

var n=me.PressProps.length; //Bind each property name with its source
for (var i=0; i<n; i++) {
 			var CompleteSource = me.PressProps.rows[i].PropertySource_pt1 +'['+PressID+']'+ me.PressProps.rows[i].PropertySource_pt2;
 var aspects = {
 industrialDataType: undefined,
 tagAddress: CompleteSource,
 scanRate: 1000,
 tagType: "Static", 
				};
 
 			Things[PressName].SetRemotePropertyBinding({
 propertyName: me.PressProps.rows[i].PropertyName,
 sourcePropertyName: undefined,
 aspects: aspects,
// cacheTime: -1, //need to enable this from template 
 }); 
 }

This service is working fine when I apply it to Things that are not created through my template, but (this is my explaination) it does not let me override the default value given by my previously created template (cacheTime=0).

 

Any idea on how I could solve this issue?

 

 

1 reply

22-Sapphire I
September 23, 2019

What you are doing should work. If you do this on the Thing Level are you remembering to Restart the Thing?

leoRW1-VisitorAuthor
1-Visitor
September 24, 2019

If I include the "cacheTime=-1" part at Things level I get the following error returned:

"ErrorCode(39beccb4-58cd-4e74-9ece-726f6956263c), Cause(null), Reason(Access was attempted on a null reference variable.), Possible Resolutions(Remove the reference to the null variable within your extension code.)"

 

which I guess it's the same reason why I cannot manually changed certain properties at things level if they are pre-specified in the thing template.

22-Sapphire I
September 24, 2019

Seems to imply that this particular field is not being set in the right object.

is this perhaps inside an Aspects object vs. directly in the binding definition?