open62541pp 0.16.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
client_connect.cpp
#include <iostream>
#include "helper.hpp" // CliParser
int main(int argc, char* argv[]) {
const CliParser parser(argc, argv);
if (parser.nargs() < 2 || parser.hasFlag("-h") || parser.hasFlag("--help")) {
std::cout
<< "usage: client_connect [options] opc.tcp://<host>:<port>\n"
<< "options:\n"
<< " --username <name>\n"
<< " --password <password>\n"
<< " --help, -h\n"
<< std::flush;
return 2;
}
const auto serverUrl = parser.args()[parser.nargs() - 1];
const auto username = parser.getValue("--username");
const auto password = parser.getValue("--password");
opcua::Client client;
if (username) {
opcua::UserNameIdentityToken(username.value(), password.value_or(""))
);
}
client.connect(serverUrl);
const auto dt = node.readValueScalar<opcua::DateTime>();
client.disconnect();
std::cout << "Server date (UTC): " << dt.format("%Y-%m-%d %H:%M:%S") << std::endl;
}
void setUserIdentityToken(const AnonymousIdentityToken &token)
Set anonymous identity token.
High-level client class.
Definition client.hpp:121
void disconnect()
Disconnect and close the connection to the server.
void connect(std::string_view endpointUrl)
Connect to the selected server.
ClientConfig & config() noexcept
UA_DateTime wrapper class.
Definition types.hpp:354
High-level node class to access node attribute, browse and populate address space.
Definition server.hpp:30
T readValueScalar()
Read scalar value from variable node.
Definition node.hpp:850
UA_UserNameIdentityToken wrapper class.