Hi,
We Thingworx v9.7 in a SaaS environment, and we have a few hundredth things based on different templates, most of these template based on the RemoteThing Base template.
I'm working on a specific Thing Shape that will be implemented in a bunch of those things or on the templates. I would like to launch a initialization service from a subscription when the isConnected property from the RemoteThing changes state. The issue is that from the Thing Shape, I can't set the event trigger for the subscription on DataChange for isConnected. Is there a work around possible, or maybe another way to call a service on the thing Shape level, when the connection is restored for the Things where the Thing Shape is used?
I guess there is a way to duplicate the RemoteThing base template and add the subscription there, but that would also mean recreating all templates, so I'd like to avoid that solution.
Many thanks in advance,
H.
Solved! Go to Solution.
I don't see a way around it.
You can ease the process when you create a "MyRemoteThing" (choose any name you like) base template inheriting from RemoteThing (as you wrote), then export the templates to entity XML and replace "RemoteThing" with "MyRemoteThing" and then re-import the XML. (try this on a test system first). As any model change on a template, this will cause the entities based on the template to restart.
As a learning, base your entity hierarchy always from your own master template, which you have edit control over.
Hi,
You don't have to duplicate RemoteThing, just create a new template that inherits from RemoteThing. Then you can achieve anything you want on isConnected directly on your new ThingTemplate.
If you want to do something on isConnected directly on the shape, it sounds complicated ... You can create the service on ThingShape and call this service in a subscription at ThingTemplate level. You just have to check that your current object has the shape on him.
Best Regards,
Guillaume
Hi Guillaume,
Thanks for the replay. I did consider this but this would mean that I'd have to add this to each current and future template with the risk of forgetting some, that's why I would like to add it on the thing shape.
Best regards,
H.
I don't see a way around it.
You can ease the process when you create a "MyRemoteThing" (choose any name you like) base template inheriting from RemoteThing (as you wrote), then export the templates to entity XML and replace "RemoteThing" with "MyRemoteThing" and then re-import the XML. (try this on a test system first). As any model change on a template, this will cause the entities based on the template to restart.
As a learning, base your entity hierarchy always from your own master template, which you have edit control over.
Hi Rocko,
good idea, I might try that out. Thanks for the tip as well, I see now how this can be a benefit having full control over your base templates.
H.
Hello,
The best would be to create a common template like MyRemoteThing, as @Rocko and @H0610 suggested.
Alternatively, you can do one of the following:
This is just to fuel your imagination, if anything. Don't do it in a real app!
/ Constantine
Hi Constantine,
1. That's a great idea, I tried it out, yes the new property is taken over in the subscription but it seems that Thingworx automatically disables the subscription during the import. Enabling the subscription after the import is not working because it's throwing an error on the not existing property when saving the thing shape.
2. not such a fan of this since it will be launched with all property changes like you mention.
BR.
H.
Yeah, I didn't test (1), just saw that it allowed to add a subscription... Well, seems like you can only hack it that far
Hi @H0610,
It appears that a response to this post answers your question. For the benefit of other Community Members who may have the same question, it would be great if you could designate it as the Accepted Solution.
In the event that this response did not answer your question, please post your current status so that we can continue to support.
Thanks for using the PTC Community!
Regards,
As the "isConnected" property is defined on a different TS, your TS does not know about it. So yes, you cannot subscribe to it.
To workaround this you can add a ThingStart subscription to your TS and in this subscription you can dynamically add a subscription to isConnected property:
// the ThingStart subscription code:
// todo maybe check if thing has property isConnected / is derived from RemoteThing to prevent errors before subscribing
me.AddDynamicSubscription({
propertyName: "isConnected" /* STRING */ ,
eventName: "DataChange" /* STRING */ ,
thingName: me.name /* THINGNAME */ ,
serviceName: "IsConnectedDataChangeTriggered" /* STRING */
});
// calls service "IsConnectedDataChangeTriggered" when the property changes. define service in TS. service can have normal parameters a normal subscription will have (eventData, source, sourceProperty)
To be honest I did not yet do this for isConnected but for other properties. I could imagine that it might not trigger 100% of the time as e.g. the subscription is added after isConnected has changed.
But I'm not clear if this can happen (but I assume so?). Depending on what you do in the subscription u can call it manually in the ThingStart subscription - so it is triggered for sure (but this might create logic errors when the subscription also triggers)?. Might want to check if it even happens before applying such changes.
Good idea @nmutter . However, I had to solve this problem another way since isConnected isn't changing status after all when the connection the PLC' is lost / restored, it seems it remains true because the connection to Kepware still exists.