open62541pp 0.17.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.
opcua::Node objectsNode(server, opcua::ObjectId::ObjectsFolder);
// Add a method to generate and trigger events.
opcua::Event event(server);
objectsNode.addMethod(
{1, 1000},
"GenerateEvent",
const auto severity = input.at(0).scalar<uint16_t>();
const auto& message = input.at(1).scalar<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:402
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:28
constexpr reference at(size_t index) const
Access element by index with bounds checking.
Definition span.hpp:123
UA_String wrapper class.
Definition types.hpp:256