OPC-UA Node
You can communicate directly with external OPC-UA servers (Kepware, Ignition, other gateways) through community nodes like node-red-contrib-opcua. The same nodes are used to connect to the OPC-UA server of the gateway itself (opc.tcp://127.0.0.1:12000/opcua, NodeId ns=2;s=...).
Copy the TCP Endpoint URL and NodeId exactly from the OPC UA Server › Server Information tab in the screen menu. For more details, refer to Using OPC UA Server.
1. Node Types (node-red-contrib-opcua)
| Node | Purpose |
|---|---|
OpcUa-Endpoint | Server connection information (host/port/security/auth) — created once and shared across other nodes |
OpcUa-Item | Single node definition — converts nodeId into input |
OpcUa-Client | Main operation node for Read / Write / Browse / Method call |
OpcUa-Subscribe | Change event (MonitoredItem) subscription — receive via push without polling |
OpcUa-Event | OPC-UA Alarm & Event subscription |
2. Creating an Endpoint
Double-click the OpcUa-Client node → pencil icon next to Endpoint → New endpoint:
| Field | Value (Based on built-in gateway server) |
|---|---|
| Endpoint | opc.tcp://127.0.0.1:12000/opcua |
| Security Policy | None (Internal) or Basic256Sha256 (External Operation) |
| Security Mode | None / Sign / Sign & Encrypt |
| Login | Username/Password from the OPC UA server screen or Anonymous (if permitted) |
3. Read / Write Patterns
inject ─▶ OpcUa-Item (nodeId, msg.payload type) ─▶ OpcUa-Client (READ/WRITE) ─▶ debug
OpcUa-Item:
| Field | Value |
|---|---|
| Item | ns=2;s=SITE_00001.OPC_00303.TAG_TEST_00042 |
| DataType | Int32 (Must match the actual tag data type — otherwise results in BadTypeMismatch) |
OpcUa-Client:
| Field | Value |
|---|---|
| Action | READ or WRITE |
| Endpoint | Endpoint created above |
When performing a WRITE, fill values like msg.payload = 9999 using change before the OpcUa-Item node.
4. Subscribe — Receiving Changes Without Polling
Subscribe is significantly more efficient than polling (periodic read). There is no traffic when there are no changes, and data arrives in microseconds.
inject (once after deploy) ─▶ OpcUa-Item ×N ─▶ join (배열) ─▶ OpcUa-Subscribe ─▶ debug / function
OpcUa-Subscribe:
| Field | Value |
|---|---|
| Action | SUBSCRIBE |
| Interval | 100 ms recommended (minimum cycle for the server to notify the client) |
| Queue size | 10 (Buffer for server congestion) |
Incoming messages include msg.payload (value) + msg.topic (NodeId) + msg.timestamp.
5. Browse — Automatic Node Tree Exploration
Used when you need to identify "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, ...} ] of child nodes. This can be processed via function to create an automatic registration flow.
6. Common Pitfalls
| Symptom | Cause / Solution |
|---|---|
BadIdentityTokenInvalid | Untrusted user/password or certificate. Trust the client certificate in the server console |
BadTypeMismatch | DataType of OpcUa-Item differs from the actual node type |
| Frequent Connection Lost messages | Host domain in Endpoint URL differs from the certificate CN — reissue certificate or match URL host to certificate CN |
| Subscribe triggers only once | OpcUa-Subscribe only needs to be "registered" once. Use the once after deploy option for inject |