OPC UA is a technical specification used in the automation field for communication between different devices and systems, enabling cross platform, cross language, and cross network operations, providing a reliable and secure data exchange foundation for the Industrial Internet of Things. IoTDB supports OPC UA protocol, and IoTDB OPC Server supports both Client/Server and Pub/Sub communication modes.
Features:
OPC UA will organize the device information received from Sink into folders under the Objects folder according to a tree model.
Each measurement point is recorded as a variable node and the latest value in the current database is recorded.
Features:
Each measurement point is wrapped as an Event Node in OPC UA.
The relevant fields and their meanings are as follows:
| Field | Meaning | Type (Milo) | Example |
|---|---|---|---|
| Time | Timestamp | DateTime | 1698907326198 |
| SourceName | Full path of the measurement point | String | root.test.opc.sensor0 |
| SourceNode | Data type of the measurement point | NodeId | Int32 |
| Message | Data | LocalizedText | 3.0 |
Events are only sent to clients that are already listening; if a client is not connected, the Event will be ignored.
The syntax for creating the Sink is as follows:
create pipe p1 with source (...) with processor (...) with sink ('sink' = 'opc-ua-sink', 'sink.opcua.tcp.port' = '12686', 'sink.opcua.https.port' = '8443', 'sink.user' = 'root', 'sink.password' = 'TimechoDB@2021', //Before V2.0.6.x the default password is root 'sink.opcua.security.dir' = '...' )
| key | value | value range | required or not | default value |
|---|---|---|---|---|
| sink | OPC UA SINK | String: opc-ua-sink | Required | |
| sink.opcua.model | OPC UA model used | String: client-server / pub-sub | Optional | pub-sub |
| sink.opcua.tcp.port | OPC UA's TCP port | Integer: [0, 65536] | Optional | 12686 |
| sink.opcua.https.port | OPC UA's HTTPS port | Integer: [0, 65536] | Optional | 8443 |
| sink.opcua.security.dir | Directory for OPC UA's keys and certificates | String: Path, supports absolute and relative directories | Optional | Opc_security folder/<httpsPort: tcpPort>in the conf directory of the DataNode related to iotdb If there is no conf directory for iotdb (such as launching DataNode in IDEA), it will be the iotdb_opc_Security folder/<httpsPort: tcpPort>in the user's home directory |
| sink.opcua.enable-anonymous-access | Whether OPC UA allows anonymous access | Boolean | Optional | true |
| sink.user | User for OPC UA, specified in the configuration | String | Optional | root |
| sink.password | Password for OPC UA, specified in the configuration | String | Optional | TimechoDB@2021 //Before V2.0.6.x the default password is root |
create pipe p1 with sink ('sink' = 'opc-ua-sink', 'sink.user' = 'root', 'sink.password' = 'TimechoDB@2021' //Before V2.0.6.x the default password is root start pipe p1;
DataRegion Requirement: The OPC UA server will only start if there is a DataRegion in IoTDB. For an empty IoTDB, a data entry is necessary for the OPC UA server to become effective.
Data Availability: Clients subscribing to the server will not receive data written to IoTDB before their connection.
Multiple DataNodes may have scattered sending/conflict issues:
For IoTDB clusters with multiple dataRegions and scattered across different DataNode IPs, data will be sent in a dispersed manner on the leaders of the dataRegions. The client needs to listen to the configuration ports of the DataNode IP separately.。
Suggest using this OPC UA server under 1C1D.
Take UAExpert client as an example, download the UAExpert client: https://www.unified-automation.com/downloads/opc-ua-clients.html
Install UAExpert and fill in your own certificate information.
create pipe p1 with sink ('sink'='opc-ua-sink');
insert into root.test.db(time, s2) values(now(), 2)
The metadata is automatically created and enabled here.
The code is located in the opc-ua-sink packageunder the iotdb-example package.
The code includes:
The steps are as follows:
insert into root.a.b(time, c, d) values(now(), 1, 2);
The metadata is automatically created and enabled here.
create pipe p1 with sink ('sink'='opc-ua-sink', 'sink.opcua.model'='pub-sub'); start pipe p1;
At this point, you can see that the opc certificate-related directory has been created under the server's conf directory.
Open the Client, and now the two-way trust is successful, and the Client can connect to the server.
Write data to the server, and the Client will print out the received data.
stand alone and cluster: It is recommended to use a 1C1D (one coordinator and one data node) single machine version. If there are multiple DataNodes in the cluster, data may be sent in a scattered manner across various DataNodes, and it may not be possible to listen to all the data.
No Need to Operate Root Directory Certificates: During the certificate operation process, there is no need to operate the iotdb-server.pfx certificate under the IoTDB security root directory and the example-client.pfx directory under the client security directory. When the Client and Server connect bidirectionally, they will send the root directory certificate to each other. If it is the first time the other party sees this certificate, it will be placed in the reject dir. If the certificate is in the trusted/certs, then the other party can trust it.
It is Recommended to Use Java 17+: In JVM 8 versions, there may be a key length restriction, resulting in an “Illegal key size” error. For specific versions (such as jdk.1.8u151+), you can add Security.setProperty("crypto.policy", "unlimited");; in the create client of ClientExampleRunner to solve this, or you can download the unlimited package local_policy.jar and US_export_policy to replace the packages in the JDK/jre/lib/security . Download link:https://www.oracle.com/java/technologies/javase-jce8-downloads.html。