node-red-contrib-opcua

raw JSON →
0.2.351 verified Sat Apr 25 auth: no javascript

A Node-RED node collection for OPC UA communication and server functionality, based on the node-opcua library. Current stable version is 0.2.351, released regularly with active maintenance. It provides client nodes to read, write, subscribe, browse, and invoke methods on OPC UA servers, plus server nodes to create variable and method nodes. Key differentiators include tight integration with Node-RED's flow-based programming model and support for complex OPC UA features like subscriptions, monitored items, events, and array index ranges. Compared to generic OPC UA SDKs, it abstracts connection management and message parsing into easy-to-configure nodes.

error Error: Cannot find module 'node-opcua'
cause Missing or incomplete installation of node-opcua dependency.
fix
Run 'npm install node-opcua' in the Node-RED user directory or globally.
error Error: connect ECONNREFUSED <ip>:4840
cause OPC UA server is not running or is blocked by firewall.
fix
Check OPC UA server status and ensure port 4840 is open on server and client firewall.
error BadNodeIdInvalid: BadNodeIdInvalid
cause The nodeId string format is incorrect.
fix
Ensure nodeId follows pattern 'ns=<namespaceIndex>;<identifierType>=<identifier>' (e.g., 'ns=2;s=MyVariable').
error StatusCode: BadSessionIdInvalid
cause Session expired or invalid session token.
fix
Reconnect the OpcUa-Client node (e.g., deploy flow again or trigger reconnect).
error SecurityError: Certificate verification failed
cause OPC UA client certificate rejected by server (PKI issue).
fix
Place client's self-signed certificate in server's trusted certificate store, or disable certificate verification (not recommended).
breaking From v0.2.223, namespace index used with variables for set value; flows using older version may need adjustment.
fix Update to v0.2.223+ and ensure variable nodes have correct namespace index.
deprecated The node-opcua library has undergone major API changes; some deprecated methods may cause warnings.
fix Update to latest node-opcua and this package, check node-opcua migration guides.
gotcha Payload must include both nodeId and datatype in topic field for read/write operations.
fix Format topic as 'ns=<namespace>;s=<identifier>;datatype=<DataType>' (e.g., 'ns=3;s=Counter;datatype=Int32').
breaking Node.js 15 minimum required (engines field). Older Node.js versions may cause installation failures.
fix Upgrade Node.js to version 15 or later.
gotcha Firewall blocks: OPC UA uses dynamic ports for discovery; ensure network allows OPC UA TCP (port 4840 by default) and discovery endpoints.
fix Configure firewall to allow OPC UA traffic, or set specific client/server ports.
deprecated action field 'monitor' is deprecated; use 'subscribe' instead.
fix Use action='subscribe' with interval and queueSize parameters.
npm install node-red-contrib-opcua
yarn add node-red-contrib-opcua
pnpm add node-red-contrib-opcua

Installation and minimal flow to read an OPC UA variable using OpcUa-Client and OpcUa-Item nodes.

// No code snippets needed - this is a Node-RED node collection.
// To use: Install Node-RED, then run:
// npm install node-red-contrib-opcua
// Then in Node-RED flows, drag OpcUa-Client, OpcUa-Item, OpcUa-Server nodes.
// Example flow (JSON) to read a variable:
// [{"id":"n1","type":"OpcUa-Item","name":"example-item","topic":"ns=2;s=MyVariable","datatype":"Int32"},
//  {"id":"n2","type":"OpcUa-Client","name":"example-client","endpoint":"opc.tcp://localhost:4840","action":"read","items":["n1"]},
//  {"id":"n3","type":"inject","name":"trigger","topic":"","payload":"","repeat":"","crontab":"",once":false},
//  {"id":"n4","type":"debug","name":"output"},
//  {"id":"n3","wires":[["n2"]]}, {"id":"n2","wires":[["n4"]]}]