### Install node-red-contrib-opcua Source: https://github.com/mikakaraila/node-red-contrib-opcua/blob/master/Readme.md Run this command in your Node-RED installation directory to install the package. Alternatively, use the global installation command. ```bash npm install node-red-contrib-opcua ``` ```bash npm install -g node-red-contrib-opcua ``` -------------------------------- ### Write Multiple OPC UA Items Source: https://github.com/mikakaraila/node-red-contrib-opcua/blob/master/Readme.md This example demonstrates how to write multiple items. Ensure the payload contains the necessary nodeId, datatype, and value for each item. ```javascript // msg.payload = [ { nodeId: "ns=1;s=MyVar", dataType: "Int32", value: 10 }, ... ] ``` -------------------------------- ### Server Commands: addFolder, addVariable, addMethod, setFolder Source: https://github.com/mikakaraila/node-red-contrib-opcua/blob/master/Readme.md The server sub-flow supports commands to add folders, variables, and methods, as well as set folder properties. Refer to the OPCUA-TEST-NODES.json example flow for details. ```javascript // Example: msg.payload = { command: "addFolder", name: "MyNewFolder" } // Example: msg.payload = { command: "addVariable", name: "MyNewVar", dataType: "Int32", value: 0 } // Example: msg.payload = { command: "addMethod", name: "MyMethod", arguments: ["Int32"], outputArgs: ["Int32"] } // Example: msg.payload = { command: "setFolder", nodeId: "ns=1;s=MyFolder", browseName: "UpdatedFolderName" } ``` -------------------------------- ### Register Namespace and Get Index Source: https://github.com/mikakaraila/node-red-contrib-opcua/blob/master/Readme.md Use 'registerNamespace' and 'getNamespaceIndex' server commands to manage namespaces. This allows adding variables with custom namespaces, like ns=5. ```javascript // Example: msg.payload = { registerNamespace: "MyCustomNamespace" } // Example: msg.payload = { getNamespaceIndex: "MyCustomNamespace" } ``` -------------------------------- ### Read/Write Partial Array Source: https://github.com/mikakaraila/node-red-contrib-opcua/blob/master/Readme.md When working with arrays, you can specify a range in msg.payload.range to read or write specific elements. For example, '2:4' selects elements from index 2 to 4. ```javascript // Example for reading/writing a portion of an array // msg.payload.range = "2:4" ``` -------------------------------- ### Server User Management Source: https://github.com/mikakaraila/node-red-contrib-opcua/blob/master/Readme.md Define users for the server in Users.json. Each user entry should include username, password, and role for access control. ```json // Users.json example // [ // { "username": "user", "password": "password", "role": "admin" }, // ... // ] ``` -------------------------------- ### Add File Command Source: https://github.com/mikakaraila/node-red-contrib-opcua/blob/master/opcua/104-opcuaserver.html Use the 'addFile' command to add a file to the OPC UA address space. Specify the file path in 'fileName'. ```json { "opcuaCommand": "addFile", "fileName": "c:/temp/test.txt" } ``` -------------------------------- ### 2D and 3D Array Support Source: https://github.com/mikakaraila/node-red-contrib-opcua/blob/master/Readme.md The server node supports 2D and 3D arrays. Define the array dimensions in the topic, e.g., 'ns=1;s=Float2D;datatype=FloatArray[5,5]' for a 2D array. ```javascript // Example for 2D array // ns=1;s=Float2D;datatype=FloatArray[5,5] // Example for 3D array // ns=1;s=Float3D;datatype=FloatArray[5,5,5] ``` -------------------------------- ### Set Folder/Variable Access Level and Permissions Source: https://github.com/mikakaraila/node-red-contrib-opcua/blob/master/Readme.md Utilize the opcua-rights node to define access levels, roles, and permissions for folders and variables. ```javascript // Example: msg.payload = { nodeId: "ns=1;s=MySecureVar", accessLevel: "1", role: "user", permissions: "read" } ``` -------------------------------- ### Add Variable with Initial Value Source: https://github.com/mikakaraila/node-red-contrib-opcua/blob/master/Readme.md Set an initial value for a server variable when creating it. The server will return the nodeId of the created variable. ```javascript // Example: msg.payload = { name: "MyVariable", dataType: "Int32", value: 100, initialValue: 50 } ``` -------------------------------- ### OPC UA Server Commands via JSON Inject Source: https://github.com/mikakaraila/node-red-contrib-opcua/blob/master/opcua/104-opcuaserver.html Use JSON inject nodes to send commands to the OPC UA Server. Specify the command in 'opcuaCommand' and provide necessary parameters like 'nodeName' or 'nodeId'. ```json { "opcuaCommand": "addEquipment", "nodeName": "Machine" } ``` ```json { "opcuaCommand": "restartOPCUAServer" } ``` ```json { "opcuaCommand": "addPhysicalAsset", "nodeName": "PhysicalAsset" } ``` ```json { "opcuaCommand": "deleteNode", "nodeId": "ns=4;s=PhysicalAsset2" } ``` -------------------------------- ### Register OPC UA Client Node Source: https://github.com/mikakaraila/node-red-contrib-opcua/blob/master/opcua/102-opcuaclient.html Registers the OPC UA Client node with Node-RED, defining its properties, inputs, outputs, and UI elements. Includes logic for dynamically showing/hiding input fields based on the selected action. ```javascript RED.nodes.registerType('OpcUa-Client', { category: 'opcua', color: "#3FADB5", defaults: { endpoint: {value: "", required: true, type: "OpcUa-Endpoint"}, action: {value: "read", required: true}, deadbandtype: {value: "a"}, deadbandvalue: {value: 1}, time: {value: 10}, timeUnit: {value: "s"}, // These are fixed or can be read through endPoint certificate: {value: "n"}, localfile: {value: ""}, localkeyfile: {value: ""}, securitymode: {value: "None"}, securitypolicy: {value: "None"}, useTransport: {value: false, required: false}, maxChunkCount: {value: 1, required: false}, maxMessageSize: {value: 8192, required: false}, // should be at least 8192 receiveBufferSize: {value: 8192, required: false}, sendBufferSize: {value: 8192, required: false}, setstatusandtime: {value: false, required: true}, keepsessionalive: {value: false, required: true}, name: {value: ""}, applicationName: {value: "", required: false}, applicationUri: {value: "", required: false} }, inputs: 1, outputs: 3, align: "right", icon: "opcuanodeLogo.png", label: function () { return this.name || "OPC UA Client"; }, labelStyle: function () { return this.name ? "node_label_italic" : ""; }, oneditprepare: function () { var node = this; try { var keepsessionaliveCheckbox = $("#node-input-keepsessionalive"); keepsessionaliveCheckbox.prop('checked', node.keepsessionalive); var inputAction = $("#node-input-action"); var inputTime = $("#node-input-timerow"); var inputDeadband = $("#node-input-deadband"); change_time_input(); // first to fit config now inputAction.change(change_time_input); } catch (err) { node.error(err); } function change_time_input() { if (inputAction.val() == "subscribe" || inputAction.val() == "events" || inputAction.val() == "monitor") { inputTime.show(); } else { inputTime.hide(); } if (inputAction.val() == "monitor") { inputDeadband.show(); } else { inputDeadband.hide(); } } } }); ``` -------------------------------- ### Server Node Security Settings Source: https://github.com/mikakaraila/node-red-contrib-opcua/blob/master/Readme.md Configure security settings for the server node, including mode and policy, to control access and communication security. ```json // Server security settings example // mode: "SecurityMode.None", "SecurityMode.Sign", "SecurityMode.SignAndEncrypt" // policy: "SecurityPolicy.Basic256Sha256", "SecurityPolicy.Basic128Sha256", "SecurityPolicy.None" ``` -------------------------------- ### Read Multiple OPC UA Items Source: https://github.com/mikakaraila/node-red-contrib-opcua/blob/master/Readme.md To read multiple items, set the message topic to 'readmultiple' and the payload to 'ALL'. The server will return all values. ```javascript msg.topic = "readmultiple" msg.payload = "ALL" ``` -------------------------------- ### Define OPC UA Variables Source: https://github.com/mikakaraila/node-red-contrib-opcua/blob/master/Readme.md Use the OpcUa-Item node to define variables for communication with OPC UA servers. This is a fundamental step before interacting with the server. ```javascript // OpcUa-Item node configuration example // topic: ns=3;s=Counter;datatype=Int32 ``` -------------------------------- ### Register OPC UA Rights Node Source: https://github.com/mikakaraila/node-red-contrib-opcua/blob/master/opcua/108-opcuarights.html Registers the 'OpcUa-Rights' node type with Node-RED, defining its default properties, inputs, outputs, and appearance. This code sets up the node's configuration including various access level and permission defaults. ```javascript RED.nodes.registerType('OpcUa-Rights', { category: "opcua", color:"#3FADB5", defaults: { accessLevelCurrentRead: {value: true}, accessLevelCurrentWrite: {value: true}, accessLevelStatusWrite: {value: true}, accessLevelHistoryRead: {value: true}, accessLevelHistoryWrite: {value: true}, accessLevelSemanticChange: {value: true}, role: {value: "a"}, // User Role like Anonymous, Operator, Engineer,... // Permissions permissionBrowse: {value: true}, permissionRead: {value: true}, permissionWrite: {value: true}, permissionWriteAttribute: {value: true}, permissionReadRole: {value: true}, permissionWriteRole: {value: true}, permissionReadHistory: {value: true}, permissionWriteHistory: {value: true}, permissionInsertHistory: {value: true}, permissionModifyHistory: {value: true}, permissionDeleteHistory: {value: true}, permissionReceiveEvents: {value: true}, permissionCall: {value: true}, permissionAddReference: {value: true}, permissionRemoveReference: {value: true}, permissionDeleteNode: {value: true}, permissionAddNode: {value: true}, name: {value: ""}, }, inputs: 1, outputs: 1, align: "right", icon: "opcuanodeLogo.png", label: function () { return this.name || "OPC UA Rights"; }, labelStyle: function () { return this.name ? "node_label_italic" : ""; } }); ``` -------------------------------- ### OPC UA Endpoint Configuration Form Source: https://github.com/mikakaraila/node-red-contrib-opcua/blob/master/opcua/105-opcuaendpoint.html HTML form elements for configuring an OPC UA endpoint. Includes fields for name, endpoint URL, security policy, security mode, and authentication options. ```html
Anonymous
use credentials
user certificate