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].
-
Itemfield: TheCurrentTempvariable is in namespace 2 and has an index of6011, so we set it tons=2;i=6011. -
Typefield:CurrentTempis 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.
-
Namefield: The name can be set to anything, it will be set toCurrentTempfor 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].
-
Endpointfield: We set it to one of theIP:PORTURLs on which the server listens. -
Actionfield: We decide to go withSUBSCRIBE, we could as well go withREAD. -
Intervalfield: 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].