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
My device collects state information - a single property value - and sends the collected data in bulk to the server when a connection is available. Each record has start time and end time and the state value that held during that period. When a state change occurs the device generates two records - one that indicates the when the previous state ended and one that indicates when the next state began. What I want is every time the state value changes from A to B I want all three values logged to the ValueStream.
In Thingworx, then, I have an entity that is bound to the device, The entity has 3 properties: LastOEEStartTime, LastOEEEndTime and OEEState all marked IsLogged:true. I defined OEEState with aspect DataChange Value and the other two with DataChange:Never. I thought this would do it.
The results of QueryPropertyHistory show that I am getting a record in the Value stream for every record the device is sending. Why is that?
It seems that I am getting a new entry in the value stream every time the OEEState property is written to whether the value has changed or not. Is this what I should expect?
Solved! Go to Solution.
Hi Andy, just use a Subscription on DataChange for the OEEState and use a regular stream vs. ValueStream
the data you get from the DataChange event is the new and old value, timestamp and quality.
You can use that to use your determination and log the information you want.
Hi Andy,
This result is correct, because you have marked all three properties as Logged. If you just want to display the OEEState, then go to the other two properties and uncheck the Logged checkbox. The timestamp is add to the query of the value stream by default.
If you still want to record your start and end time for each state to the ValueStream, but return a result just with the State (and the timestamp), you can create your own Javascript services that makes a wrapped call to QueryPropertyHistory and then creates a new infotable (that has a data shape just with the state and/or timestamp).
Let me know if you need further clarifications.
Costin
You can just do the specific QueryNamedPropertyHistory or QueryStringPropertyHistory to just recall the one column, and it will give you just that column. Something looks wrong though, I don't see any value changes between the recorded items, did you set the DataChange to Always vs. Value?
What the device is doing is recording the state every 20 seconds whether it changes or not, so the start and end times are changed with every record.
Then if the state value changes, we get a pair of records that gives the time when the previous state ended and the next state began.
What I want to do is "boil" the stream down to just the records where the state value has actually changed.
Thanks, Costin. This makes sense but it is important to understand that the device is acting as a data concentrator/historian. It is accumulating state data all the time but sending to Thingworx only when it is idle and a connection is available. So, depending on when the data is received, the Thingworx timestamp could be minutes, hours or days after the actual time that the state change took place. We need the timestamps recorded by the device to get an accurate, fine grained trace of when the state changes actually took place.
Here is what I really want to have happen ...
As each record from the device is received, I want to compare the new state value to the state value of the last record in the Thingworx repository. If the state value HAS NOT changed, all I really want to do us update the LastOEEEndTime - because the device has remained in the same state for another 20 seconds (or however long). If the state value HAS changed, then I want to add a new record to the repository with the new OEEState, LastOEEStartTime and LastOEEEndTime.
I thought the Value Stream would essentially do this form me. That is, it didn't expect it would update the LastOEEndTime like I want, but it should always have an accurate LastOEEStartTime to mark every change of state.
I suppose I will have to write a custom service to do this filtering on the incoming data values before they hit the ValueStream.
Hi Andy, just use a Subscription on DataChange for the OEEState and use a regular stream vs. ValueStream
the data you get from the DataChange event is the new and old value, timestamp and quality.
You can use that to use your determination and log the information you want.
The key point is that by using Stream instead of ValueStream I have control over when to log, what to log (Stream uses a DataShape), and can use the timestamp generated in the device instead of system time. This brought me to the solution I have now implemented. Thanks.