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.

Which one decides is your choice, made on the prefix of the NodeId field: a message always triggers the read; whether it also targets it is a setting. See Where does the NodeId come from?.

Input

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

Where the nodeId comes from is decided by the NodeId source, the first stop of the prefix next to the field:

  • this node — the configured value is always used, whatever the message contains. This is what a node you create today starts on.
  • this node, templated — the configured value is a template such as ns=1;s={{msg.payload.name}} that the message fills in.
  • the message — the field holds a message path (nodeId, topic, payload, …) and the value found there is used.
You no longer have to strip properties off the message

Older documentation told you to make sure msg.nodeId, msg.topic and msg.payload were unset if you wanted your configured NodeId to be used. That workaround is what the NodeId source replaces: pick this node and the message cannot override the value at all — wire any Inject Node you like.

Flows saved before version 3.40 have no source and keep the historical precedence (msg.nodeIdmsg.topicmsg.payload → the configured NodeId). See Where does the NodeId come from? for the full story.

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'