From c67f89ea7baf0628ca1c6ca3b8a8e3a698e8b774 Mon Sep 17 00:00:00 2001 From: Zoltan Kis Date: Fri, 16 Feb 2018 11:01:08 +0200 Subject: [PATCH 1/5] Use schema, inputSchema, outputSchema from updated TD spec Signed-off-by: Zoltan Kis --- index.html | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index 8c5d14c2..ee3fd991 100644 --- a/index.html +++ b/index.html @@ -682,7 +682,7 @@

The DataSchema type

typedef USVString DataSchema;

- 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 "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 name attribute represents the name of the Property.
  • - The type attribute represents the type for the Property. + The schema attribute represents the data type for the Property described by DataSchema.
  • The value attribute represents the value of the Property.
  • @@ -738,16 +738,16 @@

    The ThingActionInit dictionary

               dictionary ThingActionInit: SemanticAnnotations {
                 required DOMString name;
    -            DataSchema inputDataDescription;
    -            DataSchema outputDataDescription;
    +            DataSchema inputSchema;
    +            DataSchema outputSchema;
               };
           

    The ThingActionInit dictionary describes the arguments and the return value.

    • The name attribute provides the Action name.
    • -
    • The inputDataDescription 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.
    • -
    • The outputDataDescription attribute provides the description of the returned data. If missing, it means the action does not return data.
    • +
    • 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.
    • +
    • The outputSchema attribute provides the description of the returned data. If missing, it means the action does not return data.

    @@ -768,12 +768,12 @@

    The ThingEventInit dictionary

               dictionary ThingEventInit: SemanticAnnotations {
                 required DOMString name;
    -            DataSchema dataDescription;
    +            DataSchema schema;
               };
             
    • The name attribute represents the event name.
    • -
    • The dataDescription attribute represents the type of the data that is attached to the event. If missing, it means the event does not carry data.
    • +
    • The schema attribute represents the type of the data that is attached to the event. If missing, it means the event does not carry data.
    @@ -854,13 +854,13 @@

    Examples

    thing.addProperty({ name: "temperature", value: "0", - type: "number", + schema: "number", writable: false // use default values for the rest }); thing.addEvent({ name: "onchange", - dataDescription: "number" + schema: "number" }); thing.addAction({ name: "reset", From a76fbcac908838768e93815b0d249ba3f5ca40e7 Mon Sep 17 00:00:00 2001 From: Zoltan Kis Date: Fri, 16 Feb 2018 15:26:06 +0200 Subject: [PATCH 2/5] Add support for TD links. Fix schema examples. Signed-off-by: Zoltan Kis --- index.html | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index ee3fd991..1ec46daa 100644 --- a/index.html +++ b/index.html @@ -173,6 +173,8 @@
  • Invoke an Action.
  • Observe Events emitted by the Thing.
  • Observe changes to the Thing Description of the Thing.
  • +
  • Get the Thing Description.
  • +
  • Get the list of linked resources based on the Thing Description.
@@ -509,6 +511,7 @@

The ConsumedThing interface

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); @@ -541,6 +544,41 @@

The ConsumedThing interface

+

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 invokeAction() method

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 @@

The DataSchema type

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 "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.

@@ -854,13 +892,13 @@

Examples

thing.addProperty({ name: "temperature", value: "0", - schema: "number", + schema: '{ \"type\": \"number\" }', writable: false // use default values for the rest }); thing.addEvent({ name: "onchange", - schema: "number" + schema: '{ \"type\": \"number\" }' }); thing.addAction({ name: "reset", @@ -1125,6 +1163,9 @@

The Observable interface

IANA media types (formerly known as MIME types) are defined in RFC2046.

+

+ The terms hyperlink reference and relation type are defined in [[!HTML5]] and RFC8288. +

From a38a250800f3945f656bc8982daf2a3283e83775 Mon Sep 17 00:00:00 2001 From: Zoltan Kis Date: Mon, 19 Feb 2018 15:30:53 +0200 Subject: [PATCH 3/5] Remove ConsumedThing.name. Move getLinks() to experimental extensions section. Add getProperties(), getActions(), getEvents(). Signed-off-by: Zoltan Kis --- index.html | 144 +++++++++++++++++++++++++++++------------------------ 1 file changed, 80 insertions(+), 64 deletions(-) diff --git a/index.html b/index.html index 1ec46daa..0b2adb2a 100644 --- a/index.html +++ b/index.html @@ -508,10 +508,7 @@

The ConsumedThing interface

       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. -

    -
  • - The name read-only attribute represents the user given name of the Thing. -
  • -

-

The setName() method

-

- 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. -

-
-

The getThingDescription() method

Returns the Thing Description of the Thing. @@ -544,41 +530,6 @@

The ConsumedThing interface

-

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 invokeAction() method

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 @@

The ExposedThing interface

Promise<void> unregister(optional USVString directory); Promise<void> emitEvent(DOMString eventName, any payload); // define Thing Description modifiers - ExposedThing addProperty(ThingPropertyInit property); + ExposedThing addProperty(ThingProperty property); ExposedThing removeProperty(DOMString name); - ExposedThing addAction(ThingActionInit action); + ExposedThing addAction(ThingAction action); ExposedThing removeAction(DOMString name); - ExposedThing addEvent(ThingEventInit event); + ExposedThing addEvent(ThingEvent event); ExposedThing removeEvent(DOMString name); // define request handlers ExposedThing setActionHandler(ActionHandler action, optional DOMString actionName); @@ -731,10 +682,10 @@

The DataSchema type

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.

-
-

The ThingPropertyInit dictionary

+
+

The ThingProperty dictionary

-          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 the action argument of type ThingAction and updates the Thing Description. Throws on error. Returns a reference to the same object for supporting chaining.

-
-

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 the event 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 a ConsumedThing 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); - }); + };
@@ -885,8 +890,7 @@

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 Kis Date: 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) {