22 using namespace OpcUa;
28 std::cout <<
"Received DataChange event for Node " << node << std::endl;
32 std::vector<OpcUa::Variant>
MyMethod(
NodeId context, std::vector<OpcUa::Variant> arguments)
34 std::cout <<
"MyMethod called! " << std::endl;
35 std::vector<OpcUa::Variant> result;
36 result.push_back(
Variant(static_cast<uint8_t>(0)));
45 server.
SetEndpoint(
"opc.tcp://localhost:4840/freeopcua/server");
46 server.
SetServerURI(
"urn://exampleserver.freeopcua.github.io");
67 logger->info(
"Root node is: {}", root);
68 logger->info(
"Children are:");
72 logger->info(
" {}", node);
98 logger->info(
"Ctrl-C to exit");
103 std::stringstream ss;
104 ss <<
"This is event number: " <<
counter;
107 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
113 int main(
int argc,
char ** argv)
120 catch (
const std::exception & exc)
122 std::cout << exc.what() << std::endl;
void SetEndpoint(const std::string &endpoint)
set endpoint uri on wich server will listen. opc.tcp://localhost:4841/opcua/server opc...
Node GetRootNode() const
helper methods for node you will probably want to access
void SetServerURI(const std::string &uri)
Node AddVariable(const NodeId &variableId, const QualifiedName &browsename, const Variant &val) const
Node AddMethod(const NodeId &variableId, const QualifiedName &browsename, std::function< std::vector< OpcUa::Variant >(NodeId context, std::vector< OpcUa::Variant > arguments)> method) const
void EnableEventNotification()
Enable event notification on Server node this is necessary if you want to be able to send custom even...
Subscription client class handles subscription callbacks.
uint32_t RegisterNamespace(std::string uri)
Register your application namespace.
void Start()
Start and Stop server.
int main(int argc, char **argv)
void TriggerEvent(Event event)
Trigger and event.
std::vector< OpcUa::Variant > MyMethod(NodeId context, std::vector< OpcUa::Variant > arguments)
OPC UA Address space part. GNU LGPL.
Node AddObject(const NodeId &folderId, const QualifiedName &browseName) const
A Node object represent an OPC-UA node. It is high level object intended for developper who want to e...
std::vector< Node > GetChildren(const OpcUa::ReferenceId &refid) const
List child nodes by specified reference.
static DateTime Current()
Node GetObjectsNode() const
void SetValue(const Variant &val) const
void DataChange(uint32_t handle, const Node &node, const Variant &val, AttributeId attr) override
std::shared_ptr< logger > stderr_color_mt(const std::string &logger_name)