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

Can I log write subscription based on data change of property of another thing?

Highlighted
Level 1

Can I log write subscription based on data change of property of another thing?

Hi,

I have two things contains same properties, want to call the a subscription on data change of those things properties.

If we write subscription inside things we can call respective on data change event which is fine. But we are looking common subscription which execute on data change of all things.

Is it possible to write common subscription, pass thing name dynamically to it at run time and check on data change property of that ?

Thanks,

Anil Kesana

7 REPLIES 7

Re: Can I log write subscription based on data change of property of another thing?

You mean common code?

If that's the case, you can write a ThingShape which has the Subscription Code, and then just Add Up this ThingShape to the Things which should have the subscription and inside the Subscription just call the ThingShape's Implementing Subscription Service.

Carles.

Re: Can I log write subscription based on data change of property of another thing?

If those things belong to the same template you should define the subscription at the template level.

Then it will apply at any Thing based on that template.

Re: Can I log write subscription based on data change of property of another thing?

Same for ThingShapes

Re: Can I log write subscription based on data change of property of another thing?

That is right, but in our case, we have some properties are thing specific we want to include them as well. If we write subscription template or shape level how can we include thing specific properties?.

Re: Can I log write subscription based on data change of property of another thing?

If you subscribe to ThingStart event ( The problem here it's that you can only have one subscription to ThingStart event from the same thing ) you can check for property existence, and in the case that it exists add up the subscription by code.

if (me["my_thing_level_property_name"]!=undefined) {

     me.AddDynamicSubscription({

               propertyName: "my_thing_level_property_name",

               thingName: undefined,

               eventName: "DataChange",

               serviceName: "mySubscriptionServiceImplementation"

       });

}

Re: Can I log write subscription based on data change of property of another thing?

Hi Anil, can you check the following: if you subscribe to AnyDataChange in a ThingShape, won't it react to the Thing level properties as well?

Re: Can I log write subscription based on data change of property of another thing?

Yes Vladimir this is another option, but you will have the same problem pointed out with ThingStart event, once you subscribed to AnyDataChange you can subscribe to it anymore from another ThingShape/ThingTemplate...