Node-RED Client Instructions
Nodes
OpcUa-Item Node
An Item node represents an object inside the information model. It is used to query the server for the object that is defined with in the item field.
Properties#fig:item-node[1.1]:
-
The
Item
field: Used to define which object/node from the Information Model on the Server we are querying. It can be set in two ways:-
ns=int;s=string
- wherens
is the namespace in which the object resides ands
is the name of the object in the information model. -
ns=int;i=int
- wherei
is the index of the object (the index of the information model node) in the information model.
-
-
The
Type
field: Used to define the type of the object we are querying. -
The
Value
field: Can be left blank, as it is only used when creating an OPC-UA Server. -
The
Name
field: Used to set a custom name.-
NOTE: the
name
that we set in theName
field will be part of themsg
object that is used on Node-RED. It it set inmsg.browseName
field. This can be useful when filtering for a specificmsg
that carries the value of the item we are looking for.
-
OpcUa-Client Node
A Client node is used to connect to a OPC-UA Server. Client nodes work in tandem with Item nodes. Normally, an Item Node is connected to a Client node, and afterward, the Client node preforms an action with the node.
Properties#fig:client-node[1.3]:
-
The
Endpoint
field: Used to configure an connection to an endpoint that is used in the Client Node. This can be done by pressing thepen
icon.-
Properties#fig:endpoint[1.2]:
-
The
Endpoint
field: The URL of the server in the formatopc.tcp://<IP>:<PORT>
. -
Other fields: Can be left at their default values.
-
-
-
The
Action
field: Used to define what action the client node will be performing. -
Other fields can be left at their default state.
NOTE: Every Client Node creates its own connection to the OPC-UA Server, this can potentially consume a significant number of connections. To avoid this, group the Item nodes that are used in for the same action and connect them to a single Client node that preforms that action.
Tomorro [fig:client-node]
OpcUa-Browser Node
The Browser node is used to query the information model, just like the Client Node. It requires the Inject Node to run and is used for browsing the information model.
Properties#fig:browse-node[1.4]:
-
Endpoint
field : Same asEndpoint
field in the Client node. -
Topic
field : If left empty, it queries the top root nodes in the information model. Otherwise, it can be set in the same way as theTopic
field in the Item node. -
Name
field : This is an optional field for naming the node.
It is normally chained with a Inject node to run it and a Debug node to read the output (this can be done by opening the debug tab on the right of the Node-RED page)#fig:browse-link[1.5]. It outputs an array of JSON objects.
MQTT-out Node
The MQTT out node is used to publish to an MQTT broker.
Properties#fig:mqtt-node[1.7]:
-
The
Server
field: Used to set up the MQTT broker.-
Properties#fig:mqtt-broker[1.6]:
-
The
Name
field: Provides a custom name for the node. -
The
Server
field: Configures theIP
andPort
of the broker. -
Other nodes can be left at their default values.
-
-
-
The
Topic
field: Used to specify the MQTT Topic to which the information is published. -
The
Name
field: Provides a custom name for the node. -
Other fields can be left at their default values.
Dashboard Nodes
Dashboard nodes are used to visualize the information received from the
server. After setting up the dashboard, you can access the dashboard UI
at <NODE-RED URL>/ui
.
There are various types of dashboard nodes, including text and value nodes, as well as nodes for charts and gauges. For more information on the types of nodes available and how to use them, you can visit HERE or refer to the manual/help that is included as part of Node-RED..
Example of Setting Up a Client Configuration
This step-by-step example will explain how to configure a Node-RED
client-side for an OPC-UA Server. The information model for this example
contains two objects: the TempSensor
and LightSensor
.
Both objects contain four variables :
-
SensorID
- ID of the sensor. -
VendorID
- ID of the vendor of the sensor. -
CurrentTemp
orCurrentLight
- Current temperature or Current light intensity. -
Active
- Is the sensor active and operating.
The end goal is to create a Node-RED Client side, that reads the active status and CurrentTemp/CurrentLight from the respective sensors.
Step 1: Reading From The Server
Setting Up The Inject Node
First, we need an Inject Node, which is a basic node that is part of
Node-RED and can be found under the common
tab.
Most of the Inject node’s properties can be left at their default
values. Optionally it can be named and the two fields that are generated
by default can be removed. What needs to be set-up is the Repeat
field., which should be configured to interval
from the dropdown list
and set to 0.1 seconds
#fig:inject-node[2.1].
Setting Up The Item Node
The second step is to create Item nodes for the variables we want to query. Since we want to track the status and readings from the sensors, we will need four Item nodes: two nodes for the temperature sensor and two nodes for the light sensor.
The temperature sensor is in namespace 2 and the light sensor is in namespace 3. The first Item node will be for the current temperature#fig:currenttemp-node[2.2].
-
Item
field: TheCurrentTemp
variable is in namespace 2 and has an index of6011
, so we set it tons=2;i=6011
. -
Type
field:CurrentTemp
is of typeDouble
. -
Value field: This field does not need to be set up since it is only used when creating a Node-RED OPC-UA server.
-
Name
field: The name can be set to anything, it will be set toCurrentTemp
for clarity and future ease of use in other nodes.
This is repeated for the other three values we want to track.
Afterwards, we connect all four Item nodes to the Inject node#fig:inject-item[2.3].
Setting Up The Client Node
The third step is to connect the Item nodes to the Server node. Since all four Item nodes will be used to track the values of the four variables, we only need a single Client node#fig:client-node-properties[2.4].
-
Endpoint
field: We set it to one of theIP:PORT
URLs on which the server listens. -
Action
field: We decide to go withSUBSCRIBE
, we could as well go withREAD
. -
Interval
field: We set it to10 milliseconds
. -
Other fields are optional.
NOTE: In place of the IP, you can and should use a DNS name. In the
Sandbox environment use base-opc-ua-server
.
Now we connect the four Item nodes to the Client node. All four are connected to the same client node, so we save up the number of connections to the server#fig:item-client[2.5].
Step 2: Sending The Data Through MQTT
Setting Up The Function Node
This is an optional step. The Function Node is used to transform the
’msg’ object sent by the Client node. The MQTT node sends out the
’msg.payload’ field of the ’msg’ object. This means that it only sends
the value it just read but doesn’t indicate which Item node this value
is connected to. To address this, we will take the ’msg’ object and
create a new one, where ’msg.payload’ contains four fields: timeStamp,
topic (which corresponds to the item
field in the Item Nodes),
browseName and payload as seen in #fig:function-node[2.6].
Setting Up The MQTT Out Node
First, we need to set up the Server
field. To do this, click the pen
icon located to the right of the field#fig:mqtt-merge[2.7]. This action
opens a tab for configuring the broker.
Setting up the broker:
-
Server
field: Here, we enter the IP and PORT of the MQTT broker. -
Other fields can be left at their default values.
Afterward, we configure the Topic
field, to the topic which we wish to
publish on. Other fields can be left at their default settings.
image::step2-mqtt.png[Left side: Properties of the MQTT Broker. Right side: Properties of the MQTT Out node]
Now we connect the Client node to the Function node and the Function node to the MQTT out node#fig:client-func-mqtt[2.8].
Step 3: Creating The Dashboard UI
Setting Up The Text Node
The Text node is used to visualize data on the UI. It will be displayed
in the format TEXT VALUE
. This will be used to display the respective
sensor status. For the temperature sensor, create the node and set the
value of the Label
field to Temp Active
.
Since all values from all item nodes will flow down this connection, we
need to filter out the ActiveTemp
item. To do this, we use the
msg.browseName
and the Fork node#fig:switch-text[2.9].
We do the same for the ActiveLight
value.
Setting Up The Chart Node
We use the same switch node for filtering out CurrentTemp
and
CurrentLight
values, but this time connect them to Chart nodes. Also
add a Text node for both values, to display the current values.
In the properties of the Chart node, we only set up the Label
field.
We also add a Delay node, to delay the UI update times, if we wish to use it. The delay can just be set to zero or removed.
Finally, we connect all the switch nodes to the Client node and the switch nodes to the Dashboard nodes #fig:fin[2.10].
Deploying And The UI
By clicking the Deploy
button located in the top right corner, it
connects to the OPC-UA Server and the MQTT Broker, and starts reading
data.
You can access the user interface (UI) at`<Node-RED IP>/ui`#fig:ui[2.11].
Afterwards use the client.py
script to simulate posting data to the
server and displaying it on the UI.