Skip to main content
7-Bedrock
November 9, 2021
Solved

Can't set cacheTime for remote property from Thing Shape

  • November 9, 2021
  • 1 reply
  • 2925 views

Some background, we were having some issues with properties connecting that do not change often. We changed the push type of the property to "Always" and this allowed good quality. According to best practices though, we shouldn't do this for many properties. In the same article, it mentions setting the Cache time would pull from the Edge device so we tried this in hopes these properties can pull these static values and connect.

 

Issue: We're having trouble with setting the cache time of a remote property via service. Here's the code, cacheTime grabbed from this article

 

 

 

// properties and addresses from Kepware
propertiesAndAddresses = ["FlowMeterFlowRateAV","S7E_1501_1032.1032.3.DB74,DBW10",.....];

for(var i = 0; i < propertiesAndAddresses.length - 1; i+=2){
 var aspects = { 
 "tagAddress": propertiesAndAddresses[i+1],
 "scanRate": 500
 };

 me.SetRemotePropertyBinding({ 
 propertyName: propertiesAndAddresses[i], // STRING
 aspects: aspects,// JSON
 cacheTime: 1 //1 second
 });
}
me.RestartThing();

 

 

I receive this error when I try to run this script. "Error executing service bindProperties. Message :: Wrapped java.lang.NullPointerException - See Script Error Log for more details."

 

These properties that we are binding are from a Thing Template and Thing Shape. Could this be an issue? Because if we bind these properties without setting the cache method, the cache method box is grayed out. 

JA_9980354_0-1636481724446.png

 

Any thoughts? Thank you!

Best answer by Mukul_467346

I do have a similar use case and it is working fine for me. Below is my tested service code.

 

var a = {
"scanRate":"1500",
"Cache Method":"Cached for specific time",
};
Things["MfgSegment.KepwareThing"].SetRemotePropertyBinding({
propertyName: "LineGroup1-Current" /* STRING */,
pushThreshold: 0 /* NUMBER */,
aspects: a /* JSON */,
foldType: undefined /* STRING */,
sourcePropertyName: "LineGroup1.1-1_CurrentVal" /* STRING */,
timeout: 50 /* INTEGER */,
pushType: "VALUE" /* STRING */,
cacheTime: 1 /* INTEGER */
});

 

Here I am setting tag address "LineGroup1.1-2_CurrentVal to the property LineGroup1-Current having cache method as cache for a specific time and cache time as 1.

1 reply

1-Visitor
November 11, 2021

As per your service code, you are executing the service on the entity itself (me.SetRemotePropertyBinding). Considering your code, I would assume that all the properties exist on the entity itself. If any of the properties do not exist, it can throw a null pointer exception.

7-Bedrock
November 11, 2021

Hi Mukul, 

Thanks for the idea! So I tried this with just one property. Tried it once with the cacheTime in the code and received the null pointer exception. Tried it again with the cacheTime code commented out and property was bound successfully. Must be another reason?

 

// properties and addresses from Kepware
propertiesAndAddresses = ["FlowMeterFlowRateAV","S7E_1501_1032.1032.3.DB74,DBW10"];
...

 me.SetRemotePropertyBinding({ 
 propertyName: propertiesAndAddresses[i], // STRING
 aspects: aspects// JSON
 //cacheTime: 1 //1 second
 });
...

 

JA_9980354_1-1636650060054.png

 

 

 

JA_9980354_0-1636649880345.png

 

1-Visitor
November 12, 2021

can you try to include this line in aspects - "Cache Method":"Cached for specific time". Put this in aspects and set required cacheTime and execute.