permanent_dt.md 16.6 KB
Newer Older
1
2
# Permanent Digital Twin

Jiahang Chen's avatar
Jiahang Chen committed
3
With the fml40 python reference implementation package, we have developed a Digital Twin, which is modeled based on the ForestML 4.0 and runs permanently. The Digital Twin is implemented using fog approach, which means it is composed of the part of edge DT, which lives in our internal server, and the part of cloud DT, which runs at the S³I Repository. The S³I Interface is enabled in the DT. To communicate with the DT, we provided a python script named `hmi.py` in the folder `demo`. Please feel free to contact with us in order to get the credentials file for the HMI. Put the credentials in the folder `config` and then you can run the script `hmi.py` to speak with the DT after installing the corresponding python virtual environment. This documentation introduces various services the Digital Twin provides and show its JSON entries in the S³I Directory and Repository.  
4
5
6


## S³I Directory entry
Jiahang Chen's avatar
Jiahang Chen committed
7
S³I Directory entry describes a thing at the layer of the metadata, which can be mapped to a JSON file. In order to query the JSON file, you can send a HTTP Request to the S³I Directory. For information about how to send a HTTP Request, refer to [the S³I Document](https://kwh40.pages.rwth-aachen.de/-/s3i/-/jobs/1095388/artifacts/public/html/md/communication.html). The Digital Twin has a directory entry shown below:
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
```
{
    "thingId": "s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03",
    "policyId": "s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03",
    "attributes": {
        "owner": "318b5bc4-7479-4d8d-b347-1019ca194d81",
        "class": "ml40::Thing",
        "allEndpoints": [
            "s3ib://s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03",
            "https://ditto.s3i.vswf.dev/api/2/things/s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03/"
        ],
        "type": "component",
        "name": "mmi_fog_harvester",
        "location": {
            "longitude": 6.45435,
            "latitude": 52.543534
        },
        "dataModel": "fml40",
        "thingStructure": {
            "class": "ml40::Thing",
            "links": [
                {
                    "association": "roles",
                    "target": {
                        "class": "fml40::Harvester",
                        "identifier": "s3i:e1b8b3d6-65a6-4733-876a-dbde9ff72afd"
                    }
                },
                {
                    "association": "features",
                    "target": {
                        "class": "fml40::ProvidesProductionData",
                        "identifier": "s3i:3cece6c6-5e94-448d-b95d-9e3b3c02e6da"
                    }
                },
                {
                    "association": "features",
                    "target": {
                        "class": "ml40::ProductionData",
                        "identifier": "s3i:30b9325f-ce4f-4c55-89f7-663eb4b76273"
                    }
                },
                {
                    "association": "features",
                    "target": {
                        "class": "fml40::AcceptsFellingJobs",
                        "identifier": "s3i:2ce793d4-0b6f-472e-abcb-c0e1e9b084af"
                    }
                },
                {
                    "association": "features",
                    "target": {
                        "class": "fml40::Harvests",
                        "identifier": "s3i:94f8c4d1-9d6c-45e8-a137-3bb33b1004b6"
                    }
                },
                {
                    "association": "features",
                    "target": {
                        "class": "ml40::JobList",
                        "identifier": "s3i:3ba16ab9-a472-42b7-af97-c19acef55196"
                    }
                },
                {
                    "association": "features",
                    "target": {
                        "class": "ml40::Composite",
                        "identifier": "s3i:316f0140-8ce2-440b-badd-3ece563c167c",
                        "links": [
                            {
                                "class": "ml40::Thing",
                                "identifier": "s3i:a57543fb-2b03-43d8-ac4b-f3ba24a545c4",
                                "links": [
                                    {
                                        "association": "roles",
                                        "target": {
                                            "class": "ml40::Engine",
                                            "identifier": "s3i:2fb281c8-180f-41fb-a333-7b83d83cfae0"
                                        }
                                    },
                                    {
                                        "association": "features",
                                        "target": {
                                            "class": "ml40::RotationalSpeed",
                                            "identifier": "s3i:209eb6e3-4a16-458c-952b-dcf3569d062b"
                                        }
                                    }
                                ]
                            },
                            {
                                "class": "ml40::Thing",
                                "identifier": "s3i:97453feb-e15d-463c-9a45-ec4c59b4c8c8",
                                "links": [
                                    {
                                        "association": "roles",
                                        "target": {
                                            "class": "ml40::Crane",
                                            "identifier": "s3i:8f480a94-7b0a-4293-96a9-08ddb0360af6"
                                        }
                                    },
                                    {
                                        "association": "features",
                                        "target": {
                                            "class": "ml40::Shared",
                                            "identifier": "s3i:5cba3433-051b-4e22-9245-30e4c6a45200"
                                        }
                                    }
                                ]
                            }
                        ]
                    }
                }
            ]
        }
    }
}
```

## S³I Repository entry
In a run time environment like edge device or S³I Repository, a conceptual fml40 data model can be directly mapped to a JSON file which describes the thing itself. The Repository entry can be queried via HTTP REST Request, refer to [S³I Documentation](https://kwh40.pages.rwth-aachen.de/-/s3i/-/jobs/1095388/artifacts/public/html/md/communication.html). The permanent Digital Twin has a repository entry which is shown in the following:
```
{
    "thingId": "s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03",
    "policyId": "s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03",
    "attributes": {
        "class": "ml40::Thing",
        "name": "mmi_fog_harvester",
        "roles": [
            {
                "class": "fml40::Harvester",
                "identifier": "s3i:e1b8b3d6-65a6-4733-876a-dbde9ff72afd"
            }
        ],
        "features": [
            {
                "class": "fml40::ProvidesProductionData",
                "identifier": "s3i:3cece6c6-5e94-448d-b95d-9e3b3c02e6da"
            },
            {
                "class": "ml40::ProductionData",
                "identifier": "s3i:30b9325f-ce4f-4c55-89f7-663eb4b76273",
                "subFeatures": [
                    {
                        "class": "ml40::Composite",
                        "identifier": "s3i:78309618-f796-4132-92c9-a3e923506463",
                        "targets": [
                            {
                                "class": "ml40::Thing",
                                "identifier": "s3i:70e808e0-0e0c-4bca-bbaf-23a350c3cf91",
                                "name": "Stammsegment 4711",
                                "roles": [
                                    {
                                        "class": "fml40::StemSegment",
                                        "identifier": "s3i:1cbe9e8d-cc80-47fb-baab-20878043348a"
                                    }
                                ],
                                "features": [
                                    {
                                        "class": "ml40::Location",
                                        "identifier": "s3i:6cdbd9a5-95e2-4539-bd5d-c5238a9d952f",
                                        "latitude": 50.1231,
                                        "longitude": 6.1231
                                    },
                                    {
                                        "class": "fml40::StemSegmentProperties",
                                        "identifier": "s3i:ddeb1e34-1a74-4f6e-a806-75d1cfe98d68",
                                        "diameter": 0.4,
                                        "length": 2,
                                        "woodType": "Spruce"
                                    }
                                ]
                            },
                            {
                                "class": "ml40::Thing",
                                "identifier": "s3i:55d6793c-37e3-4433-a214-89513bd1cfe0",
                                "name": "Stammsegment 4712",
                                "roles": [
                                    {
                                        "class": "fml40::StemSegment",
                                        "identifier": "s3i:0c24170c-e122-454d-b803-a94af462c554"
                                    }
                                ],
                                "features": [
                                    {
                                        "class": "ml40::Location",
                                        "identifier": "s3i:d1b80ca5-df18-4ed9-b9a9-129e18cb8b76",
                                        "latitude": 50.1231,
                                        "longitude": 6.1231
                                    },
                                    {
                                        "class": "fml40::StemSegmentProperties",
                                        "identifier": "s3i:57d09fc1-4218-4fc6-9e80-c6d2fc44c2f4",
                                        "diameter": 0.6,
                                        "length": 3,
                                        "woodType": "Spruce"
                                    }
                                ]
                            }
                        ]
                    }
                ]
            },
            {
                "class": "fml40::AcceptsFellingJobs",
                "identifier": "s3i:2ce793d4-0b6f-472e-abcb-c0e1e9b084af"
            },
            {
                "class": "fml40::Harvests",
                "identifier": "s3i:94f8c4d1-9d6c-45e8-a137-3bb33b1004b6"
            },
            {
                "class": "ml40::JobList",
                "identifier": "s3i:3ba16ab9-a472-42b7-af97-c19acef55196"
            },
            {
                "class": "ml40::Composite",
                "identifier": "s3i:316f0140-8ce2-440b-badd-3ece563c167c",
                "targets": [
                    {
                        "class": "ml40::Thing",
                        "identifier": "s3i:a57543fb-2b03-43d8-ac4b-f3ba24a545c4",
                        "name": "Motor",
                        "roles": [
                            {
                                "class": "ml40::Engine",
                                "identifier": "s3i:2fb281c8-180f-41fb-a333-7b83d83cfae0"
                            }
                        ],
                        "features": [
                            {
                                "class": "ml40::RotationalSpeed",
                                "identifier": "s3i:209eb6e3-4a16-458c-952b-dcf3569d062b",
                                "rpm": 2331
                            }
                        ]
                    },
                    {
                        "class": "ml40::Thing",
                        "identifier": "s3i:97453feb-e15d-463c-9a45-ec4c59b4c8c8",
                        "name": "Kran",
                        "roles": [
                            {
                                "class": "ml40::Crane",
                                "identifier": "s3i:8f480a94-7b0a-4293-96a9-08ddb0360af6"
                            }
                        ],
                        "features": [
                            {
                                "class": "ml40::Shared",
                                "identifier": "s3i:5cba3433-051b-4e22-9245-30e4c6a45200",
                                "targets": [
                                    {
                                        "class": "ml40::Thing",
                                        "identifier": "s3i:efbc9eef-82a1-4ed1-86d0-b06170cae3cd",
                                        "name": "Harvesterkopf",
                                        "roles": [
                                            {
                                                "class": "fml40::HarvestingHead",
                                                "identifier": "s3i:f338cd4d-ca21-46db-8b3b-a17c7c026b6d"
                                            }
                                        ],
                                        "features": [
                                            {
                                                "class": "fml40::Cuts",
                                                "identifier": "s3i:83d8e549-0d07-49f4-9906-6a729b3e6e9b"
                                            },
                                            {
                                                "class": "fml40::Grabs",
                                                "identifier": "s3i:cf6ad395-69d2-493f-838e-82bbc74c4273"
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    },
    "features": {}
}
```

## Service Call
Jiahang Chen's avatar
Jiahang Chen committed
293
As shown in the directory entry, the DT provided diverse service functions. A list containing all implemented and embedded service functions can be found below:
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
```
class: fml40::AcceptsFellingJobs
methods:
    - acceptJob(job)
    - queryJobStatus(identifier)
    - removeJob(identifier)

class: fml40::ProvidesProductionData
methods:
    - getProductionData(name)
```
In order to call those functions remotely, we need to send a S³I-B ServiceRequest to the Digital Twin via the S³I Broker. The class/method name and parameters need to be declared within the message.
The following example shows how to call `removeJob` of the class `fml40::AcceptsFellingJob`
```
{
    "identifier": "s3i:94f8c4d1-9d6c-45e8-a137-3bb33b1004b6" # message ID
    "sender": "s3i:7f46a255-3245-439e-84f0-090f0b221965", # ID of my private HMI
    "receivers": ["s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03"], # ID of the Digital Twin
    "serviceType": "fml40::AcceptsFellingJob/removeJob", # specifies the method and class, which should be called
    "parameters": {"identifier": "s3i:3ba16ab9-a472-42b7-af97-c19acef55196"}, # specifies the input
    "messageType": "ServiceRequest", # message type
    "replyToEndpoint": "s3ib://s3i:7f46a255-3245-439e-84f0-090f0b221965" # Endpoint of my private HMI,
}
```
The message can be sent directly via [the S³I Broker API](https://broker.s3i.vswf.dev/apidoc) or using [S³I Python Lib](https://kwh40.pages.rwth-aachen.de/-/s3i/-/jobs/1095388/artifacts/public/html/S3I-Package.html), An example can be found [here](https://git.rwth-aachen.de/kwh40/s3i/-/blob/master/demo/demo2_sender_hmi.py)

## Query Value
A service is implemented in the DT with the purpose of handling S³I GetValueRequest, so we can send a getValueRequest message to query a specified value of the original JSON model in the edge DT. In the following, we provide also an example to query the current motor rpm value. 
```
{
    'sender': 's3i:7f46a255-3245-439e-84f0-090f0b221965',   # ID of my private HMI
    'identifier': 's3i:23c99920-c369-4074-83b9-17beb84bb2d2', # message ID
    'receivers': ['s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03'], # ID of the digital Twin
    'messageType': 'getValueRequest', # message Type
    'replyToEndpoint': 's3ibs://s3i:7f46a255-3245-439e-84f0-090f0b221965', # Endpoint of my private HMI
    'attributePath': 'attributes/features/ml40::Composite/targets/ml40::Engine/features/ml40::RotationalSpeed/rpm' # the path of rpm value
}
```
Jiahang Chen's avatar
Jiahang Chen committed
332
333
You can also query the whole JSON file and in this case, you just need to replace the `attributePath` with empty string.
The S³I GetValueRequest can be sent via the S³I Broker API or using S³I Python lib as well.