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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Multi Event subscription

AliBenBelgacem
14-Alexandrite

Multi Event subscription

Hello all,

 

I have a thing template that implement a remote thing (csdk).

From the csdk i trigger an event. Then i subscribe to this event thingworx side.

In my case, i can have multiple remote things triggering this event simultaneously, and I want to subscribe to these events from another thing. I cannot find a way to do it.

 

Exemple

1 - Thing Template TT implementing the remote thing.

2- thing1, thing2,thing3,thing4 implementing TT and trigger 'event '

3- ThingX need to subscribe to the 'event' triggering simultaneously from thing1, thing2,thing3,thing4

 

Do you have an idea what is the best why to do it ?

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions

I agree with Velkumar, if the rooms store the people count, the HomeThing shouldn't duplicate the data, but just aggregate it, when it is needed.

On the other hand, if you're not interested in the individual room count but just on the total count, then yes, you could subscribe HomeThing to all rooms events and update the global counter.

From your first post my understanding is you have trouble subscribing to the events of another thing.

When you create the subscription, there is a field called Source. There you have to select "Other entity" and select the entity you want to subscribe to. See here

If your question is how to do this programmatically, you can only use Dynamic Subscriptions, but they are not permanent (you can find about this in the community e.g. here)

Also, Thingworx 9.5 brings multi-event subscriptions, where one subscription can listen to multiple events. I am not aware if this can also be set up using API.

View solution in original post

6 REPLIES 6

Hi @AliBenBelgacem 

 

You can create a subscription in Thing Template TT and call the ThingX service inside the subscription. So whenever thing1, thing2, ... thingN event triggered, service from ThingX will be triggered.

 

/VR

AliBenBelgacem
14-Alexandrite
(To:Velkumar)

Hi,

Thank you for your proposition but this what i already did.

I want to do it the opposite way. in my project the thingX contain thing1, thing2, thing3, thing4.. 

You can see the attached picture to understand better. I want that Home see and pilot room. the room work autonomously, no depending on anything. So in Room thing I should put no reference to Home.

 

Hi @AliBenBelgacem 

 

Could you please explain your use case.

 

Based on the diagram, you can locally bind property from ThingX to Thing1... ThingN in template level.

Velkumar_0-1711702654116.png

So when property gets changed in ThingX it also updates property in other Things. Based on that you can trigger your subscription.

 

/VR

AliBenBelgacem
14-Alexandrite
(To:Velkumar)

Sorry i didn't explain well the case:

 

in my example:

 

In room (Thing template) i want to put a people counter, it counts the number of people in real time in the room. So Room is just a remote thing receiving data from sensors.

Every time the number of persons change in the room, an event is triggered containing updated counter in that specific room.

In home (thing template), i need the total number of persons in all rooms, so i need to catch all the events triggered from all the rooms to update the total counter.

 

Of course, i can update home counter from room subscription, but is it the best solution ? isn't a bad practice that room update home? isn't better that home subscribe to all rooms events so like that all rooms can work autonomously, not depending on other entities ? 

 

 

Hi @AliBenBelgacem 

 

To accumulate people count at the Home level, you have to send data from Rooms to Home. That is the only solution I can think of.

 

But why do you want to store people count at the Home level. Instead, you can calculate the number of people in the room in runtime. It will be a scalable solution. For example : if you want to calculate the number of people in Room1 and Room2 only, you can calculate in runtime and display it.

 

Also if someone leaves the room you need logic to decrease the counter at the Home level. So it will be easier to calculate the total count in runtime (sum all the counts from the rooms when needed in UI or some logic ) instead of storing it at the home level.

 

/VR

 

 

I agree with Velkumar, if the rooms store the people count, the HomeThing shouldn't duplicate the data, but just aggregate it, when it is needed.

On the other hand, if you're not interested in the individual room count but just on the total count, then yes, you could subscribe HomeThing to all rooms events and update the global counter.

From your first post my understanding is you have trouble subscribing to the events of another thing.

When you create the subscription, there is a field called Source. There you have to select "Other entity" and select the entity you want to subscribe to. See here

If your question is how to do this programmatically, you can only use Dynamic Subscriptions, but they are not permanent (you can find about this in the community e.g. here)

Also, Thingworx 9.5 brings multi-event subscriptions, where one subscription can listen to multiple events. I am not aware if this can also be set up using API.

Top Tags