Commit bc719482 authored by Jiahang Chen's avatar Jiahang Chen
Browse files

add doc link to readme

parent cc47bb0e
Pipeline #374035 passed with stages
in 1 minute and 3 seconds
......@@ -8,6 +8,9 @@
pip install https://git.rwth-aachen.de/kwh40/fml40-reference-implementation/-/jobs/artifacts/master/raw/public/ml-0.1-py3-none-any.whl?job=wheel
```
##Documentation
We provide a documentation to get start with the fml40 python reference implementation package. It can be found [here](https://git.rwth-aachen.de/kwh40/fml40-reference-implementation/-/jobs/artifacts/master/file/public/html/index.html?job=pages).
Features
--------
This package provides two different modes to launch your Digital Twins:
......@@ -17,6 +20,7 @@
Usage
-----
### Using fml40s.py
A Digital Twin can be launched in persistent mode by executing
......@@ -30,6 +34,54 @@
python fml40s.py -h
```
### Develop your Digital Twin using this package
We introduce here briefly how to develop a user-specified Digital Twin. For more details refer to the created cloud and edge Digital Twin built in [Jupyter Notebook](https://mybinder.org/v2/gh/kwh40/notebooks/master).
The following steps can be only carried out after you have created the identity of your Digital Twin via Config REST API and made a respective config file. We use the config file `MyDigitalTwin.json` appearing in the section `Config files` to build a Digital Twin. Now we continue the following steps.
- Optionally set a logger using the function `setup_logger`. The generated log file will be then located in the folder `logs`.
```
ml.setup_logger("MyDigitalTwin")
```
- Set the path of config file and import it in JSON format.
```
config_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "configs"))
dt_model = ml.load_config(config_filepath=os.path.join(config_path, "MyDigitalTwin.json"))
```
- Create the thing instance.
```
client_secret = "" #To be filled
thing = ml.create_thing(
model=dt_model, grant_type="client_credentials", secret=client_secret,
is_broker_rest=False, is_broker=True, is_repo=True
)
```
- As written in the config file, the Digital Twin has a feature named fml40::ProvidesProductionData. In the next step we extend/implement this class with our own logic.
```
class ProvidesProductionDataImpl(ProvidesProductionData):
def __init__(self, name="", identifier=""):
super(ProvidesProductionData, self).__init__(
name=name,
identifier=identifier)
self.production_data_list = thing.features["ml40::ProductionData"].subFeatures["ml40::Composite"].targets
def getProductionData(self, name):
for key in self.production_data_list.keys():
if key == name:
return self.production_data_list[key].to_subthing_json()
return {"error": "NOT FOUND"}
```
- Insert the class into the respective feature of your Digital Twin
```
ml.add_function_impl_obj(thing, ProvidesProductionDataImpl, "fml40::ProvidesProductionData")
```
- Launch your Digital Twin
```
thing.run_forever()
```
So far, your Digital Twin has been created. In the meantime you can establish a connection with it using S3I-B messages.
Config files
------------
......@@ -59,6 +111,60 @@
{
"class": "fml40::ProvidesProductionData"
},
{
"class": "ml40::ProductionData",
"subFeatures": [
{
"class": "ml40::Composite",
"targets": [
{
"class": "ml40::Thing",
"name": "Stammsegment 4711",
"roles": [
{
"class": "fml40::StemSegment",
}
],
"features": [
{
"class": "ml40::Location",
"latitude": 50.1231,
"longitude": 6.1231
},
{
"class": "fml40::StemSegmentProperties",
"diameter": 0.4,
"length": 2,
"woodType": "Spruce"
}
]
},
{
"class": "ml40::Thing",
"name": "Stammsegment 4712",
"roles": [
{
"class": "fml40::StemSegment",
}
],
"features": [
{
"class": "ml40::Location",
"latitude": 50.1231,
"longitude": 6.1231
},
{
"class": "fml40::StemSegmentProperties",
"diameter": 0.6,
"length": 3,
"woodType": "Spruce"
}
]
}
]
}
]
},
{
"class": "ml40::Location",
"longitude": 5.03424,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment