Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hi ,everyone,
Now ,I meet one question just as my title describe, I want to change the property to escape the cache effect.
My method is create a Subscription ,when the "isConnected" property change to false,convert other property to zero,but it seems didn't work well,maybe because it has been bind to the machine,anyone has other method ?Please tell me ,thank you .
Solved! Go to Solution.
Hello Xiang,
There is a workaround to achieve your objects. A little bit hacky, but if you really need to reset the value, you can follow those steps:
1. Create additional, normal property on your Remote Thing. On the screenshot below I have two properties: remote (gets data from my Agent) and actual (local property with no remote binding).
2. Create two subscriptions:
a. One on DataChange of your remote property - this subscription should update the value of actual with the value of your remote property:
b. Second on DataChange of isConnected property - this subscription should check if property isConnected is being set to false, if so - should reset the value of actual to 0.
Now all you need to use the property actual, not remote. When the value of remote changes, the value of actual is changed too. If your Agent disconnects, the value is set to 0.
This method is not the most clean solution, however it works.
Hope it helps in your problem.
Regards,
J.
Hello what exactly do you mean by "cache effect"? You should be able to change a property value in response to a data change event on the isConnected property no problem. Have you tried this and you are seeing issues?
yes ,I tried what you said ,but it seems not work well,when the remotething is offline ,it's property value is not turn to zero.
"cache effect " is when the remotething is offline,thingworx record it's online value ,and don't turn it's value to null or zero.
What is the JavaScript in your subscription to isConnected? What ThingWorx version? That should totally work
Xiang, are you looking into resetting a property to zero if your RemoteThing is offline/ not connected?
yes,that's what I need.
You need to configure cache time in order to fix this.
cacheTime — Tells the ThingWorx server how to behave when reading a
remote property. This parameter can take the following values:
○ -1 — Indicates that the VirtualThing always sends its value, and the
server should never request it from the remote application. The value
returned always comes from the in-memory cache of the server. Use this
value for properties that are configured to be pushed to the server.
○ 0 — Indicates that every time the server uses the value, it should request it
from the VirtualThing.
○ Any other positive value — Indicates that the server should cache the
value for that many seconds and then retrieve it from the VirtualThing
only after that time expires. This setting is important for properties that
may be accessed frequently by many users. For example, if 100 users
attempt to access a property value within a 10 second period, you may
want to set this value to 30 seconds. That would ensure that only a single
request for the property is sent to the edge every 30 seconds. However, the
value returned by the platform could be out of date by up to 30 seconds.
This setting is important for properties that may be frequently accessed by
many users. For example, if 100 users attempt to access a property value
within a 10 second period, you may want to set this value to 30 seconds.
That setting would ensure that only a single request for the property is sent
to the edge every 30 seconds. However, the value returned by the Platform
could be out of date by up to 30 seconds
Dear Tori, my subsciption is as follows,besides the subscription,what else should I do?
If the thing is not the Kepware remotething,the subscription works well ,but that didn't useful in my work.
Thingworx Version:7.2.4-b46
Subscription info:
Source :Me
Event: DataChange
Property: isConnected
Enabled: true
inputs/Outputs: null
Snippets:
if(me.isConnected){
}else{
me.measureTemperature = 0;
}
In the Thingworx Monitoring ----Script, Log message is as follows:
Execution error in service script[Remotething is connected.DataChange]:Wrapped java.lang.Exception: Unable to write property...........because thing is not connected.
What are your remote bind settings on the property? There should be a section for those on the thing template or shape where the property is defined under the edit menu for the property.
Is there anything wrong?
Sorry for the delay. Yes, I believe there is an issue. You have the cache option set for "Fetch from Remote Every Read". This means that there is no way to ping this property when the remote device is offline, so setting it to 0 will not benefit you in any way. What are you using this property for that you need to set it to 0? Are you using the EMS or an SDK?
well ,Tori.
you know , we use Thingworx and kepware to monitor factory machine ,if the machine stop running,it's parameter should turn to 0. if the parameter is not 0, it indicate the machine is running.Otherwise,it will make the system user confused.
Hello Xiang,
There is a workaround to achieve your objects. A little bit hacky, but if you really need to reset the value, you can follow those steps:
1. Create additional, normal property on your Remote Thing. On the screenshot below I have two properties: remote (gets data from my Agent) and actual (local property with no remote binding).
2. Create two subscriptions:
a. One on DataChange of your remote property - this subscription should update the value of actual with the value of your remote property:
b. Second on DataChange of isConnected property - this subscription should check if property isConnected is being set to false, if so - should reset the value of actual to 0.
Now all you need to use the property actual, not remote. When the value of remote changes, the value of actual is changed too. If your Agent disconnects, the value is set to 0.
This method is not the most clean solution, however it works.
Hope it helps in your problem.
Regards,
J.
Thanks Mr Jakub, yes, the method you mentioned solved my problem.
I once did another test ,that was ,built another local thing(thing2), bind the thing1(which kepware provided the property value) property to thing2's property(thing2.Conn = thing1.isConnected). When thing1 is offline ,use the thing2's Conn to trigger thing2's other property into 0.But accidentally ,parts of thing2's property would become to 0, and then the thing1's property is not 0,I didn't kown why.