> For the complete documentation index, see [llms.txt](https://docs.enlyze.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.enlyze.com/en/integrations/opc-ua-server.md).

# OPC-UA server

Connect an OPC-UA client to the Edge Device's OPC-UA server.

The Edge Device can provide the live values of its data sources through its own OPC-UA server. In this guide you set up the server and connect an OPC-UA client to it, for example UaExpert, a SCADA system or an IIoT platform such as Litmus.

The OPC-UA server runs directly on the Edge Device and is reachable on the local network. It provides the current values of all variables the Edge Device reads, but no history and no production context. For stored time series, production runs or OEE, use the [Quickstart](https://docs.enlyze.com/en/enlyze-api/quickstart.md).

In the ENLYZE Platform you set up the server as a **data sink**. A data sink defines where an Edge Device sends its data. Every Edge Device has a data sink for the ENLYZE Platform, which ENLYZE manages.

## Prerequisites

* The Edge Device is online and reads data from at least one data source.
* The computer running the OPC-UA client can reach the Edge Device on the network.
* You can edit the Edge Device's data sinks in the ENLYZE Platform.

## Set up the OPC-UA server

1. Open **Edge Devices** in the sidebar and select the Edge Device.
2. Open the **Data sinks** tab and click **Add data sink**.
3. Select **OPC UA** as the **Type**.
4. Check the settings (see the table below) and add at least one user.
5. Click **Save**.

The Edge Device picks up the configuration automatically and starts the server.

| Setting                             | Default                         | Meaning                                                          |
| ----------------------------------- | ------------------------------- | ---------------------------------------------------------------- |
| **Application name**                | `ENLYZE OPC UA @ <Edge Device>` | Name the server shows in the client                              |
| **Port**                            | `4840`                          | TCP port of the server                                           |
| **Minimum transport security**      | SHA-256 policies or stronger    | Weakest security policy the server offers                        |
| **Require Sign & Encrypt**          | On                              | Only allows encrypted connections, no sign-only ones             |
| **Minimum password token security** | SHA-256 policies or stronger    | Weakest security policy a client may use to encrypt the password |
| **Allow anonymous login**           | Off                             | Login without username and password                              |
| **Users**                           | none                            | Username and password (at least 6 characters) for logging in     |

An Edge Device has at most one OPC-UA server. The type of a data sink cannot be changed afterwards. To edit or delete the server, use the menu in its row on the **Data sinks** tab.

ENLYZE stores passwords only as hashes, so a forgotten password cannot be looked up: remove the user and add it again with a new password.

## Build the server URL

The server URL has this format:

```
opc.tcp://<IP address of the Edge Device>:<port>
```

1. Open the Edge Device's **Overview** tab. **Network interfaces** lists the IP addresses of the Edge Device.
2. Pick the IP address of the network interface that is on the same network as the OPC-UA client.
3. The port is in the **Port** column of the **Data sinks** tab (default `4840`).

Example: the network interface towards the machine has the IP address `192.168.10.25` and the port is `4840`. The server URL is `opc.tcp://192.168.10.25:4840`.

{% hint style="warning" %}
If the **Assignment** column of a network interface says **Dynamic via DHCP**, its IP address can change. For a permanent connection, give the Edge Device a fixed IP address on that network, either statically via [Configuring the Network](https://docs.enlyze.com/en/connect/edge-device/enlyze-edge/configuring-the-network.md) or through a DHCP reservation.
{% endhint %}

The Edge Device reports these IP addresses itself. While it is offline, the ENLYZE Platform shows the state of its last connection.

## Connect the OPC-UA client

### Enter the server URL directly

Enter the server URL in the client as the **Endpoint URL** (or **Server URL**).

{% hint style="warning" %}
Do not use the client's automatic search (for example **Discovery** or **Get Endpoints**). The server reports the address `opc.tcp://0.0.0.0:4840` there, which cannot be connected to. If your client only connects through the search, replace `0.0.0.0` in the address it finds with the IP address of the Edge Device.
{% endhint %}

### Choose security policy and security mode

Which combinations the server accepts depends on the OPC-UA server's settings:

| Minimum transport security                 | Security policies                                                 |
| ------------------------------------------ | ----------------------------------------------------------------- |
| SHA-256 policies or stronger               | `Basic256Sha256`, `Aes128_Sha256_RsaOaep`, `Aes256_Sha256_RsaPss` |
| SHA-1 policies or stronger (deprecated)    | additionally `Basic256` and `Basic128Rsa15`                       |
| None (also offers an unencrypted endpoint) | additionally `None`                                               |

Select **Sign & Encrypt** as the **Security mode**. **Sign** only works when **Require Sign & Encrypt** is off. The same applies to the `None` policy with mode **None**: while **Require Sign & Encrypt** is on, the server rejects such connections, even though it offers the unencrypted endpoint.

We recommend `Basic256Sha256` with **Sign & Encrypt**.

### Log in

* **Username and password**: log in as one of the OPC-UA server's users.
* **Anonymous**: only possible when **Allow anonymous login** is on.

The server does not support logging in with a client certificate.

### Certificates

The Edge Device creates the server certificate itself on first start. When your client asks whether to trust the server certificate, confirm it. The ENLYZE Platform does not show the certificate's fingerprint yet.

You do not need to install the client certificate on the Edge Device. The server accepts any client's certificate; access is controlled through the login.

## Find data in the address space

Under **Objects** there is one object per data source of the Edge Device, named after the data source. It contains the data source's variables under their display names.

| Node        | NodeId                             |
| ----------- | ---------------------------------- |
| Data source | `ns=1;g=<UUID of the data source>` |
| Variable    | `ns=1;g=<UUID of the variable>`    |

NodeIds stay stable as long as the data source and the variable exist. Clients that map data points by NodeId keep their mapping when you rename a display name. You can also get the UUIDs from the [Quickstart](https://docs.enlyze.com/en/enlyze-api/quickstart.md).

About the values:

* Each variable shows its most recent value, with its scaling factor applied.
* If a variable delivers no new value for 10 seconds, its value is empty.
* The variables are read-only. The server rejects writes with `BadNotWritable`.

## Verify the connection

The connection works when the client lists the Edge Device's data sources under **Objects** and the variable values update.

## Troubleshooting

| Problem                                | Possible cause and fix                                                                                                                           |
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| No connection, timeout                 | The client cannot reach the Edge Device. Check the IP address and port, that both are on the same network, and that no firewall blocks the port. |
| Connecting to `0.0.0.0` fails          | The client uses the address from its automatic search. Enter the server URL directly (see above).                                                |
| Server rejects the connection or login | Security policy or security mode do not match the server's settings, or username and password are wrong.                                         |
| Data source or variable is missing     | The server only shows data sources and variables the Edge Device reads. New variables appear as soon as the Edge Device reads them.              |
| Values are empty                       | The variable has not delivered a new value for more than 10 seconds. Check the Edge Device's connection to the data source.                      |

## Next steps

* [Security](https://docs.enlyze.com/en/connect/security.md): which networks the OPC-UA server is reachable from
