# OPC UA

OPC UA is a standard for reading data from industrial systems by name. This page covers how a client finds a value, the two ways to get it, and how to send it to Nominal.

[`Download this page as a notebook`](https://dev.nominal.io/learning/_downloads/569d8b7e80c69f5976a1dbfeaaa98e60/opc-ua.md) to run its code in JupyterLab. [Running the notebooks](https://dev.nominal.io/learning/guides/notebooks/running.md) explains how to set it up.

## How OPC UA works

OPC UA is “a platform independent service-oriented architecture” that integrates all the functionality of the individual OPC Classic specifications into one extensible framework.[[1]](https://dev.nominal.io/learning/guides/opc-ua.md#opc-page) It models data with its meaning, such as units and relationships, and supports both client-server requests and publish-subscribe.[[1]](https://dev.nominal.io/learning/guides/opc-ua.md#opc-page)

A server holds its data in an address space, which represents data hierarchically, like files and folders.[[1]](https://dev.nominal.io/learning/guides/opc-ua.md#opc-page) A node is a “fundamental component of an AddressSpace”.[[2]](https://dev.nominal.io/learning/guides/opc-ua.md#opc-part1) A client gets a node by its node ID, such as `i=85` in asyncua’s example, and reads its value.[[3]](https://dev.nominal.io/learning/guides/opc-ua.md#asyncua)

## Polling and subscriptions

A client can get a value in two ways:

- **Polling.** The client reads the node on its own schedule, and gets a value each time, changed or not.
- **A subscription.** A subscription is a client-defined endpoint in the server, used to return notifications to the client.[[2]](https://dev.nominal.io/learning/guides/opc-ua.md#opc-part1) The client adds monitored items to it, each of which is a client-defined entity that monitors an attribute for new values.[[2]](https://dev.nominal.io/learning/guides/opc-ua.md#opc-part1) The server reports by exception: when a value changes, according to the client’s criteria.[[1]](https://dev.nominal.io/learning/guides/opc-ua.md#opc-page)

Two intervals control a subscription. The sampling interval is the fastest rate at which the server samples its source for changes. The publishing interval is the rate at which the subscription tries to send a message to the client.[[4]](https://dev.nominal.io/learning/guides/opc-ua.md#opc-part4)

This simulation compares the two for a temperature that sits at one value for a while and then steps to another. It reads the temperature 10 times a second, and counts the values a simple report-on-change rule would send, which are the values that differ from the last one:

```ipython3
import matplotlib.pyplot as plt
import numpy as np
from learning.style import set_matplotlib_style

set_matplotlib_style()
```

```ipython3
t = np.arange(0, 60, 0.1)  # s: a read every 0.1 s
rng = np.random.default_rng(3)
temperature = np.where(t < 20, 21.0, np.where(t < 40, 24.5, 22.0))  # °C, in steps
temperature = np.round(
    temperature + rng.normal(0, 0.02, t.size), 1
)  # 0.1 °C resolution

changed = np.r_[
    True, np.diff(temperature) != 0
]  # values that differ from the last one

fig, ax = plt.subplots()
ax.plot(t, temperature, color="0.7", label=f"Polled: {t.size} values")
ax.plot(
    t[changed],
    temperature[changed],
    "o",
    label=f"Reported on change: {changed.sum()} values",
)
ax.set_xlabel("Time (s)")
ax.set_ylabel("Temperature (°C)")
ax.legend()
plt.show()
```

![../../_images/d44ad97c877125e46f15696e5c5cb933752a9a79d024639c701189275e62343b.svg](https://dev.nominal.io/learning/_images/d44ad97c877125e46f15696e5c5cb933752a9a79d024639c701189275e62343b.svg)

The changed values describe the same temperature as the polled ones with far fewer values. The cost is that a value that hasn’t changed isn’t re-sent, so a quiet signal and a dead connection look alike unless the server’s keep-alive messages, which it sends when there’s nothing to report, tell them apart.[[4]](https://dev.nominal.io/learning/guides/opc-ua.md#opc-part4) Which to use depends on the data: poll when you want a value at a steady rate, and subscribe when changes matter more than the rate.

## In Nominal

Nominal’s channels hold timestamped values, so each value you read becomes a point. This code reads a node with the asyncua library and streams it, polling once a second:[[3]](https://dev.nominal.io/learning/guides/opc-ua.md#asyncua)

```python
import asyncio
from datetime import datetime, timezone

from asyncua import Client
from nominal.core import NominalClient

client = NominalClient.from_profile("default")
dataset = client.get_dataset("<dataset RID>")

async def main():
    async with Client(url="opc.tcp://localhost:4840/freeopcua/server/") as opc:
        node = opc.get_node("ns=2;s=Furnace.Temperature")  # your node's ID
        with dataset.get_write_stream() as stream:
            while True:
                value = await node.read_value()
                now = datetime.now(timezone.utc)  # when the computer read the value
                stream.enqueue("furnace.temperature", now, float(value))
                await asyncio.sleep(1.0)

asyncio.run(main())
```

`get_write_stream` sends the values in batches.[[5]](https://dev.nominal.io/learning/guides/opc-ua.md#nominal-client) The timestamp is the time of the read, not of the measurement, so it can lag the real change by up to the polling period. [What the link means for your data](https://dev.nominal.io/learning/guides/communications.md#what-the-link-means-for-your-data) explains why that matters.

## Further reading

- [Communications](https://dev.nominal.io/learning/guides/communications.md), on the other links a test system uses, and how to check what each does to your data.
- OPC Foundation, [Unified Architecture](https://opcfoundation.org/about/opc-technologies/opc-ua/).
- OPC Foundation, [OPC 10000-4: Services](https://reference.opcfoundation.org/specs/OPC-10000-4/1), the full definitions of subscriptions and monitored items.
- opcua-asyncio, [the asyncua library](https://github.com/FreeOpcUa/opcua-asyncio).

## References

---

[1]
([1](https://dev.nominal.io/learning/guides/opc-ua.md#id1),[2](https://dev.nominal.io/learning/guides/opc-ua.md#id2),[3](https://dev.nominal.io/learning/guides/opc-ua.md#id3),[4](https://dev.nominal.io/learning/guides/opc-ua.md#id8))

OPC Foundation, [“Unified Architecture”](https://opcfoundation.org/about/opc-technologies/opc-ua/). Retrieved 2026-11-30.

[2]
([1](https://dev.nominal.io/learning/guides/opc-ua.md#id4),[2](https://dev.nominal.io/learning/guides/opc-ua.md#id6),[3](https://dev.nominal.io/learning/guides/opc-ua.md#id7))

OPC Foundation, [“OPC 10000-1: Overview and Concepts”](https://reference.opcfoundation.org/specs/OPC-10000-1/1), the definitions of Node, Subscription and MonitoredItem. Retrieved 2026-11-30.

[3]
([1](https://dev.nominal.io/learning/guides/opc-ua.md#id5),[2](https://dev.nominal.io/learning/guides/opc-ua.md#id11))

opcua-asyncio, [README](https://github.com/FreeOpcUa/opcua-asyncio), the `Client` example: `get_node` and `read_value`. Retrieved 2026-11-30.

[4]
([1](https://dev.nominal.io/learning/guides/opc-ua.md#id9),[2](https://dev.nominal.io/learning/guides/opc-ua.md#id10))

OPC Foundation, [“OPC 10000-4: Services”](https://reference.opcfoundation.org/specs/OPC-10000-4/1), sections 5.13.1.2 and 5.14.1.1. Retrieved 2026-11-30.

[[5](https://dev.nominal.io/learning/guides/opc-ua.md#id12)]

Nominal, `Dataset.get_write_stream` in the [nominal](https://pypi.org/project/nominal/) Python client, version 1.186.0. Retrieved 2026-11-30.
