Skip to content

Commit b99a02d

Browse files
authored
Merge pull request #40 from krausexb/mqtt-opcuawrite-example
Adding example for using opcua write target
2 parents 0ae7fe3 + dc8f630 commit b99a02d

File tree

3 files changed

+180
-0
lines changed

3 files changed

+180
-0
lines changed

docs/examples/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Adapters
2222
- [OPCUA to SiteWise In-Process Example](../../examples/in-process-opcua-sitewise/README.md)
2323
- [OPCUA to SiteWise Edge In-Process Example](../../examples/in-process-opcua-sitewiseedge/README.md)
2424

25+
- [IoT Core to OPCUA Write In-Process Example](../../examples/in-process-iot-core-opcua-write/README.md)
26+
2527
- [CSV File Adapter Example](../../examples/custom-adapter-csvfile/README.md)
2628

2729
Configuration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# SFC Example in process configuration for AWS IoT Core to OPC UA Write
2+
3+
The file [`iot-core-opcua-write.json`](iot-core-opcua-write.json) contains an example template for reading data from a
4+
AWS IoT Core topic and writing the received value to a tag of an OPCUA Server. This sample could be used for integrating cloud-side generated set points to control systems at a plant level.
5+
 
6+
7+
In order to use the configuration, make the changes described below and
8+
use it as the value of the --config parameter when starting sfc-main.
9+
10+
A debug target is included in the example to optionally write the output
11+
to the console.
12+
 
13+
 
14+
15+
16+
## Deployment directory
17+
18+
A Placeholder ${SFC_DEPLOYMENT_DIR} is used in the configuration. SFC
19+
dynamically replaces these placeholders with the value of the
20+
environment variable from the placeholder. In this example it should
21+
have the value of the path name of the directory where sfc-main, the used
22+
adapters and targets are deployed with the following directory
23+
structure. (This structure can be changed by setting the path name in
24+
the AdapterTypes and TargetTypes sections)
25+
26+
${SFC_DEPLOYMENT_DIR}
27+
   |-sfc-main
28+
   |-debug-target
29+
   |-opcua-writer-target
30+
   |-mqtt
31+
 
32+
33+
## Update AWS IoT Core endpoint configuration
34+
Replace the placeholders in the EndPoint configuration with your AWS account specific endpoint information.
35+
You can retrieve your endpoint by running the aws cli command: `aws iot describe-endpoint --endpoint-type iot:Data-ATS`.
36+
37+
```json
38+
"Brokers": {
39+
"default-broker": {
40+
"EndPoint": "ssl://XXX-ats.iot.XXX.amazonaws.com",
41+
...
42+
}
43+
}
44+
```
45+
46+
## Configure IoT Credentials
47+
Follow the instructions for creating a new thing in the AWS IoT Core [`Documentation`](https://docs.aws.amazon.com/iot/latest/developerguide/iot-quick-start.html). You will create a new IoT Thing and download its connection kit, which will include files that you will need in the next step.
48+
Finally, download the [`Amazon Root CA`](https://www.amazontrust.com/repository/AmazonRootCA1.pem) and move the CA file and the things cert and key to the local folder that is referenced in the broker configuration.
49+
50+
```json
51+
"Brokers": {
52+
"default-broker": {
53+
"Certificate": "${SFC_DEPLOYMENT_DIR}/certs/sfc.cert.pem",
54+
"PrivateKey": "${SFC_DEPLOYMENT_DIR}/certs/sfc.private.key",
55+
"RootCA": "${SFC_DEPLOYMENT_DIR}/certs/AmazonRootCA1.pem",
56+
...
57+
}
58+
}
59+
```
60+
61+
## Target section
62+
```json
63+
"Targets": [
64+
"OPCUAWrite",
65+
"#DebugTarget"
66+
]
67+
```
68+
69+
In order to write the data to both the OPCUA server and the console
70+
uncomment the DebugTarget by deleting the'#'.
71+
 
72+
73+
## Run SFC from deployment directory
74+
```console
75+
sfc-main/bin/sfc-main -config ./iot-core-opcua-write.json
76+
```
77+
78+
[Examples](../../docs/examples/README.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{
2+
"AWSVersion": "2022-04-02",
3+
"Name": "Subscribe to IoT Core and write temperature value to local OPCUA Server",
4+
"Version": 1,
5+
"LogLevel": "Info",
6+
"ElementNames": {
7+
"Value": "value",
8+
"Timestamp": "timestamp",
9+
"Metadata": "metadata"
10+
},
11+
"Schedules": [
12+
{
13+
"Name": "IoTCoreToOPCUA",
14+
"Interval": 1000,
15+
"Description": "Read data of all OPCUA data types once per second and send to terminal",
16+
"Active": true,
17+
"TimestampLevel": "Both",
18+
"Sources": {
19+
"iot": [
20+
"*"
21+
]
22+
},
23+
"Targets": [
24+
"OPCUAWrite",
25+
"#DebugTarget"
26+
]
27+
}
28+
],
29+
"Sources": {
30+
"iot": {
31+
"Name": "iot",
32+
"ProtocolAdapter": "IoTCore",
33+
"AdapterBroker": "default-broker",
34+
"Channels": {
35+
"temperature": {
36+
"Name": "temperature",
37+
"Topics": [
38+
"temperature"
39+
]
40+
}
41+
}
42+
}
43+
},
44+
"Targets": {
45+
"DebugTarget": {
46+
"Active": true,
47+
"TargetType": "DEBUG-TARGET"
48+
},
49+
"OPCUAWrite": {
50+
"TargetType": "OPCUA-WRITER-TARGET",
51+
"Address": "opc.tcp://localhost",
52+
"Path": "myopcua/server/",
53+
"Port": "4840",
54+
"Nodes": [
55+
{
56+
"NodeId": "ns=2;i=2",
57+
"DataPath": "@.sources.iot.values.temperature.value.temperature"
58+
}
59+
]
60+
}
61+
},
62+
"TargetTypes": {
63+
"DEBUG-TARGET": {
64+
"JarFiles": [
65+
"${SFC_DEPLOYMENT_DIR}/debug-target/lib"
66+
],
67+
"FactoryClassName": "com.amazonaws.sfc.debugtarget.DebugTargetWriter"
68+
},
69+
"OPCUA-WRITER-TARGET": {
70+
"JarFiles": [
71+
"${SFC_DEPLOYMENT_DIR}/opcua-writer-target/lib"
72+
],
73+
"FactoryClassName": "com.amazonaws.sfc.opcuawritetarget.OpcuaTargetWriter"
74+
}
75+
},
76+
"AdapterTypes": {
77+
"MQTT": {
78+
"JarFiles": [
79+
"${SFC_DEPLOYMENT_DIR}/mqtt/lib"
80+
],
81+
"FactoryClassName": "com.amazonaws.sfc.mqtt.MqttAdapter"
82+
}
83+
},
84+
"ProtocolAdapters": {
85+
"IoTCore": {
86+
"AdapterType": "MQTT",
87+
"ReadMode": "KeepAll",
88+
"Brokers": {
89+
"default-broker": {
90+
"EndPoint": "ssl://XXX-ats.iot.XXX.amazonaws.com",
91+
"Port": 8883,
92+
"Certificate": "${SFC_DEPLOYMENT_DIR}/certs/sfc.cert.pem",
93+
"PrivateKey": "${SFC_DEPLOYMENT_DIR}/certs/sfc.private.key",
94+
"RootCA": "${SFC_DEPLOYMENT_DIR}/certs/AmazonRootCA1.pem",
95+
"ConnectionTimeout": 15
96+
}
97+
}
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)