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=...).
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)
| Node | Purpose |
|---|---|
OpcUa-Endpoint | Server connection information (host/port/security/auth) — create once and share across other nodes |
OpcUa-Item | Single node definition — converts nodeId into an input |
OpcUa-Client | Main action node for Read / Write / Browse / Method call |
OpcUa-Subscribe | Subscribes to change events (MonitoredItem) — receive by push instead of polling |
OpcUa-Event | Subscribes to OPC-UA Alarm & Event |
2. Creating an Endpoint
Double-click the OpcUa-Client node → pencil icon next to the Endpoint field → new endpoint:
| Item | Value (based on the gateway's built-in server) |
|---|---|
| Endpoint | opc.tcp://127.0.0.1:12000 |
| Security Policy | None (internal) or Basic256Sha256 (external operation) |
| Security Mode | None / Sign / Sign & Encrypt |
| Login | Username/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:
| Item | Value |
|---|---|
| Item | ns=2;s=SITE_00001.OPC_00303.TAG_TEST_00042 |
| DataType | Int32 (must match the actual tag data type — a mismatch causes BadTypeMismatch) |
OpcUa-Client:
| Item | Value |
|---|---|
| Action | READ or WRITE |
| Endpoint | The 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:
| Item | Value |
|---|---|
| Action | SUBSCRIBE |
| Interval | 100 ms recommended (minimum interval at which the server notifies the client) |
| Queue size | 10 (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
| Symptom | Cause / Solution |
|---|---|
BadIdentityTokenInvalid | Username/password wrong, or certificate not trusted. Set the client certificate to Trust in the server console |
BadTypeMismatch | The DataType in OpcUa-Item differs from the actual node type |
| Repeated connection lost messages | The 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 once | OpcUa-Subscribe only needs to "register" once. Use the inject node's once after deploy option a single time |