#include <chrono>
#include <iostream>
#include <thread>
int main() {
sub.setSubscriptionParameters(subscriptionParameters);
sub.setPublishingMode(true);
auto mon = sub.subscribeDataChange(
opcua::VariableId::Server_ServerStatus_CurrentTime,
std::cout
<< "Data change notification:\n"
<< "- subscription id: " << item.subscriptionId() << "\n"
<< "- monitored item id: " << item.monitoredItemId() << "\n"
<< "- attribute id: " << static_cast<int>(item.attributeId()) << "\n"
}
);
mon.setMonitoringParameters(monitoringParameters);
mon.setMonitoringMode(opcua::MonitoringMode::Reporting);
});
while (true) {
try {
client.
connect(
"opc.tcp://localhost:4840");
std::cout <<
"Error: " << e.
what() <<
"\nRetry to connect in 3 seconds\n";
std::this_thread::sleep_for(std::chrono::seconds{3});
}
}
}
Exception for bad status codes from open62541 UA_STATUSCODE_*.
const char * what() const noexcept override
void disconnect()
Disconnect and close the connection to the server.
void connect(std::string_view endpointUrl)
Connect to the selected server.
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.
UA_DataValue wrapper class.
High-level monitored item class.
High-level subscription class.
uint32_t IntegerId
IntegerId.
String toString(const NumericRange &range)
Extended monitoring parameters with default values from open62541.
double samplingInterval
Interval in milliseconds that defines the fastest rate at which the MonitoredItem should be accessed ...
Subscription parameters with default values from open62541.
double publishingInterval
Cyclic interval in milliseconds that the subscription is requested to return notifications.