# system.opc.setServerEnabled of a remote OPC Server

**URL:** <https://forum.inductiveautomation.com/t/system-opc-setserverenabled-of-a-remote-opc-server/97601>\
**Category:** Ignition\
**Created:** [October 22, 2024, 12:45pm UTC](https://forum.inductiveautomation.com/t/system-opc-setserverenabled-of-a-remote-opc-server/97601 "2024-10-22T12:45:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshdunstan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/joshdunstan/32/43306_2.png) [@joshdunstan](https://forum.inductiveautomation.com/u/joshdunstan)\
**Post date:** [October 22, 2024, 12:45pm UTC](https://forum.inductiveautomation.com/t/system-opc-setserverenabled-of-a-remote-opc-server/97601/1 "2024-10-22T12:45:50Z")

</div>

Have an instance where I need to disable/enable an opc connection on a remote gateway, I assume I'd need to do something other than use the system.opc.setServerEnabled() system function? The remote gateway is back end only, opcua, tag historian and alarm notification.

---

<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:** [October 22, 2024, 12:50pm UTC](https://forum.inductiveautomation.com/t/system-opc-setserverenabled-of-a-remote-opc-server/97601/2 "2024-10-22T12:50:09Z")

</div>

Set up a message handler on the remote server and then use system.util.sendMessage to send it a message telling it to enable or disable the connection.

---

<div class="post-metadata">

**Author:** ![joshdunstan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/joshdunstan/32/43306_2.png) [@joshdunstan](https://forum.inductiveautomation.com/u/joshdunstan)\
**Post date:** [October 23, 2024, 8:38am UTC](https://forum.inductiveautomation.com/t/system-opc-setserverenabled-of-a-remote-opc-server/97601/3 "2024-10-23T08:38:47Z")

</div>

Thanks Kevin, works great.

For those playing at home, even though it's quite trivial:

Gateway Event Script - Message - "ResetOpcConnection":

```python
def handleMessage(payload):
	bExecute = payload['Execute']
	sOpcConnection = payload['OpcConnection']
	if bExecute:
		system.opc.setServerEnabled(sOpcConnection, False)
		system.opc.setServerEnabled(sOpcConnection, True)

```

Then running, in my case, on a change script on a one shot button value, so I can include the ever impotant "Are You Sure?":

```python
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if currentValue.value == 1:
		project = self.view.params.opcReset.ignitionProject
		messageHandler = 'ResetOpcConnection'
		payload = { 'Execute': True,
					'OpcConnection': self.view.params.opcReset.opcConnection }
		scope = 'G' #gateway
		remoteServers = [self.view.params.opcReset.ignitionServer]
		system.util.sendMessage(project, messageHandler, payload, scope = scope, remoteServers = remoteServers )
	self.props.value = 0

```
