Displaying the latest history timestamp for a data point
-
Heya,
I am stumped with what seems a simple thing: displaying the latest history timestamp for a data point.
A have a MQTT data point whose topic is being updated every 30 secs (ish). However, the value of the data point may only change once a day for example. I have set the data logging of the point to be "When point value changes".
Note: I originally had the data logging set to "timestamp changes", as showed in the history.When I display the timestamp, I get the current value "Aug 14 16:38" which is updated every 30 secs. I get the same behaviour when I display the values returned from ma-point-values. When I added realtime="false", the correct timestamp is displayed but is never updated unless the screen is refreshed.
<ma-calc input="psPCU | filter: {name: 'PCU Accel Event Count'} | maFirst" output="pPCUAccelCnt"></ma-calc> <ma-get-point-value point="pPCUAccelCnt"></ma-get-point-value> *{{pPCUAccelCnt.lastValue()}}* <span>Acceleration Count: <strong><sca-display-na value="{{pPCUAccelCnt.value}}"></sca-display-na></strong></span> <span>Latest Acceleration: <strong><sca-display-na value="{{pPCUAccelCnt.time | maMoment:'format':'MMM D, YYYY h:mm:ss A'}}"></sca-display-na></strong></span> Count ma-point-value: <ma-point-value point="pPCUAccelCnt" display-type="dateTime" date-time-format="LTS"></ma-point-value> Count ma-point-values: <ma-point-values point="pPCUAccelCnt" values="point1Values" latest="1" realtime="false"></ma-point-values> {{point1Values[0].timestamp | maMoment:'format':'MMM D, YYYY h:mm:ss A'}}
As in my example above, I have tried a variety of ways to display the latest history timestamp but without success. I don't want to use the realtime flag either. For a shot, I tried getting the lastValue but I knew it wouldn't work.
I could route the data point through a meta point to capture the timestamp but this is extra complexity for which seems something simple.
Is there something simple I am missing? heh
I encountered this before when displaying the timestamp of a virtual point. I discovered the polling update interval changed the timestamp. Turning the polling off fixed that issue.
Thanks
Ian -
Hi Ian,
To me it sounds like if it were possible to have the
<ma-get-point-value>
tag subscribed to LOGGED events on the websocket instead of UPDATE would get most of what you're looking for, but I don't think that's an option.@Jared-Wiltshire may have a better solution, but I think you could use the on-value-updated function opportunity in the ma-get-point value to requery for the latest 1 from the ma-point-values directive. I can try to flesh that out for you but I'll give others time to chime in, since it seems there'd be a more direct way...
-
Hi Phil,
Good to know I wasn't missing something simple.
I have created a simple component that stores and displays the timestamp only when the value changes:
<ma-point-values point="pPCUAccelCnt" values="point1Values" latest="1" realtime="true"></ma-point-values> <sca-latest-timestamp value="{{point1Values[0].value}}" timestamp="{{point1Values[0].timestamp}}"></sca-latest-timestamp>
Once I get some new test devices (and updated data), I will see if this works. :)
Thanks
Ian -
My notion of the hacky solution looked more like,
<ma-get-point-value ng-init="latestTimeToggle=false; page={};" point-xid="brown" point="myPoint" on-value-updated="latestTimeToggle=!latestTimeToggle;"></ma-get-point-value> <ma-point-values ng-if="!latestTimeToggle" point="myPoint" values="page.point1Values" latest="1" realtime="false" use-cache="false"></ma-point-values> <ma-point-values ng-if="latestTimeToggle" point="myPoint" values="page.point1Values" latest="1" realtime="false" use-cache="false"></ma-point-values> <p> The point name is "{{myPoint.name}}" and its value is {{myPoint.renderedValue}} at {{myPoint.time}} </p> {{page.point1Values}}
But probably the best solution, since you're already writing components / directives, would be to interact with the point value websocket to subscribe to the
LOGGED
event type, and then you could handle any messages of that type to update your component.See the /ui/docs/ng-mango-services/ma-point-event-manager page for how to use the point event manager service to subscribe to the event type in your component. You can see an example of its use in the ma-get-point-value directive, https://github.com/infiniteautomation/ma-dashboards/blob/main/UI/web-src/ngMango/directives/getPointValue.js#L76