Skip to Content

OPC UA

Open Platform Communications Unified Architecture is a standardized open-source communication protocol that enables seamless and secure data exchange between robot controllers and other systems within a robotic cell. It ensures interoperability across different devices and manufacturers, simplifying the integration, monitoring, and coordination of automation setups in production environments.

In robotic programs, OPC UA is commonly used to perform I/O operations during program execution. This is accomplished by using an OPC UA client that connects to an OPC UA server, which must be network-accessible from NOVA. Python provides functionalities to integrate OPC UA operations into their workflows.

To use Wandelbots NOVA Python SDK in conjunction with an OPC UA server, you need a Python OPC UA client library.

Install asyncua library

The NOVA Python SDK is built upon asyncua, so the structure and methods will be familiar and easier to adapt to. asyncua is a big Python library for OPC UA and thus offers a lot of functionality. Its structure also matches the recommended way of writing Python programs with NOVA.

The NOVA Python SDK offers a convenience wrapper around asyncua to connect to an OPC UA server, reading and writing data, invoking methods, and subscribing to node changes.

Of course, you can also use any other Python OPC UA library if it better suits your requirements.

Connect to OPC UA server

Create a connection to your OPC UA server using the OPCUAClient context manager.

  1. Ensure the OPC UA server is running and accessible via network connection from the NOVA instance.
  2. Provide the server URL, e.g., opc.tcp://192.168.0.100:4840.
    The context manager establishes a connection and automatically handles cleanup.
from nova.extentions.opcua.client import OPCUAClient async def connect_example(): url = "opc.tcp://192.168.0.100:4840" # Replace with your server URL async with OPCUAClient(url) as client: print("Connected to OPC UA server")

Read values from nodes

Read data from specific OPC UA nodes using their node identifiers.

  1. Provide the node ID as a string to the read_node method in the correct server format.

    Node identifier follow the OPC UA specification format, e.g., ns=2;s=Machine.Temperature.

    The method returns the current value of the specified node.
from nova.extentions.opcua.client import OPCUAClient async def read_example(url: str): async with OPCUAClient(url) as client: temperature = await client.read_node("ns=2;s=Machine.Temperature") # Replace with OPC UA server node ID print("Current temperature:", temperature)

Write values to nodes

Send data to OPC UA nodes to control devices or update server values.

  1. Provide the target node ID and the value to write.

    Ensure the value type matches what the server expects, Use appropriate data types, e.g., bool, int, float, string.

from nova.extentions.opcua.client import OPCUAClient async def write_example(url: str): async with OPCUAClient(url) as client: await client.write_node("ns=2;s=Machine.StartButton", True) # Replace with OPC UA server node ID print("Machine start signal sent")

Call server methods

Execute functions or methods defined on the OPC UA server.

  1. Provide the parent node ID and the method node ID.
  2. Pass any required parameters as additional arguments.
    The method returns the result from the server function.
from nova.extentions.opcua.client import OPCUAClient async def call_method_example(url: str): parent_node = "ns=2;s=Machine.Controller" # Node containing the method, replace with OPC UA server node ID method_node = "ns=2;s=Machine.Controller.Reset" # Method to call, replace with OPC UA server method node ID async with OPCUAClient(url) as client: result = await client.call_node(parent_node, method_node, "param1", 42) print("Method result:", result)

Subscribe to node changes

Monitor nodes for value changes and react when specific conditions are met.

  1. Define a condition function that returns True when the subscription should stop.
  2. Use SubscriptionConfig to customize subscription behavior, e.g., printing received messages.

The subscription stops once the condition is met.

from nova.extentions.opcua.client import OPCUAClient, SubscriptionConfig def condition(value): return value == 100 # Stop when value reaches 100 async def subscribe_example(url: str): config = SubscriptionConfig(print_received_messages=True) async with OPCUAClient(url) as client: await client.watch_node_until_condition( key="ns=2;s=Machine.Counter", # Replace with OPC UA server node ID condition=condition, config=config, ) print("Condition met, subscription stopped")

Configure data exchange with config parameter

The Nova Python SDK provides comprehensive configuration parameters for OPC UA data exchange between server and client. These parameters are applied through OPC UA subscriptions, where the server notifies the client about all data changes for the respective nodes. The client can monitor and receive this information in real-time.

For detailed implementation guidance, refer to the official OPC UA documentation on:

Use the official OPC UA documentation to

  1. subscribe to a data exchange  and
  2. monitor data exchanges 

Available config parameters

Available config parameters and their default values are:

ConfigDefault
requested_publishing_interval1000
requested_lifetime_count10000
max_notifications_per_publish1000
priority0
queue_size1
sampling_interval0.0
request_timeout_seconds4
security_config (read more)-

Configuration can be applied completely, partially, or not at all. When not specified, default values are used automatically.

Server response handling

OPC UA servers may modify requested configuration parameters due to their own restrictions. When this occurs, the subscription is created with the server’s revised settings, and you’ll be notified through the logging system. For example, if you request a publishing interval of 1000 ms, the server might enforce a different value based on its capabilities.

The client implementation includes parameter comparison logic that logs any differences between requested and revised subscription parameters

Use NOVA authentication with OPC UA

The Nova OPC UA client supports username and password-based authentication by embedding credentials directly in the connection URL.

The authentication follows the standard OPC UA URL format: opc.tcp://username:password@host:port.

Example: Communicate with a camera

The Python SDK provides functions for comprehensive OPC UA communication with industrial devices like Cognex cameras. The typical workflow includes:

  • Loading jobs onto devices using opcua_call
  • Writing configuration values with opcua_write
  • Triggering operations via method calls
  • Reading multiple values in batches with opcua_read

For complete implementation examples, see the OPC UA functions documentation  in the Python SDK repository.

SSL certificates for secure communication

When establishing OPC UA connections, following OPC UA security best practices is essential.

SSL certificates enable encrypted communication channels and verify the identities of both client and server, ensuring data integrity and confidentiality.

Obtain a certificate

You can obtain certificates through two methods:

There are two ways you can obtain a certificate:

  • CA-signed certificate: Obtain from a Certificate Authority of your choice.
  • Self-signed certificate: Generate using OpenSSL with the command:
    openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
    A self-signed certificate will be generated at the location of the command execution. The generated files key.pem and cert.pem will be used in the next steps.

Upload certificate

The Python SDK uses the SecurityConfig class to manage certificate-based authentication client. The security configuration supports four parameters:

  • security_policy: Specifies encryption algorithms (Basic128Rsa15, Basic256, Basic256Sha256)
  • message_security_mode: Defines security level (Sign, SignAndEncrypt)
  • client_certificate_path: Path to the client certificate in NOVA storage
  • client_private_key_path: Path to the client private key in NOVA storage The certificate handling process automatically fetches certificates from NOVA storage and creates temporary files for secure connections client.py:77-111 .

For detailed implementation guidance, refer to the OPC UA client implementation  in the Python SDK repository.

Notes

  • The NOVA SDK uses the asyncua library as the underlying OPC UA implementation
  • All OPC UA functions (opcua_read, opcua_write, opcua_call, wait_for_opcua_value) support the same security configuration format
  • Certificate paths refer to files stored in the NOVA platform’s storage service, not local file system paths
  • The SDK automatically handles temporary file creation and cleanup for certificates during secure connections

Wiki pages you might want to explore: Overview (wandelbotsgmbh/wandelbots-nova) 

Last updated on