#include <chrono>
#include <iostream>
#include <thread>
int main() {
opcua::VariableId::Server_ServerStatus_CurrentTime,
std::cout
<< "Data change notification:\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.
IntegerId subscriptionId() const noexcept
Get the server-assigned identifier of the underlying subscription.
const NodeId & nodeId()
Get the monitored NodeId.
IntegerId monitoredItemId() const noexcept
Get the server-assigned identifier of this monitored item.
AttributeId attributeId()
Get the monitored AttributeId.
High-level subscription class.
MonitoredItem< Connection > subscribeDataChange(const NodeId &id, AttributeId attribute, MonitoringMode monitoringMode, const MonitoringParametersEx ¶meters, DataChangeNotificationCallback onDataChange)
Create a monitored item for data change notifications.
void setSubscriptionParameters(const SubscriptionParameters ¶meters)
Modify this subscription.
void setPublishingMode(bool publishing)
Enable/disable publishing of notification messages.
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.