Skip to main content
1-Visitor
August 3, 2017
Question

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

  • August 3, 2017
  • 4 replies
  • 3979 views

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

    4 replies

    1-Visitor
    August 3, 2017

    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.

    19-Tanzanite
    August 3, 2017

    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.

    1-Visitor
    August 3, 2017

    Same for ThingShapes

    akesana1-VisitorAuthor
    1-Visitor
    August 3, 2017

    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?.

    1-Visitor
    August 4, 2017

    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"

           });

    }