# Heartbeat script having effects system wide

**URL:** <https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689>\
**Category:** Ignition\
**Created:** [January 4, 2019, 1:40pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689 "2019-01-04T13:40:19Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dwatkins](https://avatars.discourse-cdn.com/v4/letter/d/9de0a6/32.png) [@dwatkins](https://forum.inductiveautomation.com/u/dwatkins)\
**Post date:** [January 4, 2019, 1:40pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/1 "2019-01-04T13:40:19Z")

</div>

I have four PLCs receiving heartbeats from the Ignition Gateway. They are four Gateway scripts running every second that:

- Count from 1 to 60 and reset to zero.
- Copy that value to an OPC tag.

I have tried a single script, four scripts, changed threading and delay…

The problem is if I unplug the network cable on one PLC, the HBs stop updating for all PLCs until they reconnect. Same thing when I plug back in. I can still ping the devices while the heartbeats stop updating.

\*\* PLCs are four Allen Bradley CompactLogix.

Any help would be appreciated, thanks.

---

<div class="post-metadata">

**Author:** ![jdrichards70](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@jdrichards70](https://forum.inductiveautomation.com/u/jdrichards70)\
**Post date:** [January 10, 2021, 2:20pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/2 "2021-01-10T14:20:33Z")

</div>

I’ve had the same problem for several months now. I updated from 7.9.10 to 7.9.16 to see if that helps, and it didn’t. I have to reboot Ignition to get it working again, helps for abut 2 weeks. Memory and CPU usage is low. Doesn’t matter if it is a tag change, tag event or gateway timer script…they all stop running.

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [January 10, 2021, 2:32pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/3 "2021-01-10T14:32:31Z")

</div>

> [@PLC Fault- Ignition HMI](http://forum.inductiveautomation.com/t/plc-fault-ignition-hmi/23968/2):
>
> Monitor the quality of the tags to pick up connection breakage. Some drivers expose a diagnostic tag you can monitor. Otherwise, you might need a rolling counter or other heartbeat in your PLC that would indicated continued code execution.

Have the HeartBeat **generated** by the PLC and **monitored** by Ignition.

@pturmel

---

<div class="post-metadata">

**Author:** ![BenKearney](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@BenKearney](https://forum.inductiveautomation.com/u/BenKearney)\
**Post date:** [January 10, 2021, 2:33pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/4 "2021-01-10T14:33:22Z")

</div>

> Have the HeartBeat **generated** by the PLC and **monitored** by Ignition.

Isn't the idea here for the PLC to be able to detect loss of connection to Ignition, rather than the other way around?

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [January 10, 2021, 2:35pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/5 "2021-01-10T14:35:16Z")

</div>

Written correctly it will do that too. HandShake as well as HeartBeat.

And the OP said he can still ping. For my largest project with over 100 device instances, I run a periodic ping and record the results to DB, then report a summary every day.

---

<div class="post-metadata">

**Author:** ![BenKearney](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@BenKearney](https://forum.inductiveautomation.com/u/BenKearney)\
**Post date:** [January 10, 2021, 2:35pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/6 "2021-01-10T14:35:51Z")

</div>

How can you detect loss of connection to Ignition using a heartbeat generated inside the PLC?

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [January 10, 2021, 2:37pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/7 "2021-01-10T14:37:02Z")

</div>

e.g. PLC counts to a certain value, once certain value is reached, Ignition resets back to 0.

If not reset within a certain time == comms loss.

---

<div class="post-metadata">

**Author:** ![BenKearney](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@BenKearney](https://forum.inductiveautomation.com/u/BenKearney)\
**Post date:** [January 10, 2021, 2:40pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/8 "2021-01-10T14:40:05Z")

</div>

Hadn’t thought of doing it that way! Unfortunately I rarely have control of my end devices so I probably won’t get too much opportunity to use it ☹

let’s wait to hear from @jdrichards70 to see how they’re trying to achieve this.

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [January 10, 2021, 2:44pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/9 "2021-01-10T14:44:55Z")

</div>

Something to add to the Spec’ for your OEM then 😉

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 10, 2021, 5:15pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/10 "2021-01-10T17:15:55Z")

</div>

> [@Matrix\_Engineering](#):
>
> PLC counts to a certain value, once certain value is reached, Ignition resets back to 0

Eeek! No. Don't write from two directions. PLC should count and roll over. The low word of a PLC clock is fine. Ignition should count and roll over in its own timer event, writing to the appropriate OPC tag. Or write the low bits of Ignition's millisecond time to the OPC tag. It isn't important what the value is, just that it changes regularly.

Neither the OP nor @jdrichards70 shared their actual scripts, so there's no telling what the real problem is. Non-blocking writes should be used to prevent one broken device connection from killing the heartbeats to other device connections.

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [January 10, 2021, 7:23pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/11 "2021-01-10T19:23:02Z")

</div>

That’s why I tagged you I knew you would have me sat-corrected 🙂

My Field IO is generally Moxa IoLogik. I use an E1212 with a hardwired heartbeat Output back to an Input on the same module, with the Output set to pulse at 1000mS.

SCADA monitors/trends/alarms this and combined with my periodic ping mentioned above, I have a good idea of RIO/FIO outages. I know when SCADA is down because my mobile (cell) phone rings shortly after 😛

---

<div class="post-metadata">

**Author:** ![jdrichards70](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@jdrichards70](https://forum.inductiveautomation.com/u/jdrichards70)\
**Post date:** [January 10, 2021, 7:32pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/12 "2021-01-10T19:32:10Z")

</div>

I think it’s more than just my heartbeat issue. Once in a while, the operators will report the barcode scans are taking 30-60 seconds to show up on the HMI or a machine will pause for a bit waiting for something from Ignition. Everything on the network pings \< 1ms while this happens.

script is stupid simple:

x = system.date.getSecond(system.date.now())

system.tag.write(“Corporate/Lincoln/Bay A/Line 4/Proof/Carousel 1/Heartbeat Count”, x)  
system.tag.write(“Corporate/Lincoln/Bay A/Weld/Welder 2020/Welder/Heatbeat Tag”, x)

and I’ve even done this just to see what happens:  
(runs every 2 seconds)  
x = system.tag.read(“Corporate/Lincoln/Bay A/Weld/Welder 2020/Welder/Heatbeat Tag”).value  
x = x + 1  
if x \> 59:  
x = 0  
else:  
pass

system.tag.write(“Corporate/Lincoln/Bay A/Weld/Welder 2020/Welder/Heatbeat Tag”, x)

The OEM will change the code for me if a better way is out there, this is what the programmer wanted, he’s just looking for a change in the value every 10 seconds.

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [January 10, 2021, 7:59pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/13 "2021-01-10T19:59:33Z")

</div>

Please use the Preformatted Text option (\</\> button) when posting scripts and error messages, as that will preserve formatting.

Sounds like you are running code in the foreground (GUI thread). Anything long-running should be in a separate thread (Invoked Async).

---

<div class="post-metadata">

**Author:** ![Kevin.Collins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.collins/32/13497_2.png) [@Kevin.Collins](https://forum.inductiveautomation.com/u/Kevin.Collins)\
**Post date:** [January 10, 2021, 10:04pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/14 "2021-01-10T22:04:19Z")

</div>

> [@Matrix\_Engineering](#):
>
> Sounds like you are running code in the foreground (GUI thread). Anything long-running should be in a separate thread (Invoked Async).

Hopefully @jdrichards70 can confirm that the scripting in question is configured as a Gateway script; agreed that you'd not want this in the client scope. Perhaps confirm your settings for the timer script?

 ![Screen Shot 2021-01-10 at 4.02.41 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/6/46ffb41b2d30d48160f2aa740b50d4682ebee4b7.png)

---

<div class="post-metadata">

**Author:** ![jdrichards](https://avatars.discourse-cdn.com/v4/letter/j/839c29/32.png) [@jdrichards](https://forum.inductiveautomation.com/u/jdrichards)\
**Post date:** [January 11, 2021, 10:00pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/15 "2021-01-11T22:00:28Z")

</div>

@Matrix_Engineering - yes, thank you, I forgot the formatting, doh!. I can try async.

@Kevin.Collins - I tried fixed delay and fixed rate, same results. I am running with dedicated thread right now.

What would the proper or industry standard be for setting up the heartbeat? I usually just use the ‘is connected’ bit with the driver and this is the only machine I have had issues with…Siemens, arg!!! While my heartbeat dies, all the other real time data is coming through, so it’s not like the machine dropped offline or the driver locked up and I can manually change the tag value in a designer.

---

<div class="post-metadata">

**Author:** ![mori.luca](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mori.luca/32/13424_2.png) [@mori.luca](https://forum.inductiveautomation.com/u/mori.luca)\
**Post date:** [October 22, 2021, 7:42pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/16 "2021-10-22T19:42:10Z")

</div>

Hello, I had the same problem today.  
I have 2 OPC server and when I disconnect one, I see the timer script slow down and not writing the heartbeat to the second one.  
(They live in two completely separate timer script)

I receive an error ( I can’t share it at the moment ) in the system log saying that there was an error on the timer script code, even if there is no error.  
The whole timer script is just a write on the tag.

I tested system.tag.write and system.tag.writeBlocking with the same outcome.

Coul I ask you which settings are the best for a simple and reliable heartbeat?

I don’t understand why this is happening even if I select dedicated thread.

I remember fixed delay and fixed rate was bugged, is it still the case?

Thanks

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 22, 2021, 7:56pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/17 "2021-10-22T19:56:16Z")

</div>

There was a bug in the OPC tag execution system that caused breakage on a single connection to hold up all tags on the same pace across all other OPC connections. I don’t recall what version it was fixed, but your case sounds suspiciously similar. What Ignition version are you using?

---

<div class="post-metadata">

**Author:** ![mori.luca](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mori.luca/32/13424_2.png) [@mori.luca](https://forum.inductiveautomation.com/u/mori.luca)\
**Post date:** [October 23, 2021, 12:03pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/18 "2021-10-23T12:03:25Z")

</div>

I will post the gateway and errors details on Monday as soon I will have a remote connection with the server.  
The version is the 8.x.x.  
One thing I’d like to understand is how scripts are managed.  
For example, let’s assume we have this scenario:

2 plc tags with one script each, when the value change (udt tags with event change script):

- A writeblock writing 2 booleans to PLC, resetting the request bit and setting an ack
- an opc.read to retrieve the state of few tags
- store some values on a database
- writeblock to write an integer plus a bool to the plc with the result of the action performed

2 timer script, setting a boolean on the plc as heartbeat.

Now my question is, if for example we are in the situation when the timer script and the tag change event fire at the same time, will they be executed on their own thread or they will share the thread and so be executed one after another (with obvious writeblock time delay) ?

The same question bother me for consequential events being fired at the same time on multiple tag change scripts.  
There is a difference between how ignition treat gateway tag change scripts vs udt tag change? Are they executed on the same thread?  
In case a writeblock goes in timeout due to connection probelm, block all the other script of changing tags?

Would be nice if you can point me out some documentation about it,  
Thankyou

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 23, 2021, 3:38pm UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/19 "2021-10-23T15:38:16Z")

</div>

> [@mori.luca](#):
>
> The version is the 8.x.x

That is not how you answer "What Ignition version are you using?" The rest of the digits matter.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [October 24, 2021, 6:34am UTC](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689/20 "2021-10-24T06:34:31Z")

</div>

Haha, a bit like “what’s your address?” “I’m in Australia”

[Next page](https://forum.inductiveautomation.com/t/heartbeat-script-having-effects-system-wide/21689.md?page=2)
