#include <iostream>
int main() {
client.
onConnected([] { std::cout <<
"Client connected" << std::endl; });
std::cout << "Session activated" << std::endl;
client,
std::cout <<
"Read result with status code: " << result.
code() << std::endl;
const auto dt = result.
value().getScalar<opcua::DateTime>();
std::cout << "Server date (UTC): " << dt.format("%Y-%m-%d %H:%M:%S") << std::endl;
}
);
);
std::cout << "Browse result with " << result.getReferences().size() << " references:\n";
for (const auto& reference : result.getReferences()) {
std::cout << "- " << reference.getBrowseName().getName() << std::endl;
}
});
client,
true,
{},
[](uint32_t subId) { std::cout << "Subscription deleted: " << subId << std::endl; },
std::cout
<< "Subscription created:\n"
<< "- status code: " << response.getResponseHeader().getServiceResult() << "\n"
<< "- subscription id: " << response.getSubscriptionId() << std::endl;
client,
response.getSubscriptionId(),
),
std::cout
<< "Data change notification:\n"
<< "- subscription id: " << subId << "\n"
<< "- monitored item id: " << monId << "\n"
<< "- timestamp: " << dv.getSourceTimestamp() << std::endl;
},
{},
std::cout
<< "MonitoredItem created:\n"
<< "- status code: " << result.getStatusCode() << "\n"
<< "- monitored item id: " << result.getMonitoredItemId() << std::endl;
}
);
}
);
});
client.
onSessionClosed([] { std::cout <<
"Session closed" << std::endl; });
client.
onDisconnected([] { std::cout <<
"Client disconnected" << std::endl; });
}
UA_BrowseDescription wrapper class.
UA_BrowseResult wrapper class.
void onConnected(StateCallback callback)
Set a state callback that will be called after the client is connected.
void onDisconnected(StateCallback callback)
Set a state callback that will be called after the client is disconnected.
void onSessionActivated(StateCallback callback)
Set a state callback that will be called after the session is activated.
void run()
Run the client's main loop by. This method will block until Client::stop is called.
void onSessionClosed(StateCallback callback)
Set a state callback that will be called after the session is closed.
void connectAsync(std::string_view endpointUrl)
Asynchronously connect to the selected server.
UA_CreateSubscriptionResponse wrapper class.
UA_DataValue wrapper class.
UA_MonitoredItemCreateResult wrapper class.
UA_ReadValueId wrapper class.
The template class Result encapsulates a StatusCode and optionally a value.
constexpr T & value() &
Get the value of the Result.
constexpr StatusCode code() const noexcept
Get the StatusCode of the Result.
auto browseAsync(Client &connection, const BrowseRequest &request, CompletionToken &&token)
Discover the references of one or more nodes (client only).
auto createMonitoredItemDataChangeAsync(Client &connection, uint32_t subscriptionId, const ReadValueId &itemToMonitor, MonitoringMode monitoringMode, const MonitoringParametersEx ¶meters, DataChangeNotificationCallback dataChangeCallback, DeleteMonitoredItemCallback deleteCallback, CompletionToken &&token)
auto createSubscriptionAsync(Client &connection, const CreateSubscriptionRequest &request, StatusChangeNotificationCallback statusChangeCallback, DeleteSubscriptionCallback deleteCallback, CompletionToken &&token)
Create a subscription.
@ Server_ServerStatus_CurrentTime
auto readValueAsync(Client &connection, const NodeId &id, CompletionToken &&token)
Read the AttributeId::Value attribute of a node.
@ Value
The most recent value of the variable that the server has.
Extended monitoring parameters with default values from open62541.
Subscription parameters with default values from open62541.