Class OpcuaClient

Nested Relationships

Nested Types

Class Documentation

class OpcuaClient

RAII wrapper around open62541pp::Client with auto-reconnect.

Public Types

enum class WriteError

OPC-UA write error classification.

Values:

enumerator NotConnected
enumerator TypeMismatch
enumerator AccessDenied
enumerator NodeNotFound
enumerator TransportError

Public Functions

OpcuaClient()
~OpcuaClient()
OpcuaClient(const OpcuaClient&) = delete
OpcuaClient &operator=(const OpcuaClient&) = delete
bool connect(const OpcuaClientConfig &config)

Connect to OPC-UA server

Returns:

true if connected successfully

void disconnect()

Disconnect and stop reconnect attempts.

bool is_connected() const

Check if currently connected.

std::string endpoint_url() const

Get the endpoint URL (for status reporting)

OpcuaClientConfig current_config() const

Get the current config (for reconnection)

std::vector<std::string> browse(const opcua::NodeId &parent_node)

Browse child nodes of a given node

Returns:

Vector of child node ID strings (e.g., “ns=1;s=TankLevel”)

ReadResult read_value(const opcua::NodeId &node_id)

Read a single value.

std::vector<ReadResult> read_values(const std::vector<opcua::NodeId> &node_ids)

Read multiple values.

tl::expected<void, WriteErrorInfo> write_value(const opcua::NodeId &node_id, const OpcuaValue &value, const std::string &data_type_hint = "")

Write a value to a node

Parameters:

data_type_hint – If non-empty, skip readValue type-probe and use this hint (“bool”, “int”, “float”, “string”) to select the write coercion directly. Halves mutex hold time by eliminating a round-trip to the server.

Returns:

void on success, WriteErrorInfo on failure with specific error code

uint32_t create_subscription(double publish_interval_ms, DataChangeCallback callback)

Create a subscription with data change notifications

Returns:

Subscription ID, or 0 on failure

bool add_monitored_item(uint32_t subscription_id, const opcua::NodeId &node_id)

Add a monitored item to a subscription

Returns:

true if item was added

void remove_subscriptions()

Remove all subscriptions.

std::string server_description() const

Get server description string (for status endpoint)

struct WriteErrorInfo

Detailed write error info.

Public Members

WriteError code
std::string message