Heartbeat Signal in Perspective

I have an OPC heartbeta tag that I want to monitor, and display status OK or NOT OK accordingly, based on whether I receive true from the tag after 30 seconds or not. Is there a way to monitor the tag value and using some time function add a script binding with mapping?
Example case:
if (time after 30 secs):
if (heartbeat) == true:
text = OK
else:
text = False

Please see Wiki - how to post code on this forum.

Create an expression tag to monitor the heartbeta(!) tag.

{[~]heartbeat}
&& 
(now() - {[~]heartbeat.Timestamp} > 30000)

I would monitor the tag's timestamp for being within the last 30 seconds.

1 Like

Yes, but is there a function for getting the timestamp? .Timestamp doesnt seem to be working. Do i also enable history on the heartbeat signal?

Ok i did get somewhere but I dont understand how to utilize the property. The timestamp returns the exact date and time, and I just need to monitor the seconds. This is what the subtraction is giving me, I dont understand how to make use of it:


Timestamp returns:

Now returns:

Did you try what I suggested? It will return true if the timestamp is older than 30,000 ms (30 s).
That's what you asked for, but I don't think that's what you want.

@sfatimazahrak what is your current objective? Try explaining it so we can try to help you

(post deleted by author)

I did, but the timestamp being returned is way larger, which is why Im confused. What im trying to do is monitor the value of the tag (RM_VLD_LLM), its a heartbeat signal sending a 1 after every 30 secs. I want to use that to display the status of the signal as text, i.e if heartbeat gives me 1 after 30 secs I want to display OK, otherwise i want to display FAULT. The condition needs to monitor the tag for every 30 secs, I have enabled history on the tag and given it a sampling rate of 30 secs.
Essentially, every 30 secs I wanna check for a heartbeat and display the status accordingly.

I did, but the timestamp being returned is way larger, which is why I'm confused.

A tag timestamp is the number of milliseconds since 1970-01-01 00:00:00, the dawn of Unix time. The timestamp for today will be a large number.

What im trying to do is monitor the value of the tag (RM_VLD_LLM), its a heartbeat signal sending a 1 after every 30 secs.

What you should be doing is sending an alternating 0 - 1 - 0 - 1 ... signal, changing every 30 s.

I want to use that to display the status of the signal as text, i.e if heartbeat gives me 1 after 30 secs I want to display OK, otherwise i want to display FAULT.

No, what you want is that if the tag timestamp is less than 30 s old you want the monitor tag to go true, else false.

The condition needs to monitor the tag for every 30 secs,

No, it needs to monitor continuously - probably at the default rate of 1000 ms.

I have enabled history on the tag and given it a sampling rate of 30 secs.

History is for recording history. You're not interested in history. You're interested in now. Disable the history.

Essentially, every 30 secs I wanna check for a heartbeat and display the status accordingly.

Create an expression tag, say heartbeatGood, to monitor the heartbeat tag.
Set the expression to,

(now() - {[~]heartbeat.Timestamp}) < 30000

This tag will now turn true if the last heartbeat change was within the last 30 s and false if it doesn't change for more than 30 s.

On the label component text property create an expression binding:
if({[~]heartbeatGood, 'OK', 'FAULT')

1 Like

Is this tag coming from an external OPC server, like one built-in to a PLC? If so, that device's clock is the source of the timestamp, and if wrong, it will be broken.

1 Like

The number is elapsed time in milliseconds. Between your two screenshots there is 1hour 19min and 7 sec difference between the timestamps. That's 4,747,000 total milliseconds, which is close to what you got by a couple of minutes. Just take the result and divide by 1000 if you want it in seconds.