[Iotcon] guide for Iotcon Web API 57/100257/10
authorJakub Skowron <j.skowron@samsung.com>
Fri, 25 Nov 2016 14:43:04 +0000 (15:43 +0100)
committerEditor Lionbridge <TizenEditor.SEL@lionbridge.com>
Thu, 8 Dec 2016 07:57:52 +0000 (09:57 +0200)
PS7: [LB] Reviewed
PS10: [LB] Repushed the editing changes to the iotcon_w.htm file from PS7 (they
had been overwritten). Also fixed the open issue related to the
optional/mandatory TV profile.

Change-Id: Ia40ec66b41cad4d953006d183bbc3572bde2e83b
Signed-off-by: Jakub Skowron <j.skowron@samsung.com>
Signed-off-by: Mateusz Bruno-Kaminski <m.bruno2@samsung.com>
Signed-off-by: jk.pu <jk.pu@samsung.com>
org.tizen.guides/html/index.htm
org.tizen.guides/html/web/connectivity/connectivity_cover_w.htm
org.tizen.guides/html/web/connectivity/iotcon_w.htm [new file with mode: 0644]
org.tizen.guides/index.xml

index 4320300..693e15b 100644 (file)
                                                <li><a href="web/connectivity/task_bluetoothchat_w.htm">Task: Bluetooth Chat</a></li>
                                        </ul>
                                </li>
+                               <li><a href="web/connectivity/iotcon_w.htm">IoTivity</a></li>
                                <li><a href="web/connectivity/nfc_w.htm">NFC</a>
                                        <ul>
                                                <li><a href="web/connectivity/task_contactsexchanger_w.htm">Task: Contacts Exchanger</a></li>
index 0973140..15029de 100644 (file)
@@ -33,7 +33,7 @@
 <div id="container"><div id="contents"><div class="content">
 <h1>Connectivity and Wireless</h1>
 
-<p>The connectivity and wireless features introduce how you can manage wireless connections to other devices and networks. They also describe how you can download content, and send and receive data in your application.</p>
+<p>The connectivity and wireless features introduce how you can manage wireless connections to other devices and networks, including IoT connectivity. They also describe how you can download content, and send and receive data in your application.</p>
 
 <p>You can use the following connectivity and wireless features in your Web applications:</p>
 
 
 <p>You can use Bluetooth functionalities in your application, such as managing the Bluetooth service, pairing, and exchanging messages. The Bluetooth standard provides a peer-to-peer (P2P) data exchange functionality over short distance between compliant devices.</p></li>
 
+<li><a href="iotcon_w.htm">IoTivity</a>
+
+<p>You can use IoTivity in Tizen. You can use the seamless device-to-device connectivity to address the needs of the Internet of Things (IoT) through the open source reference implementation of the OIC (Open Interconnect Consortium) standard specifications.</p></li>
+
 <li><a href="nfc_w.htm">Near Field Communication (NFC)</a> <strong>in mobile and wearable applications only</strong>
 
 <p>With NFC, you can share contacts, photos, and videos, use the device as a smart card, and communicate with other NFC-enabled devices. You can use an NFC-enabled device to communicate with NFC tags for a variety of activities, such as paying the grocery bill or downloading a coupon.</p></li>
