diff --git a/packages/td-tools/src/util/README.md b/packages/td-tools/src/util/README.md index 3edf9053b..00f139f27 100644 --- a/packages/td-tools/src/util/README.md +++ b/packages/td-tools/src/util/README.md @@ -4,9 +4,7 @@ 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 @@ -14,12 +12,14 @@ The file `AID_v03_counter.json` describes the counter sample in AID format. The - `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; @@ -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).