cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Set Cache Method of remote thing via service

Highlighted
Regular Member

Set Cache Method of remote thing via service

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?

 

 

4 REPLIES 4

Re: Set Cache Method of remote thing via service

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

Re: Set Cache Method of remote thing via service

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.

Re: Set Cache Method of remote thing via service

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?

Re: Set Cache Method of remote thing via service

That script works fine as long as the Thing (whose properties I am trying to bind to remote) does not come from a Thing Template. I therefore believe I need to fix this at Template level.

 

When defining the properties in the template, maybe there is something I can do with the remoteBindingAspects:

m=me.PressProps.length;
for (i=0;i<m;i++){
    
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);
}

When I run that script, all properties are correctly added to the template, but the cacheTime option is ignored. Maybe I should specify it somehow in a different way?