From c67f89ea7baf0628ca1c6ca3b8a8e3a698e8b774 Mon Sep 17 00:00:00 2001
From: Zoltan Kis
- The DataSchema type represents a type name specified in the Thing Description in a serialized form, for instance JSON Schema.
+ The DataSchema type represents a data type specified in the Thing Description in a serialized form.
DataSchema is under development, currently it can denote any type supported by the Thing Description and the WoT Runtime, such as simple type like
The ThingActionInit dictionary describes the arguments and the return value.
The DataSchema type
typedef USVString DataSchema;
"boolean"
, "number"
, "string"
, or "array"
, or "object"
that may specify value range etc.
@@ -698,7 +698,7 @@ The ThingPropertyInit dictionary
dictionary ThingPropertyInit: SemanticAnnotations {
required DOMString name;
- required DataSchema type;
+ required DataSchema schema;
any value;
boolean writable = true;
boolean observable = true;
@@ -709,7 +709,7 @@
The ThingPropertyInit dictionary
The ThingActionInit dictionary
dictionary ThingActionInit: SemanticAnnotations {
required DOMString name;
- DataSchema inputDataDescription;
- DataSchema outputDataDescription;
+ DataSchema inputSchema;
+ DataSchema outputSchema;
};
dictionary ThingEventInit: SemanticAnnotations { required DOMString name; - DataSchema dataDescription; + DataSchema schema; };
+ Returns the list of linked resources in Thing Description of the Thing in the form of a list of TDLink objects. +
++ Contains a hyperlink reference, a relation type and a media type. +
++ dictionary TDLink { + required USVString href; + USVString mediaType; + DOMString rel; + }; ++
The TDLink dictionary contains the following properties: +
Takes the Action name from the name argument and the list of parameters, then requests from the underlying platform and the Protocol Bindings to invoke the Action on the remote Thing and return the result. Returns a Promise
that resolves with the return value or rejects with an Error.
@@ -685,7 +723,7 @@
- DataSchema is under development, currently it can denote any type supported by the Thing Description and the WoT Runtime, such as simple type like "boolean"
, "number"
, "string"
, or "array"
, or "object"
that may specify value range etc.
+ DataSchema is under development, currently it can denote any type supported by the Thing Description and the WoT Runtime.
+ The terms hyperlink reference and relation type are defined in [[!HTML5]] and RFC8288. +
interface ConsumedThing { - readonly attribute DOMString name; - void setName(DOMString name); ThingDescription getThingDescription(); - sequence<TDLink> getLinks(); Promise<any> invokeAction(DOMString name, any parameters); Promise<void> writeProperty(DOMString name, any value); Promise<any> readProperty(DOMString name); @@ -522,19 +519,8 @@The ConsumedThing interface
ConsumedThing
represents a local proxy object of the remote Thing.
-
- Takes a name
parameter and sets the name of the Thing, as used in applications. Applications can provide a maximum 128 bytes long name, but implementations may reject (by throwing a `RangeError`) or truncate the provided name, depending on the capabilities of the underlying platform. Setting name
throws `TypeError` on other invalid (not string) input.
-
Returns the Thing Description of the Thing. @@ -544,41 +530,6 @@
- Returns the list of linked resources in Thing Description of the Thing in the form of a list of TDLink objects. -
-- Contains a hyperlink reference, a relation type and a media type. -
-- dictionary TDLink { - required USVString href; - USVString mediaType; - DOMString rel; - }; --
The TDLink dictionary contains the following properties: -
Takes the Action name from the name argument and the list of parameters, then requests from the underlying platform and the Protocol Bindings to invoke the Action on the remote Thing and return the result. Returns a Promise
that resolves with the return value or rejects with an Error.
@@ -668,11 +619,11 @@
Adds a Property defined by the argument and updates the Thing Description. Throws on error. Returns a reference to the same object for supporting chaining.
-- dictionary ThingPropertyInit: SemanticAnnotations { + dictionary ThingProperty: SemanticAnnotations { required DOMString name; required DataSchema schema; any value; @@ -769,19 +720,19 @@The ThingPropertyInit dictionary
The addAction() method
- Adds an Action to the Thing object as defined by the
-action
argument of type ThingActionInit and updates the Thing Description. Throws on error. Returns a reference to the same object for supporting chaining. + Adds an Action to the Thing object as defined by theaction
argument of type ThingAction and updates the Thing Description. Throws on error. Returns a reference to the same object for supporting chaining.- @@ -885,8 +890,7 @@The ThingActionInit dictionary
++ The ThingAction dictionary
- dictionary ThingActionInit: SemanticAnnotations { + dictionary ThingAction: SemanticAnnotations { required DOMString name; DataSchema inputSchema; DataSchema outputSchema; };- The ThingActionInit dictionary describes the arguments and the return value. + The ThingAction dictionary describes the arguments and the return value.
+
- The name attribute provides the Action name.
- The inputSchema attribute provides the description of the input arguments (argument list is represented by an object). If missing, it means the action does not accept arguments.
@@ -799,12 +750,12 @@The ThingActionInit dictionary
The addEvent() method
- Adds an event to the Thing object as defined by the
-event
argument of type ThingEventInit and updates the Thing Description. Throws on error. Returns a reference to the same object for supporting chaining. + Adds an event to the Thing object as defined by theevent
argument of type ThingEvent and updates the Thing Description. Throws on error. Returns a reference to the same object for supporting chaining.- +The ThingEventInit dictionary
++ The ThingEvent dictionary
- dictionary ThingEventInit: SemanticAnnotations { + dictionary ThingEvent: SemanticAnnotations { required DOMString name; DataSchema schema; }; @@ -975,6 +926,71 @@Examples
+ +Experimental extensions to the ConsumedThing interface
++ The ThingDescription related functionality, such as enumerating Properties, Actions, Events and links (introspection) is an API extension that is out of scope for this specification. However, the draft interfaces are defined here for informative purposes. +
++ partial interface ConsumedThing { + sequence<ThingProperty> getProperties(); + sequence<ThingAction> getActions(); + sequence<ThingEvent> getEvents(); + sequence<TDLink> getLinks(); + }; ++ ++ + The getProperties() method
++ Returns the list of Properties defined in the Thing Description of the Thing in the form of a list of ThingProperty objects. +
++ + The getActions() method
++ Returns the list of Actions defined in the Thing Description of the Thing in the form of a list of ThingAction objects. +
++ + The getEvents() method
++ Returns the list of Events defined in the Thing Description of the Thing in the form of a list of ThingEvent objects. +
++ The getLinks() method
++ Returns the list of linked resources in Thing Description of the Thing in the form of a list of TDLink objects. +
++ +The TDLink dictionary
++ Contains a hyperlink reference, a relation type and a media type. +
++ dictionary TDLink { + required USVString href; + USVString mediaType; + DOMString rel; + }; ++The TDLink dictionary contains the following properties: +
+
+ +- + The href attribute represents a hyperlink reference. +
+- + The rel attribute represents a relation type. +
+- + The mediaType attribute represents a IANA media type. For TDs there will be registered media types, so applications will be able to check whether an `href` link points to a TD, i.e. whether the link is fetcheable with this API. +
+Observables
From 2870cab30f5103a9eae717df6a92938c1c04bdbd Mon Sep 17 00:00:00 2001 From: Zoltan Kis
Date: Tue, 20 Feb 2018 13:39:15 +0200 Subject: [PATCH 4/5] Fix examples containing thing.name. Add ed note about constraints. Signed-off-by: Zoltan Kis --- index.html | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/index.html b/index.html index 0b2adb2a..c0fcc675 100644 --- a/index.html +++ b/index.html @@ -308,6 +308,9 @@ The ThingFilter dictionary
+ Constraints are experimental feature, implementations are not required to support them. +
Semantic annotations need revisiting in order to simplify their representation. In the [[WOT-TD]] specification they represent the `@type` construct. At the moment only `@context`, `@type` and `@id` constructs are used in the TD.
@@ -451,7 +454,7 @@The ThingTemplate dictionary
url: "http://directory.wotservice.org" }; let subscription = wot.discover(discoveryFilter).subscribe( - thing => { console.log("Found Thing " + thing.name); }, + thing => { console.log("Found Thing " + await thing.readProperty('name'); }, error => { console.log("Discovery finished because an error: " + error.message); }, () => { console.log("Discovery finished successfully");} ); @@ -466,14 +469,14 @@The ThingTemplate dictionary
let subscription = wot.discover({ method: "local" }).subscribe( - thing => { console.log("Found local Thing " + thing.name); }, + thing => { console.log("Found local Thing " + await thing.readProperty('name'); }, error => { console.log("Discovery error: " + error.message); }, () => { console.log("Discovery finished successfully");} );let subscription = wot.discover({ method: "local" }).subscribe({ - next: thing => { console.log("Found local Thing " + thing.name); }, + thing => { console.log("Found local Thing " + await thing.readProperty('name'); }, error: err => { console.log("Discovery error: " + err.message); }, complete: () => { console.log("Discovery finished successfully");} }); @@ -483,7 +486,7 @@The ThingTemplate dictionary
method: "nearby", constraints: [{ protocol: "BLE-4.2" }, { protocol: "NFC"}] }).subscribe( - thing => { console.log("Found nearby Thing " + thing.name); }, + thing => { console.log("Found nearby Thing " + await thing.readProperty('name'); }, error => { console.log("Discovery error: " + error.message); }, () => { console.log("Discovery finished successfully");} ); @@ -493,7 +496,7 @@The ThingTemplate dictionary
method: "other", constraints: [{ solution: "XYZ123", key: "..."}] }).subscribe( - thing => { console.log("Found Thing " + thing.name); }, + thing => { console.log("Found Thing " + await thing.readProperty('name'); }, error => { console.log("Discovery error: " + error.message); }, () => { console.log("Discovery finished successfully");} ); @@ -581,8 +584,10 @@Examples
Below aConsumedThing
interface example is given.- wot.fetch("http://mmyservice.org/mySensor").then(td => { + try { + let td = await wot.fetch("http://mmyservice.org/mySensor"); let thing = wot.consume(td); + let thingName = await thing.readProperty('name'); console.log("Thing " + thing.name + " has been consumed."); let subscription = thing.onPropertyChange("temperature") .subscribe(function(value) { @@ -594,9 +599,9 @@Examples
console.log("Error starting measurement."); subscription.unsubscribe(); }) - }).catch(error => { + } catch(error) { console.log("Error during fetch or consume: " + error.message); - }); + };Examples
WoT.fetch("http://myservice.org/mySensor/description") .then(td => { let e_thing = WoT.produce(td); - // properties, actions and events are added based on the TD - console.log("created " + thing.name }); + // properties, actions and events have been added based on the TD // now add the requests handlers try { e_thing.setPropertyReadHandler(propertyName => { From 7631629b42228133563196883e1b6d0862703ebc Mon Sep 17 00:00:00 2001 From: Zoltan KisDate: Wed, 21 Feb 2018 16:59:24 +0200 Subject: [PATCH 5/5] Re-add ConsumedThing.name Signed-off-by: Zoltan Kis --- index.html | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index c0fcc675..3ac75bd3 100644 --- a/index.html +++ b/index.html @@ -454,7 +454,7 @@ The ThingTemplate dictionary
url: "http://directory.wotservice.org" }; let subscription = wot.discover(discoveryFilter).subscribe( - thing => { console.log("Found Thing " + await thing.readProperty('name'); }, + thing => { console.log("Found Thing " + thing.name); }, error => { console.log("Discovery finished because an error: " + error.message); }, () => { console.log("Discovery finished successfully");} ); @@ -469,14 +469,14 @@The ThingTemplate dictionary
let subscription = wot.discover({ method: "local" }).subscribe( - thing => { console.log("Found local Thing " + await thing.readProperty('name'); }, + thing => { console.log("Found local Thing " + thing.name); }, error => { console.log("Discovery error: " + error.message); }, () => { console.log("Discovery finished successfully");} );let subscription = wot.discover({ method: "local" }).subscribe({ - thing => { console.log("Found local Thing " + await thing.readProperty('name'); }, + thing => { console.log("Found local Thing " + thing.name); }, error: err => { console.log("Discovery error: " + err.message); }, complete: () => { console.log("Discovery finished successfully");} }); @@ -486,7 +486,7 @@The ThingTemplate dictionary
method: "nearby", constraints: [{ protocol: "BLE-4.2" }, { protocol: "NFC"}] }).subscribe( - thing => { console.log("Found nearby Thing " + await thing.readProperty('name'); }, + thing => { console.log("Found nearby Thing " + thing.name); }, error => { console.log("Discovery error: " + error.message); }, () => { console.log("Discovery finished successfully");} ); @@ -496,7 +496,7 @@The ThingTemplate dictionary
method: "other", constraints: [{ solution: "XYZ123", key: "..."}] }).subscribe( - thing => { console.log("Found Thing " + await thing.readProperty('name'); }, + thing => { console.log("Found Thing " + thing.name); }, error => { console.log("Discovery error: " + error.message); }, () => { console.log("Discovery finished successfully");} ); @@ -511,6 +511,7 @@The ConsumedThing interface
interface ConsumedThing { + readonly attribute DOMString name; ThingDescription getThingDescription(); Promise<any> invokeAction(DOMString name, any parameters); Promise<void> writeProperty(DOMString name, any value); @@ -524,6 +525,11 @@The ConsumedThing interface
ConsumedThing
represents a local proxy object of the remote Thing. +The name property
++ The `name` property represents the name of the Thing as specified in the TD. In this version it is read only. +
+The getThingDescription() method
Returns the Thing Description of the Thing. @@ -587,7 +593,6 @@
Examples
try { let td = await wot.fetch("http://mmyservice.org/mySensor"); let thing = wot.consume(td); - let thingName = await thing.readProperty('name'); console.log("Thing " + thing.name + " has been consumed."); let subscription = thing.onPropertyChange("temperature") .subscribe(function(value) {