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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Can't set cacheTime for remote property from Thing Shape

JA_9980354
7-Bedrock

Can't set cacheTime for remote property from Thing Shape

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!

ACCEPTED SOLUTION

Accepted Solutions
Mukul
14-Alexandrite
(To:JA_9980354)

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.

View solution in original post

7 REPLIES 7
Mukul
14-Alexandrite
(To:JA_9980354)

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.

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

 

Mukul
14-Alexandrite
(To:JA_9980354)

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.

Thanks again for the reply! Adding "Cache Method" : "Cached for specific time" in aspects and setting cacheTime in SetRemotePropertyBinding still gave me the NullPointrException error unfortunately. 

 

Changing cacheTime to undefined allowed the properties to be bound with no errors (I guess expected but helps to find root cause). Also noticed setting "Cache Method" in aspects did not change the cache method in the property's setting. Do we have the syntax right for that? I couldn't find any documentation about what you can put in the aspect JSON. 

var aspects = { 
        "tagAddress": propertiesAndAddresses[i+1],
        "scanRate": 500,
        "Cache Method": "Cached for specific time"
    };
    
me.SetRemotePropertyBinding({ 
    propertyName: propertiesAndAddresses[i], // STRING
    aspects: aspects,// JSON
    //cacheTime: undefined //this let script run with no errors 
    cacheTime: 1 //1 second. 
});

JA_9980354_0-1636740823542.png

 

 

Mukul
14-Alexandrite
(To:JA_9980354)

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.

Unfortunately still getting NullPointrException error with your exact code (with my properties) as well. May be on my system side and not the syntax. I will submit a Ticket. 

 

Thank you very much for all the help though! 

I was doing some testing with this today and I discovered that the "cacheTime" integer value is actually mS with a fixed (3) decimals.  So, a one-second Cache Interval would be a "cacheTime" of 1000.  I also noticed that the cacheTime appears to be an enumerated configuration for the Cache Method.  This is what I tested on my end.  Twx ver 9.2.  I didn't end up putting the "Cache Method" in the aspects json.

 

cacheTime of 0 = “Read from server cache”

cacheTime of -1 = “Fetch from remote every read”

cacheTime of [positive integer] = “Cached for specific time”

The positive integer value of “cacheTime” will also be the value shown in the “Cache Interval” property.

Announcements


Top Tags