#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";
std::cout <<
"Current server time (UTC): " << dt.
format(
"%H:%M:%S") << std::endl;
}
);
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.
Variant & value() &noexcept
Get value.
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).
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.
std::string toString() const
Encode NodeId as a string like ns=1;s=SomeNode.
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.
T & scalar() &
Get reference to scalar value with given template type (only native or wrapper types).
uint32_t IntegerId
IntegerId.
@ Value
The most recent value of the variable that the server has.
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.