# OPC UA Client

This function block establishes and maintains a connection to an OPC UA server so other communication blocks can read from or write to that server. It provides simple fields for server address and optional credentials, monitors connection health, and attempts reconnection automatically when needed.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

`(none)`

This block does not require inputs to run. It acts as a communication provider for other blocks.

## 📤 Outputs <a href="#outputs" id="outputs"></a>

`Client` Provides the connected OPC UA client object that other communication blocks can use to perform read/write operations.

## 🕹️ Controls <a href="#controls" id="controls"></a>

`Username` Enter the user name if the OPC UA server requires authentication. Leave empty for anonymous access.

`Password` Enter the password associated with the username. This field hides the input for privacy.

`Server Address` Type the server address as an IP and port (for example 192.168.1.10:4840) or as a full OPC UA URL (for example opc.tcp\://host:port). The block will use this value to connect to the server.

## 🎨 Features <a href="#features" id="features"></a>

* Automatic connection management: the block connects when the address is set and will try to reconnect if the connection is lost or the address changes.
* Authentication support: optional username and password fields for secured servers.
* Connection health monitoring: warns or logs when the client cannot reach the server.
* Clean disconnect: releases the connection when the block is removed from the workspace to free resources.

## ⚙️ Running mechanism <a href="#running-mechanism" id="running-mechanism"></a>

When the scenario runs, this block uses the provided `Server Address` (and optional `Username`/`Password`) to open a connection to the OPC UA server. It continuously checks connection status and attempts to reconnect automatically if there is a failure or if the address is changed. The active connection is exposed through the `Client` output so other blocks can perform operations against the server. When the block is removed, the connection is cleanly closed.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

`OPC UA Read`\
Connect this block to the `Client` output to read values from the server at runtime.

`OPC UA Write`\
Use this block together with the `Client` output to write values back to the server.

`CSV Export`\
Log read values by piping outputs into this block to save time-series data for later analysis.

`SQL-DB Client Connect` + `SQL-DB Operations`\
Store historical values in a database by combining the OPC UA client with a database connection and write/query blocks.

`MQTT Publish` / `MQTT Subscribe`\
Bridge OPC UA data to/from cloud systems by publishing readings to MQTT or subscribing to control topics to trigger writes.

`REST API - Post` / `REST API - Get`\
Forward critical data or alerts to web services by sending HTTP requests containing OPC data.

`Send Mail`\
Trigger email alerts (for example on connection loss or threshold breaches) by feeding condition outputs into the mail block.

`Debug Input`\
Use this block to inspect values coming from the server during setup and troubleshooting.

## 📝 Quick usage <a href="#usage" id="usage"></a>

1. Enter the server address into `Server Address` (IP:Port or full OPC UA URL).
2. If the server requires authentication, fill `Username` and `Password`.
3. Run the scenario — the block will connect and provide the `Client` output for other communication blocks to use.
4. To stop and free resources, remove the block or clear the address; the block will close the connection.

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* Connection fails or times out
  * Verify the server address and port are correct and reachable from the machine running the scenario.
  * Check firewall or network rules that may block OPC UA ports.
  * If the server uses a secure endpoint, confirm credentials and server security settings.
* Authentication errors
  * Ensure `Username` and `Password` are correct and that the server permits the chosen authentication method.
* Unexpected disconnects or unstable connection
  * Use the block together with `Debug Input` to log values and identify when disconnections occur.
  * Consider routing important read results to `CSV Export` or a database (`SQL-DB Operations`) for persistence.

If problems persist, consult your OPC UA server documentation and network administrator to confirm server endpoints, ports, and security requirements.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.augelab.com/function-blocks/input-output/communication/opc-ua-client.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
