Hello,
I think that this code should be able to work. The only difference would be that you would get rid of the first timer and substitute in your tag reading the heartbeat.
Let me try and explain what I was doing with this too:
- The first Onchange for @heart was used to create a heartbeat so you won’t need that part
- The second Onchange for Counter will create an incrementer that will go up 1 each time that the heartbeat tag changes. There is also another tag in there that I called check. This one takes the value of the counter and subtracts a few from it.
- The Heartbeat function works by taking that value of Check and increments it by 1 each time. This makes it so that if the boolean tag isn’t changing, that the timer will eventually cause the two tags to become equal. If they do become equal from a lack of a heartbeat, it will go into the next function.
- The noconnect function will then send you out an email that lets you know that there is no more connection. You can also increase the amount of time that it takes to send this by either increasing timer2. It’s currently set to every 30 seconds. So with the 30 seconds and the 5 times it would need to go through without seeing a heartbeat it’ll need to be offline for 2 minutes and 30 seconds.
TSET 1,1
REM This uses the first timer and sets it to happen every 1 second
Onchange “test”, “@heart()”
Onchange “tag1”, “@Counter()”
Onchange “Check”,"@noconnect()"
ONTIMER 1,"@test2()"
TSET 2,30
ONTIMER 2, “@HeartBeat()”
REM This code is executed every time the timer begins (every 1 second)
Function test2()
test@ = test@ + 1
IF test@ > 5 THEN
test@ = 0
ENDIF
//print test@ // Seeing if this function worked
Endfn
Function heart()
If test@ < 3 Then
tag1@ = 0
Else
tag1@ = 1
Endif
//Print tag1@ // Seeing if tag1@ is changing
EndFn
Function Counter()
Counter@ = Counter@+1
If Counter@ > 1000 Then
Counter@ = 0
Check@ = Counter@-5
Endif
//Print Counter@ // Checking that it’s counting up after each change
EndFn
Function HeartBeat()
Check@ = Check@ + 1
Print Check@
EndFn
Function noconnect()
If Check@ = Counter@ Then
Sendmail “Person@email.com”, “ccperson@email.com”, “No Heartbeat From Machine”, “”
Print “Mail Sent”
EndFN