Skip to content

Server/Client communication

Client settings

If the server started correctly, it should be able to receive requests from clients using the tcp protocol. The client side can be implemented using an OPC UA Client driver: in this paragraph, the settings of this driver will be explained, in order to offer a valid test setup for validate the server side.

Driver options

To allow communication with the server, the basic options to be set are:

  • Endpoint IP : ip address of the server.
  • Endpoint port : tcp port
  • Server Name : name of the server to reach. In our case OpcuaServerApplication

Component creation

These options are the bare minimum necessary to connect to a server that implements a security method equal to None and a user token Anonymus, and the client wants to access with the same configuration. But if the server doesn't accept these conditions, or the clients wants to rise the security of the connection, an user must modify also the security options of the client.

First of all, the Certificate Setup must be implemented by the user, following the instruction provided by the Opc Ua Client Driver Documentation. From this moment on, it is taken for granted that this operation has been done.

Then it is necessary to change these settings:

  • Keystore path: the path to the keystore created by the Certificate Setup
  • Security policy: the encryption algorithm for signing and encryption
  • Username: the username to access the server with the User and Password user token
  • Password: the password to access the server with the User and Password user token

Component creation

The other settings can be left as they are. Now that the client’s options have been set, everything is properly configured: as said before, the first connection will fail, and the manually certificate moving must be performed to let the client connect to the server. After this last operation, the client should be able to connect to the server: if this happens, it can proceed to the read/write phase.

Clarifications

Clarification is needed to avoid being stuck using the driver: if the server is restarted while the client is connected, the latter will not always be able to reconnect automatically. For example, if the server password changes or the client user token is no longer available, the client cannot connect anymore. For this reason, the user should always "trigger" a client update, so that it can update the connection: this can be done simply by changing an option, for example changing the ip address option from 0.0.0.0 to localhost.

Channel Configuration

In the Asset section, the Node characteristics must be set, in order to correctly read or write the server data. In addition to classic options like name, value.type, and so on, the node channel options must be set as:

  • node.id : id of the resource to read
  • node.namespace.index : namespace index of the resource to read
  • opcua.type : OPC UA data type of the resource
  • node.id.type : The type of the node id (see the OPC UA driver documentation)

ClientDriverConfigChannel

Reading

If you want to read the contents of the variable SetDefVariable, the NodeId will be addressable through a node.id=2002, node.namespace.index=2, opcua.type=Int32 and node.id.type=NUMERIC : if the reading is successful, the the expected result will be 123456.

Defined variable reading

The same steps performed, instead, on a node.id=2003 and node.namespace.index=2, lead to the reading of the NotSetDefaultVariable variable: the expected result of this reading is instead a null value, as no default value has been assigned to this variable. Specificly for the OPC UA Client driver, the reading procedure will fail, as the null value is not accepted.

Writing

Regarding writing, you can change the value of a variable, always selecting it through the node.id and node.namespace.index: in this case, if the operation is successful, the value of the variable will be changed.

Warning: if the server settings are changed, the server will be restarted, so the xml file variables will be reloaded and have the default values.

A write operation can be used to set the value of a null variable. As depicted in the picture, the reading procedure initially fails, but after the writing operation, the same variable can be read.

Undefined variable reading

Undefined variable reading after writing

Monitoring a variable

From the client driver it is also possible to monitor the status of a variable using an OPC UA subscription. This can be enabled by using the "listen" mode. The server component will send a notification to the clients who monitor a variable when its value changes.

For example, if one client monitors the SetDefVariable variable, and another user changes its value, the server will notify all those who are tracking that variable, reporting the new value assumed by that variable.