Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeintner committed Sep 11, 2023
1 parent c06c67c commit 9de4893
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions packages/td-tools/src/util/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

The [IDTA Asset Interface Description (AID) working group](https://github.com/admin-shell-io/submodel-templates/tree/main/development/Asset%20Interface%20Description/1/0) defines a submodel that can be used to describe the asset's service interface or asset's related service interfaces. The current AID working assumptions reuse existing definitions from [WoT Thing Descriptions](https://www.w3.org/TR/wot-thing-description11/) and hence it is possible to consume AAS with AID definitions with node-wot (e.g., read/subscribe live data of the asset and/or associated service).

### Sample Application

The file `AID_v03_counter.json` describes the counter sample in AID format. The `AssetInterfaceDescriptionUtil` utility class allows to transform the AID format to a valid WoT TD format which in the end can be properly consumed by node-wot.
### Sample Applications

#### Prerequisites

- `npm install @node-wot/td-tools`
- `npm install @node-wot/core`
- `npm install @node-wot/binding-http`

#### Sample Code
#### AAS/AID to WoT TD

The file `counterHTTP.json` describes the counter sample in AID format for http binding. The `AssetInterfaceDescriptionUtil` utility class allows to transform the AID format to a valid WoT TD format which in the end can be properly consumed by node-wot.

The example tries to load an AID file in AID format and transforms it to a regular WoT TD.

```js
// aid-client.js
// aid-to-td.js
const fs = require("fs/promises"); // to read JSON file in AID format

Servient = require("@node-wot/core").Servient;
Expand Down Expand Up @@ -63,10 +63,39 @@ async function example() {
example();
```

#### Run the sample script
#### WoT TD to AAS/AID

The example tries to load online counter TD and converts it to AAS JSON format.

`node aid-client.js`
```js
// td-to-aid.js
AssetInterfaceDescriptionUtil = require("@node-wot/td-tools").AssetInterfaceDescriptionUtil;

It will show the counter value retrieved from http://plugfest.thingweb.io:8083/counter/properties/count
let assetInterfaceDescriptionUtil = new AssetInterfaceDescriptionUtil();

async function example() {
try {
const response = await fetch("http://plugfest.thingweb.io:8083/counter");
const counterTD = await response.json();

const sm = assetInterfaceDescriptionUtil.transformTD2AAS(JSON.stringify(counterTD), ["http", "coap"]);

// print JSON format of AAS
console.log(sm);
} catch (err) {
console.log(err);
}
}

// launch example
example();
```

#### Run the sample scripts

`node aid-to-td.js`
... will show the counter value retrieved from http://plugfest.thingweb.io:8083/counter/properties/count
Note: make sure that the file `counterHTTP.json` is in the same folder as the script.

`node td-to-aid.js`
... will show the online counter im AAS/AID JSON format (usable by AASX Package Explorer 2023-08-01.alpha).

0 comments on commit 9de4893

Please sign in to comment.