# Connect to an OPC UA server

> Connect to an OPC UA server using Synnax.

The Synnax Driver connects to any [OPC UA](https://opcfoundation.org/) server: PLCs, SCADA systems, DCS, MES, and industrial sensors. Secure and non-secure connections are supported with anonymous, username and password, or certificate authentication.

## Prerequisites

Before you can connect to an OPC UA server, you will need to ensure that you have the following:

1. A [Synnax Core](https://docs.synnaxlabs.com/reference/core/quick-start) running on your network.
2. A [Synnax Driver](https://docs.synnaxlabs.com/reference/driver/get-started) running on your network. This Driver must be connected to the Core and running on the same machine or network as your OPC UA server.
3. The [Synnax Console](https://docs.synnaxlabs.com/reference/console/get-started) installed on your local machine.
4. An OPC UA server running on your network. This server must be reachable by the Driver.

## Supported operating systems

| Platform           | Status      |
| ------------------ | ----------- |
| Windows            | ✓ Supported |
| Linux              | ✓ Supported |
| NI Linux Real-Time | ✓ Supported |
| macOS              | ✓ Supported |
| Docker             | ✓ Supported |

> When running in a Docker container, ensure [the container has network access](https://docs.docker.com/get-started/docker-concepts/running-containers/publishing-ports/) to the OPC UA server.

## Common OPC UA servers

| Server                                                                                                                             | Description                                |
| ---------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
| [open62541](https://open62541.org/)                                                                                                | Open-source OPC UA stack                   |
| [Beckhoff TwinCAT](https://infosys.beckhoff.com/english.php?content=../content/1033/tf6100_tc3_opcua_client/15427857035.html\&id=) | PLC and automation platform                |
| [FactoryTalk](https://www.rockwellautomation.com/en-us/docs/factorytalk-optix/1-00/contents-ditamap/getting-started.html)          | Allen-Bradley FactoryTalk with OPC UA      |
| [Ignition](https://inductiveautomation.com/ignition/modules/ignition-opc-ua)                                                       | SCADA platform with built-in OPC UA server |
| [Siemens S7](https://www.siemens.com/global/en/products/automation/industrial-communication/opc-ua.html)                           | PLCs with OPC UA support                   |
| [Prosys OPC UA Simulation Server](https://prosysopc.com/products/opc-ua-simulation-server/)                                        | For testing and development                |

## Configuration parameters reference

| Parameter            | Type   | Required | Default | Description                                                                                                             |
| -------------------- | ------ | -------- | ------- | ----------------------------------------------------------------------------------------------------------------------- |
| `name`               | string | Yes      | -       | Human-readable server name for identification in Console                                                                |
| `rack`               | string | Yes      | -       | Synnax Driver (rack) key that will connect to the OPC UA server                                                         |
| `endpoint`           | string | Yes      | -       | Server endpoint URL (e.g., `opc.tcp://localhost:4840`)                                                                  |
| `username`           | string | No       | -       | Username for server authentication (optional)                                                                           |
| `password`           | string | No       | -       | Password for server authentication (optional)                                                                           |
| `security_mode`      | string | No       | `None`  | Security mode: `None`, `Sign`, or `SignAndEncrypt`                                                                      |
| `security_policy`    | string | No       | `None`  | Security policy: `None`, `Basic128Rsa15`, `Basic256`, `Basic256Sha256`, `Aes128_Sha256_RsaOaep`, `Aes256_Sha256_RsaPss` |
| `client_cert`        | string | No       | -       | Client certificate for signing/encrypting (required if security policy ≠ `None`)                                        |
| `client_private_key` | string | No       | -       | Client private key for signing/encrypting (required if security policy ≠ `None`)                                        |
| `server_cert`        | string | No       | -       | Trusted server certificate (required if security policy ≠ `None`)                                                       |

Security mode and policy reference

**Security mode:**

* **None** -> No security applied
* **Sign** -> Messages are signed but not encrypted. Provides authentication without confidentiality
* **SignAndEncrypt** -> Messages are signed and encrypted for full authenticity and confidentiality

**Security policy:**

* **None** -> No encryption
* **Basic128Rsa15** -> 128-bit encryption with RSA-15
* **Basic256** -> 256-bit encryption
* **Basic256Sha256** -> 256-bit encryption with SHA-256
* **Aes128\_Sha256\_RsaOaep** -> 128-bit AES with SHA-256 and RSA OAEP
* **Aes256\_Sha256\_RsaPss** -> 256-bit AES with SHA-256 and RSA PSS

## How-to

**Console**

[](https://synnax.nyc3.cdn.digitaloceanspaces.com/docs/device-drivers/opc-ua/connect-server/connect-server-dark.mp4#t=0.001)

**Python**

Connect to OPC UA server

```python
import synnax as sy
from synnax import opcua

# Initialize Synnax client
client = sy.Synnax()

# Retrieve the embedded rack
rack = client.racks.retrieve_embedded_rack()

# Create the OPC UA device
device = opcua.Device(
    endpoint="opc.tcp://localhost:4841/",
    name="My OPC UA Server",
    location="opc.tcp://localhost:4841/",
    rack=rack.key,
)

# Create the device in Synnax
device = client.devices.create(device)

# Or retrieve by location
device = client.devices.retrieve(location="opc.tcp://localhost:4841/")

# Or retrieve by name
device = client.devices.retrieve(name="My OPC UA Server")

print(f"Connected to OPC UA server: {device.name}")
```

Disconnect server

```python
import synnax as sy

# Initialize Synnax client
client = sy.Synnax()

# Retrieve the device by name
device = client.devices.retrieve(
    name="My OPC UA Server",
    ignore_not_found=True
)

if device is not None:
    # Delete the server
    client.devices.delete([device.key])
    print(f"Disconnected OPC UA server: {device.name}")
else:
    print("Server not found")
```
