#include <iostream>
int main() {
client.
onConnected([] { std::cout <<
"Client connected" << std::endl; });
std::cout << "Session activated" << std::endl;
client,
opcua::VariableId::Server_ServerStatus_CurrentTime,
std::cout <<
"Read result with status code: " << result.
code() << std::endl;
std::cout <<
"Server date (UTC): " << dt.
format(
"%Y-%m-%d %H:%M:%S") << std::endl;
}
);
opcua::ObjectId::Server,
opcua::BrowseDirection::Forward,
opcua::ReferenceTypeId::References
);
std::cout << "Browse result with " << result.references().size() << " references:\n";
for (const auto& reference : result.references()) {
std::cout << "- " << reference.browseName().name() << std::endl;
}
});
client,
true,
{},
std::cout << "Subscription deleted: " << subId << std::endl;
},
std::cout
<< "Subscription created:\n"
<< "- status code: " << response.responseHeader().serviceResult() << "\n"
<< "- subscription id: " << response.subscriptionId() << std::endl;
client,
response.subscriptionId(),
opcua::VariableId::Server_ServerStatus_CurrentTime,
),
opcua::MonitoringMode::Reporting,
std::cout
<< "Data change notification:\n"
<< "- subscription id: " << subId << "\n"
<< "- monitored item id: " << monId << "\n"
<< "- timestamp: " << dv.sourceTimestamp() << std::endl;
},
{},
std::cout
<< "MonitoredItem created:\n"
<< "- status code: " << result.statusCode() << "\n"
<< "- monitored item id: " << result.monitoredItemId() << std::endl;
}
);
}
);
});
client.
onSessionClosed([] { std::cout <<
"Session closed" << std::endl; });
client.
onDisconnected([] { std::cout <<
"Client disconnected" << std::endl; });
}
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_DataValue wrapper class.
UA_DateTime wrapper class.
std::string format(std::string_view format, bool localtime=false) const
Convert to string with given format (same format codes as strftime).
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.
UA_BrowseDescription wrapper class.
UA_BrowseResult wrapper class.
UA_CreateSubscriptionResponse wrapper class.
UA_MonitoredItemCreateResult wrapper class.
UA_ReadValueId wrapper class.
auto browseAsync(Client &connection, const BrowseRequest &request, CompletionToken &&token)
Discover the references of one or more nodes (client only).
auto createMonitoredItemDataChangeAsync(Client &connection, IntegerId 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.
auto readValueAsync(Client &connection, const NodeId &id, CompletionToken &&token)
Read the AttributeId::Value attribute of a node.
uint32_t IntegerId
IntegerId.
@ 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.