# Value Change Script Fires When Gateway Loses/Restores Communication

**URL:** <https://forum.inductiveautomation.com/t/value-change-script-fires-when-gateway-loses-restores-communication/73215>\
**Category:** Ignition\
**Tags:** ignition81, scripting, database\
**Created:** [May 3, 2023, 5:22pm UTC](https://forum.inductiveautomation.com/t/value-change-script-fires-when-gateway-loses-restores-communication/73215 "2023-05-03T17:22:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![james4](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james4/32/49597_2.png) [@james4](https://forum.inductiveautomation.com/u/james4)\
**Post date:** [May 3, 2023, 5:22pm UTC](https://forum.inductiveautomation.com/t/value-change-script-fires-when-gateway-loses-restores-communication/73215/1 "2023-05-03T17:22:33Z")

</div>

We are having an issue with a remote location regarding the communication through a VPN tunnel.

What we are finding is any and all "Value Change" scripts that are based on OPC tags changing value are re-triggered upon gateway restoration. This is causing some issues with accurate data logging from the remote site as well as some extra database writes that are not valid.

We are using a basic script:

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):  
system.tag.writeBlocking(["[.]../Recipe Misc/Trigger"], [1])

Until we figure out why the VPN tunnel is not rigid enough for the site is there anyway we could look at the tag data to not allow to fire unless a stable connection is made? We tried using the previous value in the script but it did not work either.

The setup is as follows:

Server + Gateway + Database in Location A

VPN Tunnel to Location B

Location B has the PLC that all OPC tags are being brought from.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 3, 2023, 5:24pm UTC](https://forum.inductiveautomation.com/t/value-change-script-fires-when-gateway-loses-restores-communication/73215/2 "2023-05-03T17:24:44Z")

</div>

> [@james4](#):
>
> We tried using the previous value in the script but it did not work either.

What have you tried so far?

---

<div class="post-metadata">

**Author:** ![james4](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james4/32/49597_2.png) [@james4](https://forum.inductiveautomation.com/u/james4)\
**Post date:** [May 3, 2023, 5:34pm UTC](https://forum.inductiveautomation.com/t/value-change-script-fires-when-gateway-loses-restores-communication/73215/3 "2023-05-03T17:34:22Z")

</div>

We tried:

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):  
if previousValue != currentValue:  
system.tag.writeBlocking(["[.]../Recipe Misc/Trigger"], [1])

But it still fires even though the value did not in fact change.

---

<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:** [May 3, 2023, 5:36pm UTC](https://forum.inductiveautomation.com/t/value-change-script-fires-when-gateway-loses-restores-communication/73215/4 "2023-05-03T17:36:30Z")

</div>

> [@james4](#):
>
> OPC tags are being brought from

This makes me think that you are making an OPC connection through the tunnel to a PLC that has its own OPC server, or to an OPC server in Location B.

But your symptoms sound like you are using a native driver in the gateway in Location A and **polling through the VPN**. If so, then you are unlikely to succeed. PLC branded query-response protocols have no state associated with them, so will always give bad quality when disconnected/interrupted (and will perform dramatically slower than a local connection). You should fix this first, perhaps with a base install of Ignition Edge.

---

<div class="post-metadata">

**Author:** ![james4](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james4/32/49597_2.png) [@james4](https://forum.inductiveautomation.com/u/james4)\
**Post date:** [May 3, 2023, 5:42pm UTC](https://forum.inductiveautomation.com/t/value-change-script-fires-when-gateway-loses-restores-communication/73215/5 "2023-05-03T17:42:00Z")

</div>

You are correct we are polling through the VPN as of right now.

We have a full ignition sever going into Location B but unfortunately that has been a slow process. This was an attempt to get data tracking started with what we have now.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 3, 2023, 5:45pm UTC](https://forum.inductiveautomation.com/t/value-change-script-fires-when-gateway-loses-restores-communication/73215/6 "2023-05-03T17:45:51Z")

</div>

Log the qualified values and see what is going on. I'd expect a quality change, if nothing else, when the connection is lost.

---

<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:** [May 3, 2023, 5:46pm UTC](https://forum.inductiveautomation.com/t/value-change-script-fires-when-gateway-loses-restores-communication/73215/7 "2023-05-03T17:46:56Z")

</div>

If the situation is temporary, I'd not bother expending labor to work around the pathological case. Just clean up the data in batches until the other server is deployed. Perhaps use this information to justify a faster deployment.

---

<div class="post-metadata">

**Author:** ![james4](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james4/32/49597_2.png) [@james4](https://forum.inductiveautomation.com/u/james4)\
**Post date:** [May 3, 2023, 6:03pm UTC](https://forum.inductiveautomation.com/t/value-change-script-fires-when-gateway-loses-restores-communication/73215/8 "2023-05-03T18:03:37Z")

</div>

Thanks for the quick responses, I will log the values to see what they are doing as Kevin mentioned but also going to push this to IT.
