Skip to main content

read general concepts

Let's first introduce general concepts about reading a value from an OPCUA server with the "@opcua/for-node-red" Read node.

First of all, you need to remember that the read operation will only occur when the node receives an input message.

A typical flow will look like this:

[Inject Node] --> [Read Node] --> [Debug Node]

The value and attributes that will be read depends on a set of rules that are quite important to understand.

The node can either be configured fully by its property that you set in the node configuration, or by the input message that you inject in the node.

As a general rule, the input message will take precedence over the node configuration.

Input

The read operation is triggered when the node receive an input message.

The nodeId to read can be specified in the following ways, in priority order:

  1. msg.nodeId

  2. or, if msg.nodeId is not defined ; the value of the msg.topic

  3. or, if msg.topic is not defined, the value of the msg.payload

  4. or, if msg.payload is not defined, the value of node.nodeId parameter in the node red node configuration.

note !

If you want to make sure that the node configuration is used, you have to ensure that the input message does not contain any property that may override the 'Read' node configuration.

In particular, if you use an Inject Node, you have to ensure that the msg.nodeId, msg.topic and msg.payload properties are not set, if you want to use the node configuration.

type of inputs

  1. reading a single OPCUA Variable:

    You can read a single OPCUA Variable by specifying its NodeId in the msg.nodeId or msg.topic attribute.

    see reading a single value for more details.

  2. reading multiple OPCUA Variables:

    You can read multiple OPCUA Variables by specifying an array of NodeIds in the msg.nodeId or msg.topic attribute.

    see reading multiple values with an array for more details.

  3. reading a subtree structure:

    You can read multiple nodes by specifying an array of nodeId in the msg.nodeId or msg.topic attribute. see reading multiple values with an array for more details.

  4. reading all attributes of a single OPCUA Variable:

    You can read all attributes of a single OPCUA Variable by specifying the NodeId in the msg.nodeId or msg.topic attribute, and setting the msg.attributeId to All.

    see reading all attributes for more details.

how to specify the NodeId

NodeId can be specified in different formats:

  • Direct NodeId: ns=1;s=Temperature or ns=1;i=12345
  • Unified NodeId: nsu=http://opcufoundation.org/UA/ADI;i=1234
  • BrowsePath: /2:MyDevice/1:MyTemperatureSensor/2:ParameterSet/3:Temperature
  • Aliased BrowsePath: /di:MyDevice/own:MyTemperatureSensor/di:ParameterSet/ns1:Temperature

when detecting the the nodeId provided is not a direct nodeId or Unified NodeId, @opcua for node-red will try to resolve the browsePath against the OPCUA server address space and convert it to a NodeId.

For performance reasons, this is only done once, and the result is cached in the node configuration. Cache is cleared when the connection is established or restablished after an outage, in case the OPCUA server address space has changed.

specifying attribute to read

At a glance

reminder !

The read operation is triggered when the node receive an input message.

reminder !

If you want to make sure that the node configuration is used, you have to ensure that the input message does not contain any property that may override the 'Read' node configuration.

reminder !

You can overwrite 'Read' node configuration by injecting a message with the following properties:

  • msg.nodeId
  • msg.topic
  • msg.attributeId : 'Value', 'DataType', 'BrowseName', 'DisplayName', 'All'