Skip to main content

Using OPC-UA Nodes in Detail

Community nodes such as node-red-contrib-opcua let you communicate directly with external OPC-UA servers (Kepware, Ignition, other gateways). The same nodes are also used to connect to the gateway's own OPC-UA server (opc.tcp://127.0.0.1:12000, NodeId ns=2;s=...).

When connecting to the built-in OPC-UA server

Copy the TCP Endpoint URL and NodeId directly from the OPC-UA Viewer screen menu. See Using the OPC-UA Node Viewer for details.


1. Node Types (node-red-contrib-opcua)

NodePurpose
OpcUa-EndpointServer connection information (host/port/security/auth) — create once and share across other nodes
OpcUa-ItemSingle node definition — converts nodeId into an input
OpcUa-ClientMain action node for Read / Write / Browse / Method call
OpcUa-SubscribeSubscribes to change events (MonitoredItem) — receive by push instead of polling
OpcUa-EventSubscribes to OPC-UA Alarm & Event

2. Creating an Endpoint

Double-click the OpcUa-Client node → pencil icon next to the Endpoint field → new endpoint:

ItemValue (based on the gateway's built-in server)
Endpointopc.tcp://127.0.0.1:12000
Security PolicyNone (internal) or Basic256Sha256 (external operation)
Security ModeNone / Sign / Sign & Encrypt
LoginUsername/Password from the OPC-UA Viewer screen, or Anonymous (if permitted)

3. Read / Write Patterns

inject ─▶ OpcUa-Item (nodeId, msg.payload type) ─▶ OpcUa-Client (READ/WRITE) ─▶ debug

OpcUa-Item:

ItemValue
Itemns=2;s=SITE_00001.OPC_00303.TAG_TEST_00042
DataTypeInt32 (must match the actual tag data type — a mismatch causes BadTypeMismatch)

OpcUa-Client:

ItemValue
ActionREAD or WRITE
EndpointThe endpoint created above

For WRITE, place a change before the OpcUa-Item node to populate the value, e.g. msg.payload = 9999.


4. Subscribe — Receiving Only Changes, Without Polling

Subscribe is far more efficient than polling (periodic reads). If nothing changes there is no traffic, and updates arrive within microseconds.

inject (once after deploy) ─▶ OpcUa-Item ×N ─▶ join (배열) ─▶ OpcUa-Subscribe ─▶ debug / function

OpcUa-Subscribe:

ItemValue
ActionSUBSCRIBE
Interval100 ms recommended (minimum interval at which the server notifies the client)
Queue size10 (buffer for server bursts)

Incoming messages contain msg.payload (value) + msg.topic (NodeId) + msg.timestamp.


5. Browse — Automatic Node Tree Exploration

Use this when you need to find out "which NodeIds exist" in environments with hundreds or thousands of nodes, such as KEPServerEX.

inject ─▶ OpcUa-Client (action=BROWSE, msg.payload="ns=2;i=85") ─▶ debug

The response is an array of [ {nodeId, browseName, displayName, ...} ] for the child nodes. You can process this with function to build an automatic registration flow.


6. Common Pitfalls

SymptomCause / Solution
BadIdentityTokenInvalidUsername/password wrong, or certificate not trusted. Set the client certificate to Trust in the server console
BadTypeMismatchThe DataType in OpcUa-Item differs from the actual node type
Repeated connection lost messagesThe host domain in the Endpoint URL differs from the certificate CN — reissue the certificate or match the host in the URL to the certificate CN
Subscribe fires only onceOpcUa-Subscribe only needs to "register" once. Use the inject node's once after deploy option a single time

7. Next Steps