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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Bind Thing Properties to Stream

drieder
15-Moonstone

Bind Thing Properties to Stream

Hello Everyone,

 

I would like to write a location and state property of my things to a Stream (and then use this Stream to display the Location properties on the Google Maps Widget). The Datashape for the Stream is set accordingly (location and String). 

 

Is there a way to ''bind'' the property Values to this Stream so that I always have the current values when I execute the GetStreamData service of my Stream? I am aware of the AddStreamEntry service but It implies that I would have to write the data manually. Also I would have to add the ThingName as a primary key and take care of how the entries are added to avoid redundancy.

 

PS: Using a ValueStream is not an option for me because I need to get the properties of all my logged things as an Infotable (just like provided by the GetStreamData service)

 

Any help is appreciated very much!

 

Best Regards,

Dominik

1 ACCEPTED SOLUTION

Accepted Solutions

But to build an Infotable with current values (property values not historical values - Stream/ValueStream-) you can just query for property values via ThingShape or ThingTemplate:

 

ThingTemplates["YourThingTemplateNameThatOwnsTheTwoProperties"].GetImplementingThingsWithData() or QueryImplementingThingsWithData()

 

And your are done.

View solution in original post

6 REPLIES 6

Well Actually you can use ValueStream in companion with QueryPropertyHistory or QueryNamedPropertyHistory and it will join state and location.

 

With the Stream you are right, you will have to write down to the Stream manually (with a Value Change subscription or alike)

drieder
15-Moonstone
(To:CarlesColl)

Hello @CarlesColl,

 

thank you for your reply. When trying to QueryPropertyHistory on a valueStream it does not work because the ValueStream does not contain a ValueStream. And I also dont want to query the history of a single Thing, but of many things. 

 

So I am trying to update the entries in a Stream Manually, but now I am facing the following problem:

Every newly added Entry gets an automatically generated ID assigned. I need that ID for the UpdateEntry service.

Unfortunately I can't get this ID when adding a new entry (so I don't know which ID the entry has when it is added).

 

The best way would be if I could define a ID or Primary Key of the Entry (not the Data) by myself. Or is there a way to get the ID of a newly added Entry?

 

Thank you for your help.

 

Best Regards,

Dominik

I don't understand your first statement " on a valueStream it does not work because the ValueStream does not contain a ValueStream". But yes, if you want to query multiple things on the ValueStream approach you will have to do one by one query for each different Thing.

 

On the stream approach you will never have the ID of the created Stream, ValueStream and Stream writes are Asynchronous operations, then it's impossible to have an ID of the created stream entry when you call the AddStreamValue service as the database row won't be create at that exact moment it will be put on a queue. If you can create your own unique IDs (for instance using generateGUID() service, but don't expect to work this data entry on the same service call you added it, remember it's asynchronous (it can be available in few millisecond or seconds...)

 

 

drieder
15-Moonstone
(To:CarlesColl)

This is realy unfortunate. I can not query every Thing, because I need an Infotable with the current property values of the things. With the Value Stream I would have to ''Build'' this table for every call (which I want to avoid).

 

The Stream provides exactly the functionallity I need, but since I can not update the Properties without the ID I will not be able to use it. I will try using a Data Table then

 

 

But to build an Infotable with current values (property values not historical values - Stream/ValueStream-) you can just query for property values via ThingShape or ThingTemplate:

 

ThingTemplates["YourThingTemplateNameThatOwnsTheTwoProperties"].GetImplementingThingsWithData() or QueryImplementingThingsWithData()

 

And your are done.

drieder
15-Moonstone
(To:CarlesColl)

This does work, thank you very much

Top Tags