Read a node value from an OPC UA server using the open62541 C client

domain: open62541.org · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Create a client handle with UA_Client *client = UA_Client_new()
  2. Apply default settings via UA_ClientConfig_setDefault(UA_Client_getConfig(client))
  3. Connect with UA_Client_connect(client, "opc.tcp://<host>:4840") and check the returned UA_StatusCode against UA_STATUSCODE_GOOD
  4. Read a value into a UA_Variant with UA_Client_readValueAttribute(client, nodeId, &value)
  5. Browse the address space with the Browse service (UA_Client_Service_browse) to enumerate child nodes before reading unknown NodeIds
  6. Clean up with UA_Variant_clear(&value) then UA_Client_delete(client), which also disconnects

Known gotchas

Related routes

Read and subscribe to OPC UA server nodes from a Node-RED flow using node-red-contrib-opcua
npmjs.com · 6 steps · unrated
Connect, browse, read, and subscribe to nodes on an OPC UA server using Eclipse Milo (Java SDK)
github.com · 6 steps · unrated
Browse an OPC UA server's address space and subscribe to data changes from a client
reference.opcfoundation.org · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans