Connect to an OPC UA Server
Connect to an OPC UA server using Synnax.
Prerequisites
Before you can connect to an OPC UA server, you will need to ensure that you have the following:
- A Synnax Core running on your network.
- A Synnax Driver 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.
- The Synnax Console installed on your local machine.
- An OPC UA server running on your network. This server must be reachable by the Driver.
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, Aes128Sha256RsaOaep, Aes256Sha256RsaPss |
client_certificate | 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_certificate | string | No | - | Trusted server certificate (required if security policy ≠ None) |
Security Mode & 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
- Aes128Sha256RsaOaep: 128-bit AES with SHA-256 and RSA OAEP
- Aes256Sha256RsaPss: 256-bit AES with SHA-256 and RSA PSS
How-To
Connect to OPC UA Server
import synnax as sy
from synnax.hardware import opcua
# Initialize Synnax client
client = sy.Synnax()
# Retrieve the embedded rack
rack = client.hardware.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.hardware.devices.create(device)
# Or retrieve by location
device = client.hardware.devices.retrieve(location="opc.tcp://localhost:4841/")
# Or retrieve by name
device = client.hardware.devices.retrieve(name="My OPC UA Server")
print(f"Connected to OPC UA server: {device.name}") Disconnect server
import synnax as sy
# Initialize Synnax client
client = sy.Synnax()
# Retrieve the device by name
device = client.hardware.devices.retrieve(
name="My OPC UA Server",
ignore_not_found=True
)
if device is not None:
# Delete the server
client.hardware.devices.delete([device.key])
print(f"Disconnected OPC UA server: {device.name}")
else:
print("Server not found")