diff --git a/org.tizen.guides/html/web/connectivity/iotcon_w.htm b/org.tizen.guides/html/web/connectivity/iotcon_w.htm
new file mode 100644 (file)
index 0000000..ead1e6b
--- /dev/null
@@ -0,0 +1,536 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+
+<head>
+  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+  <meta http-equiv="X-UA-Compatible" content="IE=9" />
+  <link rel="stylesheet" type="text/css" href="../../css/styles.css" />
+  <link rel="stylesheet" type="text/css" href="../../css/snippet.css" />
+  <script type="text/javascript" src="../../scripts/snippet.js"></script>
+  <script type="text/javascript" src="../../scripts/jquery.util.js" charset="utf-8"></script>
+  <script type="text/javascript" src="../../scripts/common.js" charset="utf-8"></script>
+  <script type="text/javascript" src="../../scripts/core.js" charset="utf-8"></script>
+  <script type="text/javascript" src="../../scripts/search.js" charset="utf-8"></script>
+  <title>IoTivity</title>
+</head>
+
+<body onload="prettyPrint()" style="overflow: auto;">
+
+  <div id="toc-navigation">
+    <div id="profile">
+      <p><img alt="Mobile Web" src="../../images/mobile_s_w_optional.png" /> <img alt="Wearable Web" src="../../images/wearable_s_w_optional.png"
+        /> <img alt="TV Web" src="../../images/tv_s_w.png" /></p>
+    </div>
+
+    <div id="toc_border">
+      <div id="toc">
+        <p class="toc-title">Dependencies</p>
+        <ul class="toc">
+          <li>Tizen 3.0 and Higher for Mobile</li>
+                 <li>Tizen 3.0 and Higher for Wearable</li>
+                 <li>Tizen 3.0 and Higher for TV</li>
+        </ul>
+        <p class="toc-title">Content</p>
+        <ul class="toc">
+          <li><a href="#prerequisites">Prerequisites</a></li>
+          <li><a href="#create-resource">Creating a New Resource</a></li>
+          <li><a href="#find-resources">Finding Remote Resources</a></li>
+          <li><a href="#find-device-infos">Retrieving Device and Platform Information</a></li>
+          <li><a href="#remote-get">Sending GET Requests</a></li>
+          <li><a href="#remote-put">Sending PUT Requests</a></li>
+          <li><a href="#remote-state-change">Observing Resource Changes</a></li>
+        </ul>
+        <p class="toc-title">Related Info</p>
+        <ul class="toc">
+          <li><a href="../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/iotcon.html">Iotcon API for Mobile Web</a></li>
+          <li><a href="../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/iotcon.html">Iotcon API for Wearable Web</a></li>
+          <li><a href="../../../../org.tizen.web.apireference/html/device_api/tv/tizen/iotcon.html">Iotcon API for TV Web</a></li>
+        </ul>
+      </div>
+    </div>
+  </div>
+
+<div id="container"><div id="contents"><div class="content">
+
+<h1>IoTivity</h1>
+
+<p><a href="https://www.iotivity.org/" target="_blank">IoTivity</a> offers seamless device-to-device connectivity to address the emerging needs of the Internet of Things (IoT) through the open source reference implementation of the OIC (Open Interconnect Consortium) standard specifications. IoT connectivity (Iotcon) provides the means of using IoTivity in Tizen.</p>
+
+<p>The Iotcon API is optional for both Tizen mobile and wearable profiles, which means that it may not be supported in all mobile and wearable devices. The Iotcon API is supported on the Tizen Emulators.</p>
+                 
+<p>IoT connectivity is usually handled with a server and client. The server is responsible for creating and providing resources, and the client can access those resources through requests.</p>
+
+
+<p>The main features of the Iotcon API include:</p>
+<ul>
+  <li>Creating a server
+       <p>You can <a href="#create-resource">create a resource</a> and send a presence event to the client when it becomes online.</p>
+  </li>
+  <li>Managing resources
+       <p>You can add types and interfaces to an existing resource.</p>
+  </li>
+  <li>Creating a client
+       <p>You can <a href="#find-resources">find remote resources</a>, <a href="#find-device-infos">retrieve device and platform information</a>, and listen for server presence events.</p>
+  </li>
+  <li>Remotely managing resources
+       <p>You can <a href="#remote-get">retrieve</a> and <a href="#remote-put">modify</a> the remote resource attributes with GET and PUT methods. You can also use POST and DELETE methods to modify the resources on a remote server. You can <a href="#remote-state-change">monitor the resource attribute changes and the <span style="font-family: Courier New,Courier,monospace">isAlive</span> state</a>.</p>
+       <p>For more information on all available remote resource management methods, see the native <a href="../../native/connectivity/iotivity_n.htm">IoTivity</a> guide.</p>
+  </li>
+</ul>
+
+<p>Before you start, remember to <a href="#prerequisites">prepare your application to use the IoT functionality</a>.</p>
+
+<h2>Warm-up</h2>
+<p>Become familiar with the Iotcon API basics by learning about:</p>
+<ul>
+  <li><a href="#prerequisites">Prerequisites</a>
+       <p>Prepare your application to use the IoT functionality.</p>
+  </li>
+  <li><a href="#create-resource">Creating a New Resource</a>
+       <p>Create a server, create a resource, and register a request handler.</p>
+  </li>
+  <li><a href="#find-resources">Finding Remote Resources</a>
+       <p>Create a client and find the resources.</p>
+  </li>
+  <li><a href="#find-device-infos">Retrieving Device and Platform Information</a>
+       <p>Get device and platform information from the server.</p>
+  </li>
+  <li><a href="#remote-get">Sending GET Requests</a>
+       <p>Get information from the resources.</p>
+  </li>
+  <li><a href="#remote-put">Sending PUT Requests</a>
+       <p>Update the resource information.</p>
+  </li>
+  <li><a href="#remote-state-change">Observing Resource Changes</a>
+       <p>Monitor attribute and state changes in a remote resource.</p>
+  </li>
+</ul>
+
+<h2 id="prerequisites">Prerequisites</h2>
+
+<p>To enable your application to use the IoT functionality:</p>
+
+<ol>
+<li>To use the Iotcon API (in <a href="../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/iotcon.html">mobile</a>, <a href="../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/iotcon.html">wearable</a>, and <a href="../../../../org.tizen.web.apireference/html/device_api/tv/tizen/iotcon.html">TV</a> applications), the application has to request permission by adding the following privilege to the <span style="font-family: Courier New,Courier,monospace">config.xml</span> file:
+<pre class="prettyprint">
+&lt;tizen:privilege name=&quot;http://tizen.org/privilege/internet&quot;/&gt;
+</pre>
+</li>
+<li>To make your application visible only for devices that support Iotcon, the application must specify the following feature in the <span style="font-family: Courier New,Courier,monospace">config.xml</span> file: 
+
+<pre class="prettyprint">
+&lt;feature name=&quot;http://tizen.org/feature/iot.ocf&quot;/&gt;
+</pre>
+
+<p>You can also check whether a device supports the API by using the <span style="font-family: Courier New,Courier,monospace">tizen.systeminfo.getCapability()</span> method and accordingly enabling or disabling the code requiring the API:</p>
+
+<pre class="prettyprint">
+try
+{
+&nbsp;&nbsp;&nbsp;/* Checks whether a device supports the Iotcon API */
+&nbsp;&nbsp;&nbsp;var iotcon_feature = tizen.systeminfo.getCapability(&quot;http://tizen.org/feature/iot.ocf&quot;);
+&nbsp;&nbsp;&nbsp;console.log(&quot;Iotcon = &quot; + iotcon_feature);
+}
+catch (error)
+{
+&nbsp;&nbsp;&nbsp;console.log(&quot;Error name: &quot; + error.name + &quot;, message: &quot; + error.message);
+}
+</pre>
+</li>
+</ol>
+
+<p>For details on OIC IoT standard specifications, see the <a href="https://openconnectivity.org/" target="_blank">Open Connectivity Foundation (OCF) Web site</a>.</p>
+
+
+<h2 id="create-resource">Creating a New Resource</h2>
+
+<p>To create a new resource:</p>
+
+<ol>
+<li>Initialize a server and set the device name:
+<ol type="a">
+<li>
+  <p>For managing secure virtual resources, a CBOR format file (Concise Binary Object Representation) must be
+       available, preferably in the application local storage. For more information on security, see <a href="https://wiki.iotivity.org/iotivity_security" target="_blank">Iotivity Security</a>.</p>
+<pre class="prettyprint">
+var cborPath = &quot;path_to_my_app_storage/iotcon-server-test.dat&quot;;
+</pre>
+</li>
+<li>
+  <p>Initialize Iotcon and set a human friendly name:</p>
+<pre class="prettyprint">
+tizen.iotcon.initialize(cborPath);
+tizen.iotcon.deviceName = &quot;Device 1&quot;;
+</pre>
+</li>
+<li>
+  <p>Get the Iotcon server object:</p>
+<pre class="prettyprint">
+var iotServer = tizen.iotcon.getServer();
+</pre>
+</li>
+</ol>
+</li>
+<li>Prepare a resource:
+<ol type="a">
+<li>
+  <p>On the server side, prepare a variable for storing the resource object and its attributes. The following example shows a door resource:</p>
+<pre class="prettyprint">
+var doorResource;
+var doorAttributes = {openstate: &quot;open&quot;};
+</pre>
+</li>
+<li>
+  <p>Prepare handlers for the get, put, post, delete, and observing requests from the client.</p>
+<p>The exact list of required handlers depends on the resource interfaces. The following example uses the &quot;oic.if.b&quot; interface.</p>
+<pre class="prettyprint">
+var requestCallbacks =
+{
+&nbsp;&nbsp;&nbsp;onget: function(request) {/* Handler code */},
+&nbsp;&nbsp;&nbsp;onput: function(request) {/* Handler code */},
+&nbsp;&nbsp;&nbsp;onpost: function(request) {/* Handler code */},
+&nbsp;&nbsp;&nbsp;ondelete: function(request) {/* Handler code */},
+&nbsp;&nbsp;&nbsp;onobserving: function(request, observeType, observeId) {/* Handler code */}
+}
+</pre>
+</li>
+<li>
+  <p>Fill the <span style="font-family: Courier New,Courier,monospace">onget</span> handler with a code that sends a response to the client. Other handlers remain empty in this example (you can modify attributes in them).</p>
+  <p>To send a response to the client:</p>
+  <ol type="a">
+       <li>Create a new <span style="font-family: Courier New,Courier,monospace">Response</span> object (in <a href="../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/iotcon.html#Response">mobile</a>, <a href="../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/iotcon.html#Response">wearable</a>, and <a href="../../../../org.tizen.web.apireference/html/device_api/tv/tizen/iotcon.html#Response">TV</a> applications) from the <span style="font-family: Courier New,Courier,monospace">Request</span> object (in <a href="../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/iotcon.html#Request">mobile</a>, <a href="../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/iotcon.html#Request">wearable</a>, and <a href="../../../../org.tizen.web.apireference/html/device_api/tv/tizen/iotcon.html#Request">TV</a> applications): <span style="font-family: Courier New,Courier,monospace">new tizen.Response(request)</span></li>
+       <li>Create a new <span style="font-family: Courier New,Courier,monospace">Representation</span> object (in <a href="../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/iotcon.html#Representation">mobile</a>, <a href="../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/iotcon.html#Representation">wearable</a>, and <a href="../../../../org.tizen.web.apireference/html/device_api/tv/tizen/iotcon.html#Representation">TV</a> applications), to be sent inside the response: <span style="font-family: Courier New,Courier,monospace">new tizen.Representation(doorResource.uriPath)</span></li>
+       <li>Fill the <span style="font-family: Courier New,Courier,monospace">Representation</span> object with values from the resource object.</li>
+       <li>Send the response: <span style="font-family: Courier New,Courier,monospace">response.send()</span></li>
+  </ol>
+
+<pre class="prettyprint">
+var requestCallbacks =
+{
+&nbsp;&nbsp;&nbsp;onget: function(request)
+&nbsp;&nbsp;&nbsp;{
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(&quot;onget&quot;);
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var response = new tizen.Response(request);
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var representation = new tizen.Representation(doorResource.uriPath);
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;representation.resourceTypes = doorResource.resourceTypes;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;representation.resourceInterfaces = doorResource.resourceInterfaces;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;representation.attributes = doorAttributes;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.representation = representation;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.result = &quot;SUCCESS&quot;;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;catch (err)
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(err.name + &quot;: &quot; + err.message);
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.result = &quot;ERROR&quot;;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.send();
+&nbsp;&nbsp;&nbsp;},
+}
+</pre>
+</li>
+<li>
+  <p>Create a resource using the prepared handlers, chosen resource path, types, and interfaces:</p>
+<pre class="prettyprint">
+var uriPath = &quot;/door&quot;;
+var resourceTypes = [&quot;core.door&quot;];
+var resourceInterfaces = [&quot;oic.if.b&quot;];
+var policy =
+{
+&nbsp;&nbsp;&nbsp;isObservable: true,
+&nbsp;&nbsp;&nbsp;isDiscoverable: true
+};
+
+doorResource = iotServer.createResource(uriPath, resourceTypes, resourceInterfaces, requestCallbacks, policy);
+</pre>
+</li>
+</ol>
+</li></ol>
+
+<h2 id="find-resources">Finding Remote Resources</h2>
+
+<p>To find remote resources:</p>
+
+<ol>
+<li>Initialize a client and set the device name:
+<ol type="a">
+<li>
+  <p>For managing secure virtual resources, a CBOR format file (Concise Binary Object Representation) must be
+       available, preferably in the application local storage. For more information on security, see <a href="https://wiki.iotivity.org/iotivity_security" target="_blank">Iotivity Security</a>.</p>
+<pre class="prettyprint">
+var cborPath = &quot;path_to_my_app_storage/iotcon-client-test.dat&quot;;
+</pre>
+</li>
+<li>
+  <p>Initialize Iotcon and set a human friendly name:</p>
+<pre class="prettyprint">
+tizen.iotcon.initialize(cborPath);
+tizen.iotcon.deviceName = &quot;Device 2&quot;;
+</pre>
+</li>
+<li>
+  <p>Get the Iotcon client object:</p>
+<pre class="prettyprint">
+var iotClient = tizen.iotcon.getClient();
+</pre>
+</li>
+</ol>
+<p>Now you can use the <span style="font-family: Courier New,Courier,monospace">iotClient</span> methods for IoT connectivity with the server.</p>
+</li>
+<li>On the client side, search for resources on servers:
+<ol type="a">
+<li>
+  <p>Get the client object:</p>
+<pre class="prettyprint">
+var client = tizen.iotcon.getClient();
+</pre>
+</li>
+<li>
+  <p>Set the remote server address and connectivity type.</p>
+  <p>The <span style="font-family: Courier New,Courier,monospace">hostAddress</span> value must be in the Constrained Application Protocol (CoAP) format (<span style="font-family: Courier New,Courier,monospace">coap(s)://address:port</span>), for example, <span style="font-family: Courier New,Courier,monospace">coaps://[fe80::ae5a:14ff:fe24:b8fe]:12345</span> or <span style="font-family: Courier New,Courier,monospace">coaps://192.168.1.10:12345</span>. The <span style="font-family: Courier New,Courier,monospace">null</span> value indicates that the client communicates with all nodes (multicast).</p>
+<pre class="prettyprint">
+var hostAddress = null;
+var connectivityType = &quot;IP&quot;;
+</pre>
+</li>
+<li>
+  <p>Prepare a query. You can search for specific <span style="font-family: Courier New,Courier,monospace">resourceType</span> and <span style="font-family: Courier New,Courier,monospace">resourceInterface</span> values, and add an attribute filter:</p>
+<pre class="prettyprint">
+var query = {resourceType: &quot;core.door&quot;};
+</pre>
+  <p>For more information, see the Query interface (in <a href="../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/iotcon.html#Query">mobile</a>, <a href="../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/iotcon.html#Query">wearable</a>, and <a href="../../../../org.tizen.web.apireference/html/device_api/tv/tizen/iotcon.html#Query">TV</a> applications).</p>
+</li>
+<li>
+  <p>Find a resource:</p>
+<pre class="prettyprint">
+client.findResource(hostAddress, query, connectivityType, foundSuccess, onerror);
+</pre>
+<p>The <span style="font-family: Courier New,Courier,monospace">foundSuccess</span> and <span style="font-family: Courier New,Courier,monospace">onerror</span> parameters are success and error callbacks for an async operation:</p>
+<pre class="prettyprint">
+function onerror(err)
+{
+&nbsp;&nbsp;&nbsp;console.log(&quot;Failed to find resource: &quot; + err.message);
+}
+</pre>
+  <p>The success callback lists information, types, and interfaces for every found remote resource:</p>
+<pre class="prettyprint">
+function foundSuccess(resource)
+{
+&nbsp;&nbsp;&nbsp;if (resource)
+&nbsp;&nbsp;&nbsp;{
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(resource.uriPath);
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(resource.hostAddress);
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(resource.deviceId);
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var resourceTypes = resource.resourceTypes;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (var i in resourceTypes)
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(resourceTypes[i]);
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var resourceInterfaces = resource.resourceInterfaces;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (var i in resourceInterfaces)
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(resourceInterfaces[i]);
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
+&nbsp;&nbsp;&nbsp;}
+}
+</pre>
+</li>
+</ol>
+</li></ol>
+
+<h2 id="find-device-infos">Retrieving Device and Platform Information</h2>
+
+<p>On the client side, you can get device and platform information from the server for a given remote resource:</p>
+<ol>
+<li>
+  <p>Prepare the error and success callbacks:</p>
+<pre class="prettyprint">
+function onerror(err)
+{
+&nbsp;&nbsp;&nbsp;console.log(&quot;Failed to find resource: &quot; + err.message);
+}
+
+function foundSuccess(platformInfo)
+{
+&nbsp;&nbsp;&nbsp;console.log(platformInfo.platformId);
+&nbsp;&nbsp;&nbsp;console.log(platformInfo.modelNumber);
+&nbsp;&nbsp;&nbsp;console.log(platformInfo.platformVersion);
+&nbsp;&nbsp;&nbsp;console.log(platformInfo.operatingSystemVersion);
+&nbsp;&nbsp;&nbsp;console.log(platformInfo.systemTime);
+&nbsp;&nbsp;&nbsp;/* Other PlatformInfo object attributes; see the API Reference for details */
+}
+</pre>
+</li>
+<li>
+  <p>Get the client object:</p>
+<pre class="prettyprint">
+var client = tizen.iotcon.getClient();
+</pre>
+</li>
+<li>
+  <p>Prepare the server address, connectivity type, and query (with optional filters):</p>
+<pre class="prettyprint">
+/* hostAddress must be a valid IP address, or null for all nodes (multicast) */
+var hostAddress = &quot;coaps://192.168.0.10:12345&quot;;
+var connectivityType = &quot;IP&quot;;
+/* null means no filter */
+var query = null;
+</pre>
+</li>
+<li>Retrieve the information:
+<ul>
+<li>
+  <p>Get the platform information from the remote server:</p>
+<pre class="prettyprint">
+client.findPlatformInfo(hostAddress, query, connectivityType, foundSuccess, onerror);
+</pre>
+<p>The success callback is called with the <span style="font-family: Courier New,Courier,monospace">PlatformInfo</span> object (in <a href="../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/iotcon.html#PlatformInfo">mobile</a>, <a href="../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/iotcon.html#PlatformInfo">wearable</a>, and <a href="../../../../org.tizen.web.apireference/html/device_api/tv/tizen/iotcon.html#PlatformInfo">TV</a> applications) as a parameter. You can access the platform information in the object attributes.</p>
+</li>
+<li>
+  <p>Get the device information from the remote server:</p>
+<pre class="prettyprint">
+client.findDeviceInfo(hostDeviceIpAddress, query, connectivityType, foundSuccess, onerror);
+</pre>
+  <p>The success callback is called with the <span style="font-family: Courier New,Courier,monospace">DeviceInfo</span> object (in <a href="../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/iotcon.html#DeviceInfo">mobile</a>, <a href="../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/iotcon.html#DeviceInfo">wearable</a>, and <a href="../../../../org.tizen.web.apireference/html/device_api/tv/tizen/iotcon.html#DeviceInfo">TV</a> applications) as a parameter. You can access the device information in the object attributes.</p>
+</li>
+</ul></li>
+</ol>
+
+<h2 id="remote-get">Sending GET Requests</h2>
+<p>On the client side, you can read resource attributes:</p>
+<ol>
+<li>
+  <p>Prepare a callback for reading the attributes:</p>
+<pre class="prettyprint">
+function onresponse(remoteResponse)
+{
+&nbsp;&nbsp;&nbsp;if (remoteResponse.result != &quot;SUCCESS&quot;)
+&nbsp;&nbsp;&nbsp;{
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(&quot;the result is not SUCCESS&quot;);
+
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;
+&nbsp;&nbsp;&nbsp;}
+
+&nbsp;&nbsp;&nbsp;var repr = remoteResponse.representation;
+
+&nbsp;&nbsp;&nbsp;/* You can retrieve attributes from Representation object in RemoteResponse */
+&nbsp;&nbsp;&nbsp;for (var key in repr.attributes)
+&nbsp;&nbsp;&nbsp;{
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(key + &quot;: &quot; + repr.attributes[key]);
+&nbsp;&nbsp;&nbsp;}
+}
+</pre>
+</li>
+<li>
+  <p><a href="#find-resources">Find a remote resource</a>.</p>
+</li>
+<li>
+  <p>Once you have a <span style="font-family: Courier New,Courier,monospace">RemoteResource</span> object, use the <span style="font-family: Courier New,Courier,monospace">methodGet()</span> method to send a request to the server. For a list of resource attributes you can request, see the API Reference (in <a href="../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/iotcon.html#RemoteResource">mobile</a>, <a href="../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/iotcon.html#RemoteResource">wearable</a>, and <a href="../../../../org.tizen.web.apireference/html/device_api/tv/tizen/iotcon.html#RemoteResource">TV</a> applications).</p>
+<pre class="prettyprint">
+/* filter results, query = null means no filter */
+query[&quot;filter&quot;] = {openstate: &quot;open&quot;};
+resource.methodGet(onresponse, query, onerror);
+</pre>
+  <p>As a result, the <span style="font-family: Courier New,Courier,monospace">onresponse</span> or (optional) <span style="font-family: Courier New,Courier,monospace">onerror</span> callback is called.</p>
+</li>
+</ol>
+
+<h2 id="remote-put">Sending PUT Requests</h2>
+<p>On the client side, you can modify remote resource attributes using the PUT method:</p>
+<ol>
+<li>
+  <p>Prepare a callback that is called after the PUT request:</p>
+<pre class="prettyprint">
+function onresponse(remoteResponse)
+{
+&nbsp;&nbsp;&nbsp;console.log(&quot;result is &quot; + remoteResponse.result);
+&nbsp;&nbsp;&nbsp;/* remoteResponse.result is expected to be &quot;RESOURCE_CHANGED&quot; */
+}
+</pre>
+</li>
+<li>
+  <p><a href="#find-resources">Find a remote resource</a>.</p>
+</li>
+<li>
+  <p>Once you have a <span style="font-family: Courier New,Courier,monospace">RemoteResource</span> object (in <a href="../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/iotcon.html#RemoteResource">mobile</a>, <a href="../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/iotcon.html#RemoteResource">wearable</a>, and <a href="../../../../org.tizen.web.apireference/html/device_api/tv/tizen/iotcon.html#RemoteResource">TV</a> applications), use the success callback to create a <span style="font-family: Courier New,Courier,monospace">Representation</span> object (in <a href="../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/iotcon.html#Representation">mobile</a>, <a href="../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/iotcon.html#Representation">wearable</a>, and <a href="../../../../org.tizen.web.apireference/html/device_api/tv/tizen/iotcon.html#Representation">TV</a> applications). This object represents the changes in attributes, types, and interfaces.</p>
+<pre class="prettyprint">
+representation = new tizen.Representation(uriPath);
+representation.resourceTypes = [&quot;core.door&quot;];
+representation.attributes = {openstate: &quot;closed&quot;};
+</pre>
+</li>
+<li>
+  <p>Call the <span style="font-family: Courier New,Courier,monospace">methodPut()</span> method on the <span style="font-family: Courier New,Courier,monospace">RemoteResource</span> object:</p>
+<pre class="prettyprint">
+/* Optional filter, query = null means no filter */
+query[&quot;filter&quot;] = {openstate: &quot;open&quot;}
+resource.methodPut(representation, onresponse, query, onerror);
+</pre>
+<p>After a successful request, the <span style="font-family: Courier New,Courier,monospace">onresponse</span> callback is called with the result and updated resource representation. In case of a failure, the (optional) <span style="font-family: Courier New,Courier,monospace">onerror</span> callback is called.</p>
+</li>
+</ol>
+
+
+<h2 id="remote-state-change">Observing Resource Changes</h2>
+
+<p>On the client side, you can observe remote resource attribute changes with the <span style="font-family: Courier New,Courier,monospace">startObserving()</span> method, and the <span style="font-family: Courier New,Courier,monospace">isAlive</span> state with the <span style="font-family: Courier New,Courier,monospace">setResourceStateChangeListener()</span> method:</p>
+<ol>
+<li>
+  <p><a href="#find-resources">Find a remote resource</a>.</p>
+</li>
+<li>
+  <p>Prepare a callback for state change events:</p>
+<pre class="prettyprint">
+function onchanged(isAlive)
+{
+&nbsp;&nbsp;&nbsp;if (isAlive == true)
+&nbsp;&nbsp;&nbsp;{
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(&quot;Remote resource is alive&quot;);
+&nbsp;&nbsp;&nbsp;}
+&nbsp;&nbsp;&nbsp;else
+&nbsp;&nbsp;&nbsp;{
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(&quot;Remote resource is lost&quot;);
+&nbsp;&nbsp;&nbsp;}
+}
+</pre>
+</li>
+<li>
+  <p>Register a listener on the <span style="font-family: Courier New,Courier,monospace">RemoteResource</span> object (in <a href="../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/iotcon.html#RemoteResource">mobile</a>, <a href="../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/iotcon.html#RemoteResource">wearable</a>, and <a href="../../../../org.tizen.web.apireference/html/device_api/tv/tizen/iotcon.html#RemoteResource">TV</a> applications):</p>
+<pre class="prettyprint">
+resource.setResourceStateChangeListener(onchanged);
+</pre>
+</li>
+<li>
+  <p>When the notifications are no longer needed, deregister the listener:</p>
+<pre class="prettyprint">
+resource.unsetResourceStateChangeListener();
+</pre>
+</li>
+</ol>
+<p>You can monitor attribute changes in a remote resource similarly using the <span style="font-family: Courier New,Courier,monospace">startObserving()</span> method on the <span style="font-family: Courier New,Courier,monospace">RemoteResource</span> object.</p>
+
+<script type="text/javascript" src="../../scripts/jquery.zclip.min.js"></script>
+<script type="text/javascript" src="../../scripts/showhide.js"></script>
+</div></div></div>
+
+<a class="top sms" href="#"><img src="../../images/btn_top.gif" alt="Go to top" /></a>
+
+<div id="footer">
+<p class="footer">Except as noted, this content - excluding the Code Examples - is licensed under <a href="http://creativecommons.org/licenses/by/3.0/legalcode" target="_blank">Creative Commons Attribution 3.0</a> and all of the Code Examples contained herein are licensed under <a href="https://www.tizen.org/bsd-3-clause-license" target="_blank">BSD-3-Clause</a>.<br/>For details, see the <a href="https://www.tizen.org/content-license" target="_blank">Content License</a>.</p>
+</div>
+
+<script type="text/javascript">
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-25976949-1']);
+_gaq.push(['_trackPageview']);
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
+</script>
+
+</body>
+
+</html>
\ No newline at end of file
index 000adf9..1850c32 100644 (file)
                <topic href="html/web/connectivity/bluetooth_w.htm" label="Bluetooth">
                        <topic href="html/web/connectivity/task_bluetoothchat_w.htm" label="Task: Bluetooth Chat"></topic>
                </topic>
+               <topic href="html/web/connectivity/iotcon_w.htm" label="IoTivity"></topic>
                <topic href="html/web/connectivity/nfc_w.htm" label="NFC">
                        <topic href="html/web/connectivity/task_contactsexchanger_w.htm" label="Task: Contacts Exchanger"></topic>
                </topic>