RE: [TF-DI] Next Meeting

Hello Soumya, all,



I am working on the TPAC Demo and I want to share the API I use (Still work in progress) for Discovery and Communication. The demo shows discovery and access of Things from a Web Page running in the Browser (Implementation is a Cordova Plugin for Android and iOS [1]). I took some ideas from my work in the Presentation API [2] since there are some common features between both APIs like discovery and communication: Presentation API considers only Displays and the Things API is more generic and considers any Thing/Object.  Namespace for the API in the Browser is “navigator.things”.



The following example shows the usage of the API. Please refer to the documentation inline. It is important to know that privacy is considered by design in the API. The Web Page can Access and get information about a Thing only if the user approves the access (The user must select a thing from the Thing Selection dialog (Similar to a File Dialog for <input type=’file’>)). For Access and Control a Thing (LED in the example) I took the concept of TD form [3] (please refer to the onSuccess example in the Example).

As you can see from the example, the API hides/abstracts the technologies (for Discovery and communication) used behind. These need to be implemented in the Browser. The Browser fetches the corresponding TD file and uses the technologies listed there to access the thing.

You feedback is welcome.  I can also prepare  corresponding WebIDL if there is a need.

// filter of things to discover. Additional parameters can be added.
// in this example we want to discover LEDs nearby (Discovery and Communication technologies is not important)
// The value of the type element is just an example here for LEDs. Ontology for Thing types needs to be defined (or reused from somewhere else).
var filter = {
        type: "http://www.w3c.org/wot/thing/led"
        proximity: "nearby"
};
var req = new ThingRequest(filter);
// onSuccess will be called only when the user selects a Thing from the Thing Selection Dialog.
// The Thing Selection Dialog is a native UI provided by the User Agent and not accessible to the Web App.
// The Thing Selection Dialog will be displayed after the Web App calls "req.start()". The user may select
// a Thing from the Dialog or may cancel the Dialog.
var onSuccess = function(thing){
        // onSetPropertySuccess is called when the property is set successfully.
        // onSetPropertyError is called for example when a thing is not reachable, the property is not writable or when the property doesn’t exist.
        thing.property.set("colorTemperature", 123456).then(onSetPropertySuccess).catch(onSetPropertyError);
        // onGetPropertySuccess is called when the property is retrived successfully.
        // onGetPropertyError is called for example when a thing is not reachable or when the property doesn’t exist.
        thing.property.get("colorTemperature").then(onGetPropertySuccess).catch(onGetPropertyError);
        // onActionCallSuccess is called when the action is successfully executed. Results are passed as input.
        // onActionCallError is called for example when a thing is not reachable, when the action doesn’t exist or when an error is raised during execution
        thing.action.call("ledOnOff", true).then(onActionCallSuccess).catch(onActionCallError);
        // colorTemperatureChangedCallback is executed each time the LED reports a new value.
        // onSubscribeSuccess is called when subscribtion was successfull.
        // onSubscribeError is called when the thing is not reachable or when the event doesn’t exist
        thing.event.on("colorTemperatureChanged", colorTemperatureChangedCallback).then(onSubscribeSuccess).catch(onSubscribeError);
        // Get reachability of the Thing. Reachability may change during runtime.
        thing.getReachability().then(function(reachability) {
               // reachability.value may be kept up-to-date by the UA as long as the reachability
               // object is alive. It is advised for the web developers to discard the object
               // as soon as it's not needed.
               handleReachabilityChange(reachability.value);
               // reachability.onchange is executed each time the reachability is changed.
               // For example when the device in not the range of the LED or the LED is not available anymore.
               reachability.onchange = function() { handleReachabilityChange(this.value);}
        });
        // the Web App may store the thing.id in localStorage or somewhere else
        // and requests access to the Thing after reload the Web App using
        var thingId = thing.id;
        localStorage.setItem("thingId", thingId);
        var thingType = thing.type;
        var thingName = thing.name;
};
// onError will be called when the user cancels the selection dialog.
var onError = function(err){
        console.error("Unexpected Error", err);
};
// start the request will display the Thing Selection Dialog.
req.start().then(onSuccess).catch(onError);

// This call is relevant when the page is reloaded, but the app already accessed the thing before and stored its Id in the Storage.
var thingId = localStorage.getItem("thingId");
thingId && navigator.things.getById(thingId).then(function(thing){
        thing.getReachability().then(function(reachability) {
               if(reachability.value){
                       // access thing in the same way as described above
               }
        });
}).catch(function(err){
        console.error("Error on get thing by Id", err);
});





Best regards,

Louay



[1] http://cordova.apache.org/docs/en/5.0.0/guide_hybrid_plugins_index.md.html#Plugin%20Development%20Guide


[2]: https://w3c.github.io/presentation-api/


[3]: <https://github.com/w3c/wot/blob/master/TF-TD/TD%20Samples/led.jsonld>  https://github.com/w3c/wot/blob/master/TF-TD/TD%20Samples/led.jsonld




> -----Original Message-----

> From: Soumya Kanti Datta [mailto:Soumya-Kanti.Datta@eurecom.fr]

> Sent: Donnerstag, 10. September 2015 08:57

> To: public-wot-ig@w3.org

> Subject: [TF-DI] Next Meeting

>

> Hi all,

>

> I regret to inform you that the TF-DI meeting today is postponed. I am

> currently attending a conference where my presentation session overlaps

> with TF-DI time slot and no one else is available to chair the session.

>

> Regards

> Soumya

>

> --

> Research Engineer, Eurecom, France | +33658194342 | @skdatta2010

> https://sites.google.com/site/skdunfolded | Skype id: soumyakantidatta

>

Received on Monday, 21 September 2015 08:24:56 UTC