How to get the time of the last received data for a DataSource?
-
I want to create an overview screen on the dashboard that shows the active state of the systems connected to the server.
What I want to do is show an LED type indicator on the display based on the time from last is more than say 5 mins. This way the operator can see if there is a problem with any unit.
How do I get this time and how do I calculate if this is more than the 5 mins since the last received data?
-
Hi Dave,
I would use the "GET /v1/point-values/{xid}/latest" endpoint. It has a query parameter for a limit of points to return, so you can use 2. Give it a look in swagger! Then,
if( result.length < 2 || Math.abs(result[0].timestamp - result[1].timestamp) < 300000) ledBlinking = true; //Or unhide or what have you
-
I was wondering how I could do this from the webpage but I think I can use an HTTP getter to poll for this and then set a tag that I can then use on the webpage.
I'll give this a try and see how it works. I'll report back so others who need to the same will know if this work.s
-
You can easily get the timestamp of the last value with
{{myPoint.time}}
Maybe check out the examples on /modules/dashboards/web/mdAdmin/#/dashboard/examples/basics/live-values
-
@phildunlap said in How to get the time of the last received data for a DataSource?:
I would use the "GET /v1/point-values/{xid}/latest" endpoint. It has a query parameter for a limit of points to return, so you can use 2. Give it a look in swagger! Then,
I tried this in an HTTP RECEIVER but it returns error 403 when I try to parse this in the data point. Testing in the receiver setup works.
-
@JoelHaggar said in How to get the time of the last received data for a DataSource?:
You can easily get the timestamp of the last value with
{{myPoint.time}}
Maybe check out the examples on /modules/dashboards/web/mdAdmin/#/dashboard/examples/basics/live-values
That might work if I could compare this to the current time.
-
I'm not the expert on JavaScript here but that should be really easy to do. One thing you could do is have a virtual data point that updates every minute and compare it to the time of that point. One of the other guys can probably post a code example tomorrow.
-
This will work:
<ma-now update-interval="1 SECONDS" output="currentTime"></ma-now> <ma-get-point-value point-xid="YOUR_XID" point="myPoint"></ma-get-point-value> <!-- Show text if there are no recent values --> <span ng-show="(currentTime - myPoint.time) > 300000">No recent value</span> <!-- Switch img src --> <img ng-src="(currentTime - myPoint.time) > 300000 ? 'bad.png' : 'ok.png'">
-
I tried the following but the image doesn't show
<ma-now update-interval="1 SECONDS" output="currentTime"></ma-now> <ma-get-point-value point-xid="DP_799565" point="mywatchdog"></ma-get-point-value> Data State: - <img ng-src="img/ligthbulb_on.png"> <img ng-src="(currentTime - mywatchdog.time > 300000) ? 'img/ligthbulb_off.png' : 'img/ligthbulb_on.png'">
I used the first one to make sure the image would show and it does but the line you gave me (last line) shows a missing image
-
Check the position of your brackets in the expression.
-
Same result. No image displayed
<img ng-src="(currentTime - mywatchdog.time) > 300000 ? 'img/ligthbulb_off.png' : 'img/ligthbulb_on.png'">
-
I think I got it to work. I won't know until the data starts to come in again. Needed the dual curly brackets :)
<img ng-src="{{(currentTime - mywatchdog.time) > 300000 ? 'img/ligthbulb_off.png' : 'img/ligthbulb_on.png'}}">