OPC UA Server¶
This page describes how the Connectware can act as an OPC UA server. The Connectware can also act as a OPC UA client.
To run an OPC UA server, the commissioning file must contain a server resource
of type Cybus::Server::Opcua
. This will start an OPC UA server that can be accessed
by OPC UA clients. From the OPC UA client, this server is reachable by the
following address:
opc.tcp://<connectwareHost>:4841<resourcePath>
Note: The OPC UA server provided by the Connectware uses the non-standard port number 4841 (whereas standard OPC UA uses port 4840) in order to avoid port number collisions on computers where another OPC UA server is already running. Also note: The Connectware can run exactly one instance of an OPC UA server, not multiple instances.
If your Connectware instance is running on a system that is reachable by a DNS
hostname, this hostname must be specified in the hostname
property,
so that the server is reachable from outside of the Connectware docker network.
The value localhost is not valid in this case, as localhost refers to the
local Docker container but not the host itself, which means this name is not
reachable from other containers or the host system.
Additionally, the property resourcePath
is important when when connecting
to the OPC UA server. This property defines the prefix of the connection string
and defaults to the value /UA/CybusOpcuaServer
. Please note that this string
has to be added to the URL when connecting from a client to the OPC UA Server.
Otherwise the client might not be able to connect successfully.
The server configuration is specified by the properties of the server resource.
The actual data points (nodes in OPC UA) are specified by defining resources
of type Cybus::Node::Opcua
, one resource for each node. The nodes are
structured in a tree-like hierarchy. There must be exactly one root node,
which has its parent
property set as a reference to the server object. All
other nodes reference either the root node or other intermediate nodes as
parent
, forming a tree of nodes on the OPC UA Server.
Nodes can be defined within the same service as the OPC UA server, or also in other services using inter-service referencing using the service-id. It is thus possible to add or remove nodes while the OPC UA server is running, by adding more service commissioning files.
Custom Server Properties¶
port
(integer)¶
Port of the listening socket
Default: 4841
Example: 4841
maxSessions
(integer)¶
Max Sessions allowed by user
Default: 20
Example: 1000
maxConnections
(integer)¶
Max Connections allowed for a single endpoint to prevent DDoS attacks
Default: 20
Example: 1000
resourcePath
(string)¶
Resource Path of the OPC Server. This must be added to the OPC UA connection URN of the client
Default: "/UA/CybusOpcuaServer"
Examples: "/UA/CybusOpcuaServer"
, "/My/IndividualName"
alternateHostname
(string)¶
This setting is deprecated, has been renamed into ‘hostname’, and will be removed in a future release
Examples: "10.20.30.40"
, "my.connectware-host.company.com"
hostname
(string)¶
The hostname by which the Connectware with the OPC UA server will be reachable on the system. This can be either an IP address or a DNS name.
Examples: "10.20.30.40"
, "my.connectware-host.company.com"
applicationUri
(string)¶
The application URI is used to define the namespace name of the Connectware defined NodeIds
Default: "urn:cybus:opcua:server:1"
Example: "urn:cybus:opcua:server:1"
allowAnonymous
(boolean)¶
If true, usage of anonymous access token is allowed. In that case, OPC UA clients are allowed to connect without any authentication. Note: This is a high security risk and must not be used in production deployments.
Default: false
Example: true
certificateFile
(string)¶
Absolute path to the server certificate file
Default: "/connectware_certs/cybus_server.crt"
Example: "/connectware_certs/cybus_server.crt"
privateKeyFile
(string)¶
Absolute path to the server private key file
Default: "/connectware_certs/cybus_server.key"
Example: "/connectware_certs/cybus_server.key"
securityPolicies
(array)¶
Defines the list of OPC UA securityPolicies that will be available on the server. Note: The policy “None” is a high security risk and must not be used in production deployments.
The object is an array with all elements of the type string
.
Each element of the array must be one of the following enum values:
Basic256Sha256
None
Default:
[
"Basic256Sha256"
]
Example: "[\"Basic256Sha256\", \"None\"]"
nodesetFiles
(array)¶
Predefined Nodeset files to load on startup
The object is an array with all elements of the type string
.
Each element of the array must be one of the following enum values:
standard
di
ia
machinery
machineTool
packML
robotics
Opc.Ua.PlasticsRubber.GeneralTypes.NodeSet2.xml
Opc.Ua.PlasticsRubber.IMM2MES.NodeSet2.xml
Opc.Ua.PLCopen.NodeSet2.xml
securityModes
(array)¶
Defines the list of OPC UA security modes which an OPC client can use to establish a connection to the Cybus OPC UA server
The object is an array with all elements of the type string
.
Each element of the array must be one of the following enum values:
Invalid
None
Sign
SignAndEncrypt
Default:
[
"SignAndEncrypt"
]
Example: "[\"None\", \"SignAndEncrypt\"]"
database
(object)¶
Definition of the database for historical access of the data. If this property exists, historical access is enabled, otherwise it is not enabled.
Properties of the database
object:
type
(string, enum)¶
Type of the history database
This element must be one of the following enum values:
influx
Default: "influx"
Example: "influx"
host
(string)¶
Database Host
Example: "10.20.30.40"
port
(integer)¶
Port of the database server
Default: 8086
Example: 8086
name
(string)¶
Database Name
Example: "opcuaHistory"
retention
(integer)¶
Data older than the specified number of days will be automatically discarded
Example: 356
Custom Node Properties¶
browseName
(string, required)¶
The browse name (not path) of this node
Examples: "temperature1"
, "pressure2"
nodeId
(string)¶
The specific node id of this node
Example: "ns=1;s=spindleSpeed"
nodeType
(string, enum, required)¶
The node type: Whether this node is a variable or an object.
This element must be one of the following enum values:
Object
Variable
historize
(boolean)¶
Whether to accumulate an historian for this node
Default: false
interpolation
(string, enum)¶
The displayed interpolation mode
This element must be one of the following enum values:
stepped
sloped
Default: "sloped"
maxTimeInterval
(integer)¶
Specifies the maximum interval between data points in the history repository regardless of their value change [in milliseconds]
Default: 10000
Example: 1000
minTimeInterval
(integer)¶
Specifies the minimum interval between data points in the history repository regardless of their value change [in milliseconds]
Default: 500
Example: 100
dataType
(string)¶
The data type of this node. This can be either an OPC UA base type (see example values), or a node ID which references a data type node.
Examples: "Boolean"
, "Byte"
, "ByteString"
, "DataValue"
,
"DateTime"
, "DiagnosticInfo"
, "Double"
,
"ExpandedNodeId"
, "ExtensionObject"
, "Float"
, "Guid"
,
"Int16"
, "Int32"
, "Int64"
, "LocalizedText"
,
"NodeId"
, "Null"
, "QualifiedName"
, "SByte"
,
"StatusCode"
, "String"
, "UInt16"
, "UInt32"
,
"UInt64"
, "Variant"
, "XmlElement"
serializeDataType
(string, enum)¶
For nodes where the data type is not an OPC UA base type but a node reference, the data type for serialization of values sometimes needs to be specified separately here. This must be a basic OPC UA data type.
This element must be one of the following enum values:
Boolean
Byte
ByteString
DataValue
DateTime
DiagnosticInfo
Double
ExpandedNodeId
ExtensionObject
Float
Guid
Int16
Int32
Int64
LocalizedText
NodeId
Null
QualifiedName
SByte
StatusCode
String
UInt16
UInt32
UInt64
Variant
XmlElement
valueRank
(integer, enum)¶
The rank of the transported data, default is scalar (-1), use 1 for array of scalars
This element must be one of the following enum values:
-3
-2
-1
0
1
2
Default: -1
arrayDimensions
(array)¶
For nodes that represent an array or a multi-dimensional array (e.g. a matrix), this array value specifies the size in each of the dimensions.
The object is an array with all elements of the type number
.
Example: [6,4]
Example Commissioning File¶
Download: opcua-server-example.yml
1---
2description: >
3
4 This is a fixture showing server resource functionality
5
6metadata:
7
8 name: OPC UA Server example
9 version: 1.0.0
10 icon: https://www.cybus.io/wp-content/uploads/2017/10/for-whom1.svg
11 provider: cybus
12 homepage: https://www.cybus.io
13
14parameters:
15
16 influxPort:
17 type: integer
18 default: 8086
19 title: Influx Database Port
20
21 retentionTime:
22 type: integer
23 default: 356
24 title: Retention Time
25
26definitions:
27
28 databaseName: opcuaHistory
29
30resources:
31
32 influxdb:
33 type: Cybus::Container
34 properties:
35 image: influxdb:1.8-alpine
36 ports:
37 - !sub '${influxPort}:8086/tcp'
38 volumes:
39 - !sub '${influxdbVolume}:/var/lib/influxdb'
40 environment:
41 INFLUXDB_DB: !ref databaseName
42 INFLUXDB_HTTP_FLUX_ENABLED: true
43
44 influxdbVolume:
45 type: Cybus::Volume
46
47 opcuaServer:
48 type: Cybus::Server::Opcua
49 properties:
50 database:
51 host: 172.17.0.1
52 name: !ref databaseName
53 retention: !ref retentionTime
54 allowAnonymous: false
55 certificateFile: /connectware_certs/cybus_server.crt
56 privateKeyFile: /connectware_certs/cybus_server.key
57
58 parentNodeRoot:
59 type: Cybus::Node::Opcua
60 properties:
61 browseName: parentNodeRoot
62 nodeId: ns=1;s=parentNodeRoot
63 parent: !ref opcuaServer
64 nodeType: Object
65
66 parentNode1:
67 type: Cybus::Node::Opcua
68 properties:
69 browseName: parentNode1
70 nodeId: ns=1;s=parentNode1
71 parent: !ref parentNodeRoot
72 nodeType: Object
73
74 parentNode2a:
75 type: Cybus::Node::Opcua
76 properties:
77 browseName: parentNode2a
78 nodeId: ns=1;s=parentNode2a
79 parent: !ref parentNode1
80 nodeType: Object
81
82 parentNode2b:
83 type: Cybus::Node::Opcua
84 properties:
85 browseName: parentNode2b
86 nodeId: ns=1;s=parentNode2b
87 parent: !ref parentNode1
88 nodeType: Object
89
90 dataNodeRoot1:
91 type: Cybus::Node::Opcua
92 properties:
93 browseName: dataNodeRoot1
94 nodeId: ns=1;s=dataNodeRoot1
95 parent: !ref parentNodeRoot
96 nodeType: Variable
97 operation: serverProvides
98 dataType: Boolean
99
100 dataNodeRoot2:
101 type: Cybus::Node::Opcua
102 properties:
103 browseName: dataNodeRoot2
104 nodeId: ns=1;s=dataNodeRoot2
105 parent: !ref parentNodeRoot
106 nodeType: Variable
107 operation: serverReceives
108 dataType: DateTime
109
110 dataNodeRoot3:
111 type: Cybus::Node::Opcua
112 properties:
113 browseName: dataNodeRoot3
114 nodeId: ns=1;s=dataNodeRoot3
115 parent: !ref parentNodeRoot
116 nodeType: Variable
117 initialValue: 42.0
118 operation: serverProvidesAndReceives
119 dataType: Float
120 historize: true
121
122 dataNode1:
123 type: Cybus::Node::Opcua
124 properties:
125 browseName: dataNode1
126 nodeId: ns=1;s=dataNode1
127 parent: !ref parentNode1
128 nodeType: Variable
129 operation: serverReceives
130 dataType: Int32
131
132 dataNode2a:
133 type: Cybus::Node::Opcua
134 properties:
135 browseName: dataNode2a
136 nodeId: ns=1;s=dataNode2a
137 parent: !ref parentNode2a
138 nodeType: Variable
139 operation: serverProvides
140 dataType: Double
141 historize: true
142
143 dataNode2b:
144 type: Cybus::Node::Opcua
145 properties:
146 browseName: dataNode2b
147 nodeId: ns=1;s=dataNode2b
148 parent: !ref parentNode2b
149 nodeType: Variable
150 operation: serverProvides
151 dataType: String
152
153 mapping:
154 type: Cybus::Mapping
155 properties:
156 mappings:
157 - publish:
158 topic: my/opcuaData/dataNode1
159 subscribe:
160 endpoint: !ref dataNode1
161
162 - publish:
163 endpoint: !ref dataNode2a
164 subscribe:
165 topic: my/opcuaData/dataNode2a
Output Format¶
If the server receives data from an external OPC UA client, the output on the internal MQTT broker will be provided as JSON object:
{
"timestamp": "<unix timestamp in ms>",
"value": "value"
}
Input Format¶
If the server should provide data to an external OPC UA client, the message on the internal MQTT broker must be published in this format:
{
"value": "<value>"
}
Note: If 64-bit integers are being used (which are unsupported in JSON, but are supported in Javascript by the BigInt class), the value must be given as a string that contains the decimal number.