OPC-UA Protocol Adapter
This section presents the capabilities and configuration options of the OPC UA Protocol Adapter, which translates the OPC UA communication protocol into objects understandable by the Gateway Agent.
For a step-by-step guide on how to install the OPC UA Protocol Adapter, see the Installation Guide.
Configuring the OPC UA Protocol Adapter
There are two configuration files of the OPC UA Protocol Adapter:
Deployment configuration file - Configuration of the MQTT connection, PMQ connection and health monitoring.
Application configuration file - Configuration of connections, global adapter properties and device data (measurements, alerts, configuration parameters and metadata).
When you modify the OPC UA Protocol Adapter configuration, restart the adapter to apply the changes by means of the following command:
systemctl restart gwa-opc-ua-adapter-c
The adapter configuration is then updated.
For an example of the OPC UA Protocol Adapter configuration files, see here.
Deployment Configuration File
The deployment configuration file of the OPC UA Protocol Adapter is located at:
/etc/relayr/gwa-opc-ua-adapter-c/gwa-opc-ua-adapter-config.json
To modify the file, edit it in a text editor.
The following configuration settings are available:
transport
- Communication channel used by the adapter. Available options:mqtt
orpmq
. By default,mqtt
.mqtt_connection
- Connection settings of the MQTT message broker:
Configuration Setting | Description | Default Value |
---|---|---|
host | IP address of the MQTT message broker. | localhost |
port | Port number for connecting to the MQTT broker. | 1883 |
keepalive | Keepalive value of the MQTT connection. | 20 |
max_inflight_messages | Maximum number of QoS 1 or 2 messages that can be in the process of being transmitted simultaneously. This includes messages currently going through handshakes and messages that are being retried. If set to 1 , it guarantees an in-order delivery of messages. | 100 |
qos_levels | Quality of Service level for each traffic type. | measurements: 0 , alerts: 1 . configuration: 1 , metadata: 1 |
health_monitor
- Health monitoring settings:
Configuration Setting | Description | Default Value |
---|---|---|
heartbeat_interval | Time interval at which the periodic heartbeat messages are sent, given in seconds. | 60 |
pmq_connection
- Configuration of the High Speed Bus (PMQ) connection. Configure this section to use thepmq
transport
:
Configuration Setting | Description | Default Value |
---|---|---|
output_queues | List of output PMQ queues, where the adapter reports all data, except for health monitoring messages, which are always reported via MQTT. Queue names must begin with / . | ["/opc-ua_out_queue"] |
input_queues | List of PMQ queues to monitor for inbound messages, e.g. configuration update tasks. Queue names must begin with / . | ["/opc-ua_in_queue"] |
message_size | Maximum size of a PMQ message, given in bytes. | 8192 |
message_count | Maximum number of messages in a PMQ queue. | 10 |
For an example of the deployment configuration file, see here.
Application Configuration File
The application configuration file of the OPC UA Protocol Adapter is located at:
/etc/relayr/gwa-opc-ua-adapter-c/gwa-opc-ua-adapter-application-config.json
If you have the Configuration Manager installed, it becomes the primary way of editing application configuration files. If you do not have the Configuration Manager, edit the application configuration file in a text editor.
See sections below for information on:
Connections - List of connections to devices.
Security - Configuring a secure connection with the X.509 certificates.
Global Adapter Properties - Configuration of a global sampling interval and custom prefix.
Devices - List of connected devices and their measurements, alerts, configuration parameters and metadata.
For an example of the application configuration file, see here.
Configuring OPC UA Connections
The connections
section of the configuration file allows you to define a list of
device connections. For each of the configured connections, configure the following settings:
Configuration Setting | Description |
---|---|
id | Unique connection identifier, which is then used to identify a device connection. See the Configuring a Device Connection section for more information. |
url | URI (Uniform Resource Identifier) of the OPC UA Endpoint. |
application_uri | URI that the adapter uses to connect to the server. It needs to match the client certificate if one is used. Optional field, defaults to urn:relayr.gwa.adapter . See here for more information on using certificates. |
username | Username for the OPC UA Endpoint, used when authenticating on the server. Optional field. |
password | Password for the OPC UA Endpoint, used when authenticating on the server. Optional field. |
security | Optional configuration section. If configured, the adapter connects using one of the OPC UA security policies. See the section below for more information on configuring security. |
namespaces_map | Optional setting. An array of namespaces that enable dynamic namespace URI mapping to appropriate indices on an OPC-UA server. Specified namespaces are automatically translated to their corresponding indices on every re-connection to the server. You can use these indices in the data_path setting in the object configuration using the @n convention. |
Here is an example of the connections
configuration:
{
"id": "OpenOpcUaServer",
"url": "opc.tcp://127.0.0.1:4840/",
"application_uri": "urn:open62541.application",
"username": "relayr",
"password": "adapter",
"security": {},
"namespaces_map": ["namespaceURI"]
}
Configuring Security
The OPC UA Protocol Adapter allows you to configure a secure connection with the OPC UA server, with the use of standard X.509 certificates in the DER format.
To enable security, add the security
configuration section to the connections configuration. The following security configuration options are available:
Configuration Setting | Description |
---|---|
client_certificate | Path to the client's certificate. |
client_private_key | Path to the client's private key. |
server_certificate | Path to the server's certificate (optional). |
encryption | Use an encrypted connection to the server (optional, defaults to false). |
Example:
{
"security": {
"client_certificate": "path/to/certificate",
"client_private_key": "path/to/private_key",
"server_certificate": "path/to/server_certificate",
"encryption": true
}
}
Most server implementations require the client's application URI to be present in the certificate's Alternative Name section. You must provide the same application URI in the connections section of the OPC UA Protocol Adapter's configuration.
Generating Certificates
The OPC UA Protocol Adapter allows you to generate certificates for a secure connection.
In the certs
directory, you can find the generate.sh
script with an example of creating certificates. Running this script creates a key and a self-signed certificate pair in the DER format. The certificate is issued to the default adapter's URI: urn:relayr.gwa.adapter
.
You can edit the generate.sh
script to adjust the generated certificates to your needs.
Global Adapter Properties
You can configure the following global settings that refer to the whole Protocol Adapter configuration:
Configuring Sampling Interval
The sampling interval determines how often the Agent gathers data from devices. It is a global setting that refers to retrieving data from all the connected devices.
The interval value is defined in milliseconds:
"sampling_interval" : 4000
Optionally, you can also define a local sampling interval for each object defined
in the devices
section of the configuration file. In such a case, a local sampling
interval overrides the global one.
Example: The global sampling interval is set to
4000
and the sampling interval for a temperaturemeasurement
object is2000
, so the Agent retrieves data about this temperature object every two seconds.
If you configure a local sampling interval for each object defined in the
devices
section, you do not need to configure a global sampling interval. However, if at least one object has no local sampling interval defined, the global one must be provided. Otherwise, the adapter configuration is invalid.
Configuring Custom Prefix
The custom prefix determines where to report data. If not defined, all data is reported to v1/sb
, by default.
The custom_prefix
option enables setting a different prefix to publish data e.g. to a custom MQTT topic for local data processing, or directly to the Gateway Agent northbound interface.
It is a global setting that refers to all data retrieved from devices.
Example:
"custom_prefix": "v1/nb"
Optionally, you can also define a local custom prefix for each measurement, alert, configuration parameter and metadata configured in the devices section of the configuration file. In such a case, a local custom prefix overrides the global one.
Instead of the
custom_prefix
option, you can also use thecustom_mqtt_prefix
option, which was implemented in the older adapter versions. However, it is recommended to usecustom_prefix
.
Configuring a List of Devices
In the devices
section of the configuration file, you can configure a list of devices. For each device, the following configuration sections are available:
connection - Selecting a device connection.
measurements - List of measurements that can be reported by a device.
alerts - List of alerts that can be reported by a device.
configuration - Configuration parameters of a device.
metadata - List of metadata of a device.
The devices
section has the following structure:
"devices" :
[
{
"connection" : { ... },
"measurements" : [ ... ],
"alerts" : [ ... ],
"configuration" : [ ... ],
"metadata" : [ ... ]
}
]
Configuring a Device Connection
In the connection.id
field, enter the connection identifier for a given device. Possible ID values are defined in the connections
section of the configuration file. See the Configuring OPC UA Connections section for details.
It is mandatory to configure a connection ID for each device.
Here is an example of the device connection configuration:
"devices": [
{
"connection": {
"id": "dev"
},
You can also configure a local connection ID for a specific measurement, alert, configuration parameter and metadata. If defined, the local connection ID overrides the global one, set in the
connection.id
field.
Configuring Measurements
You can define multiple measurements for a device, such as: temperature, humidity, pressure, etc.
To configure a measurement, define the following mandatory settings:
Configuration Setting | Description |
---|---|
id | Measurement identifier. A value provided here must match the measurement ID set in the device model version created in the relayr Cloud. For more information on creating device models and versions in the relayr Cloud, refer to the relayr Cloud API documentation. |
object | Protocol-specific object definition. See the OPC UA Object Definition section for details. |
Optionally, you can define the following advanced settings for a measurement:
Configuration Setting | Description |
---|---|
filters.cov | Change of value functionality. If it is set to enabled , measurements are reported by a device only if their value differs from the latest reported value by at least a cov_delta value. |
filters.cov_delta | Delta for the change of value functionality. It specifies the minimum change of value (in relation to the latest reported value) that is required to report the measurement to the Agent. |
sampling_interval | Local sampling interval value, given in milliseconds, that overrides the global sampling interval. |
custom_prefix | Prefix of the MQTT topic that the object is reported to. An option to publish data to a custom MQTT topic for a local data processing or directly to the northbound interface. For example, if it is set to analytics for a temperature measurement, all data is published to the topic analytics/{did}/measurements/temperature . It overrides the global custom prefix. |
connection | Local connection ID used for a given measurement. It overrides the global connection set for the device. Possible ID values are defined in the connections section of the configuration file. See the Configuring OPC UA Connections section for details. |
complex | Add this configuration section to configure a complex measurement. Specify how many data samples a complex measurement contains and, optionally, a collection_interval . For more information, see the Configuring Complex Measurements section. |
Here is an example of the measurement configuration:
{
"id" : "temperature",
"object" : { ... },
"sampling_interval" : 4000,
"filters" : {
"cov" : "enabled",
"cov_delta" : 0.04
}
},
Example: In the example presented above, the temperature reading is reported by the device every four seconds (as defined in the
sampling_interval
field). The change of value (cov
) is enabled, and thecov_delta
is set to0.04
. It means that the temperature is reported only if it is different from the latest reported value by at least0.04
.
Configuring Complex Measurements
A complex measurement is a batch of measurement data, in which several samples of collected data values are published as a single message.
Complex measurements can be consumed by the Rule Engine and the GWA Analytics for further data processing and can be stored in the Storage Service. The Cloud Adapter supports publishing complex measurements to the relayr Cloud.
You can configure the size of a complex measurement by specifying how many data samples each batch contains. Optionally, you can also specify a collection interval. If specified, the adapter starts collecting data at every collection interval (e.g. 1h) and publishes a complex measurement when a configured number of samples are collected (e.g. 1000). Then, the adapter waits for the next collection interval and starts to acquire data again.
To configure a complex measurement, add the complex
section to the measurement configuration with the following settings:
Configuration Setting | Description |
---|---|
samples | Number of collected data samples in a complex measurement. For complex measurements, this setting is mandatory. |
collection_interval | Optional setting. Time interval, given in seconds, at which the adapter starts to acquire data for a complex measurement. |
Example:
{
"object": {},
"complex":
{
"samples": 10,
"collection_interval": 3600
}
}
If the
collection_interval
is lower than needed to collect the configured number of samples, the adapter collects data continuously. It starts to acquire data immediately after publishing the previous complex measurement.
If sensors stop sending data in the middle of data collection, e.g. due to connectivity problems, the adapter waits until the required number of samples are collected, despite the collection intervals. It publishes a complex measurement that contains data points not evenly distributed in time, e.g. with a 5h gap. Such a complex measurement may be considered as incorrect and may be discarded by the Rule Engine and/or the GWA Analytics, based on the
startTs
andendTs
values.
Complex Measurement Message
The collected data samples of a configured complex measurement are published as a complex measurement message. The Protocol Adapters support acquiring and publishing complex measurements in the time domain, but you can also use complex measurement messages to publish measurements in other domains, e.g. the frequency domain.
Complex measurements in the frequency domain may be reported by the Pico Adapter, or you may use the Rule Engine or the GWA Analytics to calculate them from the time-based measurements.
In a complex measurement message:
startTs
is a moment when data acquisition begins.endTs
is a moment when data acquisition finishes.xStart
is the first value on the X axis. ThexStart
unit depends on the measured value. For measurements in the time domain, it is a timestamp indicating the moment when the first data sample is collected. For measurements in the frequency domain, it is the first frequency on the X axis.xStep
represents a resolution of data on the X axis. For measurements in the time domain,xStep
is a time interval between consecutive data samples, given in milliseconds (you configure this interval in thesampling_interval
setting of the Protocol Adapters' configuration). ThexStep
value allows you to know the precise moment when each data sample was collected. For measurements in the frequency domain,xStep
represents the frequency resolution of data representation on the X axis.yValues
is an array of ordered measurement values.
Example 1: time-based measurement:
v1/sb/{UUID}/complex_measurements/temperature {
“id”:“temperature”,
“startTs”: 1492515087123,
“endTs”: 1492515092123,
“xStart”: 1492515087123,
“xStep”: 1000,
“yValues”: [42, 43, 39, 37, 40, 48, 45, 40, 38, 33, 30, 31...]
}
In this example,
temperature
is a time-based measurement. ThexStart
value is1492515087123
, which shows the moment when the first data sample (42
) was collected. ThexStep
value is1000
, which means that consecutive data samples were collected at the interval of 1000 milliseconds.
Example 2: frequency-based measurement:
v1/sb/{UUID}/complex_measurements/acceleration_xaxis_fft {
“id”:“acceleration_xaxis_fft”,
“startTs”: 1492515087123,
“endTs”: 1492515092123,
“xStart”: 90,
“xStep”: 10,
“yValues”: [3, 12, 48, 579, 644, 689, 711, 647, 78, 644, 669, 112, 638, 652, 617, 48...]
}
In this example,
acceleration_xaxis_fft
is a frequency-based measurement. ThexStart
value is90
, which shows that the first frequency on the X axis is 90 Hz. ThexStep
value is10
, which means that the frequency step on the X axis, between consecutive data samples, is 10 Hz.
Configuring Alerts
In the alerts
configuration section, you can define alerts for the configured devices.
To configure an alert, define the following mandatory settings:
Configuration Setting | Description |
---|---|
id | Alert identifier. A value provided here must match the alert ID of the device model created in the relayr Cloud. For more information on creating device models and versions in the relayr Cloud, refer to the relayr Cloud API documentation. |
measurement_id | Identifier of a measurement associated with the alert. The ID provided here must be configured in the measurements section of the configuration file. See the section above for details. Alternatively, you can configure the object section for an alert. See here for details. |
threshold_set | Threshold value based on which the alert is activated. |
logic_set | Logical relation for alert activation. Possible values are: "<", ">", "==", "">=", "<=". |
message_set | Message sent when the alert is activated. It is a free-form string. |
threshold_clear | Threshold value based on which the alert is cleared. |
logic_clear | Logical relation for clearing the alert. Possible values are: "<", ">", "==", "">=", "<=". |
message_clear | Message displayed when the alert is cleared. It is a free-form string. |
If both the
logic_clear
andlogic_set
conditions are fulfilled at the same time, the alert is set.
Optionally, you can define the following advanced settings for an alert:
Configuration Setting | Description |
---|---|
sampling_interval | Local sampling interval value, given in milliseconds, that overrides the global sampling interval. |
custom_prefix | Prefix of the MQTT topic that the object is reported to. An option to publish data to a custom MQTT topic for a local data processing or directly to the northbound interface. For example, if it is set to analytics for a temperature-based alert, all data is published to the topic analytics/{did}/alerts/alert_temp_high . It overrides the global custom prefix. |
connection | Local connection ID used for a given alert. It overrides the global connection set for the device. Possible ID values are defined in the connections section of the configuration file. See the Configuring OPC UA Connections section for details. |
Here is an example of the alert configuration:
{
"id" : "alert_temp_high",
"measurement_id" : "temperature",
"threshold_set" : 38.5,
"logic_set" : ">=",
"message_set" : "TEMPERATURE IS TOO HIGH",
"threshold_clear" : 36.5,
"logic_clear" : "<=",
"message_clear" : "ALERT IS CLEAR",
"sampling_interval" : 4000
}
In the example presented above, the alert is activated if the temperature reaches a level defined in the
threshold_set
andlogic_set
fields, that is: if it is greater than or equal to 38.5. The message "TEMPERATURE IS TOO HIGH" is sent to the relayr Cloud when the alert is set.
When the temperature decreases and it is smaller than or equal to 36.5 (as specified in thethreshold_clear
andlogic_clear
fields), the alert is deactivated and the message "ALERT IS CLEAR" is sent to the relayr Cloud when the alert is deactivated.
The value provided in thesampling_interval
field means that the system verifies the alert data every four seconds.
Configuring Configuration Parameters
In the configuration
section, you can define the device configuration parameters.
To define a configuration parameter, define the following mandatory settings:
Configuration Setting | Description |
---|---|
id | Configuration object identifier. |
object | Protocol-specific object definition. See the OPC UA Object Definition section for details. |
Optionally, you can define the following advanced settings for a configuration parameter:
Configuration Setting | Description |
---|---|
ro | This setting determines if a given configuration parameter is read-only (if set to true ) or the read/write permissions are granted to it (if set to false ). If no ro value is defined, the object has read/write permissions, by default. |
sampling_interval | Local sampling interval value, given in milliseconds, that overrides the global sampling interval. |
custom_prefix | Prefix of the MQTT topic that the object is reported to. An option to publish data to a custom MQTT topic for a local data processing or directly to the northbound interface. For example, if it is set to analytics for a configuration parameter xyz , all data is published to the topic analytics/{did}/configuration/xyz . It overrides the global custom prefix. |
connection | Local connection ID used for a given configuration parameter. It overrides the global connection set for the device. Possible ID values are defined in the connections section of the configuration file. See the Configuring OPC UA Connections section for details. |
Here is an example of the configuration settings:
{
"id" : "parameter2045",
"object" : { ... },
"sampling_interval" : 4000,
"ro" : true
},
Configuring Metadata
The metadata
section of the configuration file allows you to define device attributes, such as the device ID, model, version, location, owner's email address, etc.
There are two ways to configure metadata:
Static metadata - metadata is an
id
andvalue
pair. It is sent only once, at the application startup.Dynamic metadata - metadata has a defined
object
. It is reported not only at the application startup, but also when the metadata value changes.
Static Metadata
Static metadata is configured as an id
and value
pair.
Static metadata is reported only once, at the application startup. To provide support for reporting a changing metadata value, configure dynamic metadata.
To configure the device static metadata, define the following values:
Configuration Setting | Description |
---|---|
id | Metadata identifier. |
value | Metadata value. |
Optionally, you can configure the following metadata settings:
Configuration Setting | Description |
---|---|
custom_prefix | Prefix of the MQTT topic that the object is reported to. An option to publish data to a custom MQTT topic for a local data processing or directly to the northbound interface. For example, if it is set to analytics for metadata serial_number , all data is published to the topic analytics/{did}/metadata/serial_number . It overrides the global custom prefix. |
It is mandatory to define the device ID (
did
) for each device. Thedid
value must match the UUID of the device created in the relayr Cloud.
For more information on creating devices in the Cloud, refer to the relayr Cloud API documentation.
The device
did
cannot contain spaces and plus (+) characters.
Here is an example of the device static metadata:
"metadata": [
{
"id": "did",
"value": "f33c6bah-b31e-4f5a-964h-13a935a8b25f"
}
]
Dynamic Metadata
Dynamic metadata is configured with a protocol-specific object
.
Dynamic metadata is published only if its value changes.
To report a metadata value dynamically, configure the following settings:
Configuration Setting | Description |
---|---|
id | Metadata identifier. |
object | Protocol-specific object definition. See the OPC UA Object Definition section for details. |
Optionally, you can configure the following dynamic metadata settings:
Configuration Setting | Description |
---|---|
custom_prefix | Prefix of the MQTT topic that the object is reported to. An option to publish data to a custom MQTT topic for a local data processing or directly to the northbound interface. For example, if it is set to analytics for metadata serial_number , all data is published to the topic analytics/{did}/metadata/serial_number . It overrides the global custom prefix. |
sampling_interval | Local sampling interval value, given in milliseconds, that overrides the global sampling interval. |
connection | Local connection ID used for given metadata. It overrides the global connection set for the device. Possible ID values are defined in the connections section of the configuration file. See the Configuring OPC UA Connections section for details. |
Here is an example of the device dynamic metadata:
"metadata": [
{
"id" : "serial_number",
"object" : { ... },
"sampling_interval" : 4000,
"custom_prefix" : "v1/nb"
},
OPC UA Object Definition
For each configured measurement, configuration parameter and dynamic metadata, configure a protocol-specific object
configuration section, with the following settings available:
Configuration Setting | Description |
---|---|
data_path | Path to the OPC UA Node on the server. It must begin with Objects/ or 0:Objects/ . If a namespace index is omitted, 0 is assumed. To use an automatic namespace translation, use the @n convention, in which @0 refers to the first namespace in the namespaces_map array configured in the connections section. |
subscription | If set to true , the data subscription mechanism is used instead of polling. Data is reported only on the change of value. Optional setting. By default, false . |
The OPC UA Protocol Adapter supports the read/write Node Value attributes of the following types:
- String
- Boolean
- Float
- SByte
- Int16
- Int32
- Int64
- Byte
- Uint16
- Uint32
- Uint64
- ExtensionObject (read only)
- DateTime (read only)
Here is an example of the measurement object configuration:
{
"object": {
"data_path": "0:Objects/2:MyObject/2:MyVariable",
"subscription": true
}
}
Here is an example of the object configuration with an automatic namespace mapping:
{
"object": {
"data_path": "Objects/@0:MyObject/@0:MyVariable",
"subscription": true
}
}
Examples of Configuration Files
Deployment Configuration File
{
"transport": "mqtt",
"mqtt_connection": {
"host": "localhost",
"port": 1883,
"keepalive": 20,
"max_inflight_messages": 100,
"qos_levels": {
"measurements": 0,
"alerts": 1,
"configuration": 1,
"metadata": 1
}
},
"health_monitor": {
"heartbeat_interval": 60
},
"pmq_connection":
{
"output_queues": ["/opc-ua_out_queue"],
"input_queues": ["/opc-ua_in_queue"],
"message_size": 8192,
"message_count": 10
}
}
Application Configuration File
{
"connections": [
{
"id": "OpenOpcUaServer",
"url": "opc.tcp://127.0.0.1:16664/OpenOpcUaServer"
}
],
"sampling_interval": 4000,
"devices": [
{
"connection": {
"id": "OpenOpcUaServer"
},
"measurements": [
{
"object": {
"data_path": "Objects/Dynamic/Scalar/Float"
},
"id": "float_stat"
},
{
"object": {
"data_path": "Objects/Dynamic/Scalar/Boolean"
},
"id": "bool_stat"
},
{
"object": {
"data_path": "Objects/Dynamic/Scalar/Int16"
},
"id": "int_stat"
},
{
"object": {
"data_path": "Objects/Dynamic/Scalar/String"
},
"id": "string_stat"
}
],
"alerts": [
{
"measurement_id": "int_stat",
"id": "int_too_high",
"threshold_set": 16,
"logic_set": ">=",
"message_set": " ALERT IS SET",
"threshold_clear": 12,
"logic_clear": "<=",
"message_clear": " ALERT IS CLEARED"
}
],
"configuration": [
{
"object": {
"data_path": "Objects/Static/Scalar/Int32"
},
"id": "int_param",
"ro": false
},
{
"object": {
"data_path": "Objects/Static/Scalar/String"
},
"id": "string_param",
"ro": false
}
],
"metadata": [
{
"id": "did",
"value": "414efac7-8296-4014-8830-6a5a1f739a54"
},
{
"id": "model_id",
"value": "82153489-ca6f-45a5-a608-1ef3703c40e9"
},
{
"id": "model_version",
"value": "1"
},
{
"id": "dynamic_metadata",
"object":{
"data_path": "Objects/Dynamic/Scalar/Int16"
},
"sampling_interval": 360000
}
]
}
]
}