Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
I would like to subscribe to an event for a thing template when an instance of a template finishes updating
properties from a remote virtual thing so I can check changed properties including all other existing properties on a thing and use a logical expression to check if I need to do an action: eg. me.temp >27 && me.pressure >100 or me.state === "fault" do something.
I also want to send that all thing's property data (including changed and old once) to a third party sql db for historical and analytical purposes.
So how to subscribe to an event on the server side that correspond to one call to updateSubscribedProperties method on the agent side. It should only be run if there is at least a change in one property.
AnyDataChange will fire multiple times (as many as the number properties that changed) per updateSubscribedProperties method call.
I want to be able to respond to this bulk change or to treat multiple properties changes done via updateSubscribedProperties method as only one event.
Thanks,
Rad
Solved! Go to Solution.
Hi Rad,
Valuestreams can automatically log all changed data for you without you having to do anything. I do recommend you build in addition some offloading and purging mechanism with that (maybe monthly or longer depending on the need and use cases)
If you have a lot of control over the agent, then what I would recommend is to have the agent side only push updated data per cycle and push with that one field that you use to trigger DataChange with. Like you mention the TimeStamp
So I would package a payload that updates all updated properties and the timestamp.
Then based on the VTQ you can determine what properties were actually updated.
Now please note that by using Valuestreams you can already log all updated data automatically, so you won't have to do it for that purpose. But if it is important for you to track 'messages' received and their content, then the DataChange is a way to do it.
Hi Rad, the simplest method I can think off is for the Agent to call or set something that indicates that the updateSubscribedProperties has been called.
Beyond that, I don't think there is any Server side event you can use besides the data changed ones.
I would agree that AnyDataChanged and DataChanged won't quite hit the mark.
A compromise would be to use a Property that changes the most often and do it after that property has changed. (that would cause duplicate writes, although you could try to eliminate some of those by perhaps doing some logic against the VTQ information)
Thanks Pai,
Can you elaborate on "duplicate writes".
What if I have a timestamp for a template and I can check if there are any property changes on the agent side, just before calling updateSubscribedProperties method and, and if there are changes I update this timestamp property and call updateSubscribedProperties again and this time I would expect to have only once property change propagate to the server in which case I can choose to subscribe to DataChange for timestamp property and do processing in that subscription. Of course there will be a small delay but it is fine.
Now remaining question is how to figure out on the agent side if there where any changes in property values.
Do you know what would be that overall flag for a VirtualThing that tells if any change is detected?
Or do you I have to iterate over all the properties to discover if there was a change?
Second. Would that event subscription be the right place to push Thing's property values to an external storage?
There must be a way to transparently push thing's data to somewhere else and allow purging of ValueStream and export that purged data for external use.
Thanks
Hi Rad,
Valuestreams can automatically log all changed data for you without you having to do anything. I do recommend you build in addition some offloading and purging mechanism with that (maybe monthly or longer depending on the need and use cases)
If you have a lot of control over the agent, then what I would recommend is to have the agent side only push updated data per cycle and push with that one field that you use to trigger DataChange with. Like you mention the TimeStamp
So I would package a payload that updates all updated properties and the timestamp.
Then based on the VTQ you can determine what properties were actually updated.
Now please note that by using Valuestreams you can already log all updated data automatically, so you won't have to do it for that purpose. But if it is important for you to track 'messages' received and their content, then the DataChange is a way to do it.