open62541pp 0.16.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
events/server_events.cpp
int main() {
opcua::Server server;
// Objects node can be used to subscribe to events.
// Add a method to generate and trigger events.
opcua::Event event(server);
objectsNode.addMethod(
{1, 1000},
"GenerateEvent",
const auto severity = input[0].getScalar<uint16_t>();
const auto& message = input[1].getScalar<opcua::String>();
event.writeTime(opcua::DateTime::now());
event.writeSeverity(severity);
event.writeMessage({"", message});
event.trigger();
},
{
{"severity", {"", "Severity"}, opcua::DataTypeId::UInt16, opcua::ValueRank::Scalar},
{"message", {"", "Message"}, opcua::DataTypeId::String, opcua::ValueRank::Scalar},
},
{}
);
server.run();
}
static DateTime now() noexcept
Get current DateTime.
Definition types.hpp:366
Create and trigger events.
Definition event.hpp:19
High-level node class to access node attribute, browse and populate address space.
Definition server.hpp:30
Node & writeEventNotifier(Bitmask< EventNotifier > eventNotifier)
Write the AttributeId::EventNotifier attribute of a node.
Definition node.hpp:1121
Node addMethod(const NodeId &id, std::string_view browseName, services::MethodCallback callback, Span< const Argument > inputArguments, Span< const Argument > outputArguments, const MethodAttributes &attributes={}, const NodeId &referenceType=ReferenceTypeId::HasComponent)
Add method.
Definition node.hpp:227
High-level server class.
Definition server.hpp:132
void run()
Run the server's main loop. This method will block until Server::stop is called.
View to a contiguous sequence of objects, similar to std::span in C++20.
Definition span.hpp:26
UA_String wrapper class.
Definition types.hpp:251