<p class="toc-title">Related Info</p>
<ul class="toc">
<li><a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_tutorial_w.htm">Bluetooth Tutorial</a></li>
- <li><a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_le_tutorial_w.htm">Bluetooth Low Energy Tutorial</a></li>
<li><a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html">Bluetooth API for Mobile Web</a></li>
<li><a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html">Bluetooth API for Wearable Web</a></li>
</ul>
<li>Managing the local Bluetooth adapter
<p>The <a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_tutorial_w.htm#Managing_BT_Adapter">Bluetooth adapter management</a> is performed the same way as in regular Bluetooth API.</p></li>
<li>Discovering Bluetooth Low Energy Devices
- <p>You can <a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_le_tutorial_w.htm#Discovering_BT_Devices">discover Bluetooth Low Energy devices</a> in range.
+ <p>You can <a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_tutorial_w.htm#Discovering_BT_LE_Devices">discover Bluetooth Low Energy devices</a> in range.
By this discovery process you will obtain basic information about available remote devices: their names, provided services etc.</p></li>
<li>Managing the Advertising Options
- <p>You can <a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_le_tutorial_w.htm#Managing_Advertising">managing the advertising</a> to control how your device announces itself to other Bluetooth Low Energy devices to be discovered.</p></li>
+ <p>You can <a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_tutorial_w.htm#Managing_Advertising">managing the advertising</a> to control how your device announces itself to other Bluetooth Low Energy devices to be discovered.</p></li>
<li>Connecting to a Bluetooth Low Energy Device
- <p>You can <a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_le_tutorial_w.htm#Connecting">connecting to a remote Bluetooth Low Energy device</a>. When connected you can access services and characteristics of the remote device.</p></li>
+ <p>You can <a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_tutorial_w.htm#Connecting">connecting to a remote Bluetooth Low Energy device</a>. When connected you can access services and characteristics of the remote device.</p></li>
<li>Receiving Notifications on Connection State Change
- <p>You can <a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_le_tutorial_w.htm#Connection_Notification">monitor the state of the connection</a> to detect when the connection to the remote device is lost.</p></li>
+ <p>You can <a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_tutorial_w.htm#Connection_Notification">monitor the state of the connection</a> to detect when the connection to the remote device is lost.</p></li>
<li>Retrieving Bluetooth GATT Services
- <p>You can <a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_le_tutorial_w.htm#Retrieving_Services">retrieve information about Bluetooth GATT Services</a> provided by the remote device.</p>
+ <p>You can <a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_tutorial_w.htm#Retrieving_Services">retrieve information about Bluetooth GATT Services</a> provided by the remote device.</p>
<p>Every GATT service defines characteristics it includes. By knowing the service you know what features the Bluetooth device exposes.</p></li>
<li>Accessing Bluetooth GATT Characteristic Value
- <p>You can <a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_le_tutorial_w.htm#Characteristic_Value">read and write Bluetooth GATT characteristic value</a>.</p>
+ <p>You can <a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_tutorial_w.htm#Characteristic_Value">read and write Bluetooth GATT characteristic value</a>.</p>
<p>Characteristics allows you to monitor and sometimes control remote Bluetooth Low Energy devices. For example a sensor reading can be exposed by the sensor device as a Bluetooth GATT characteristic.</p></li>
<li>Receiving Notification on Characterictic Value Change
- <p>You can <a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_le_tutorial_w.htm#Characterictic_Notification">monitor changes of a characterictic value</a> to detect change for example in sensor reading, battery level and so on.</p></li>
+ <p>You can <a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_tutorial_w.htm#Characterictic_Notification">monitor changes of a characterictic value</a> to detect change for example in sensor reading, battery level and so on.</p></li>
<li>Accessing Bluetooth GATT Descriptor Value
- <p>You can <a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_le_tutorial_w.htm#Descriptor_Value">read and write Bluetooth GATT descriptor value</a>.</p></li>
+ <p>You can <a href="../../../../../org.tizen.tutorials/html/web/tizen/communication/bluetooth_tutorial_w.htm#Descriptor_Value">read and write Bluetooth GATT descriptor value</a>.</p></li>
</ul>
<li><a href="web/tizen/communication/task_bluetoothchat_w.htm">Task: Bluetooth Chat</a></li>
</ul>
</li>
- <li><a href="web/tizen/communication/bluetooth_le_tutorial_w.htm">Bluetooth Low Energy</a></li>
<li><a href="web/tizen/communication/nfc_tutorial_w.htm">NFC</a>
<ul>
<li><a href="web/tizen/communication/task_contactsexchanger_w.htm">Task: Contacts Exchanger</a></li>
+++ /dev/null
-<!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>Bluetooth: Managing a Bluetooth Low Evergy Device</title>
-</head>
-
-<body onload="prettyPrint()" style="overflow: auto;">
-
-<div id="toc-navigation">
- <div id="profile">
- <p><img alt="Mobile Web" src="../../../images/mw_icon_optional.png"/><img alt="Wearable Web" src="../../../images/ww_icon_optional.png"/></p>
- </div>
- <div id="toc_border"><div id="toc">
- <p class="toc-title">Content</p>
- <ul class="toc">
- <li><a href="#Managing_BT_Adapter">Managing the Local Bluetooth Adapter</a></li>
- <li><a href="#Discovering_BT_Devices">Discovering Bluetooth Low Energy Devices</a></li>
- <li><a href="#Managing_Advertising">Managing the Advertising Options</a></li>
- <li><a href="#Connecting">Connecting to a Bluetooth Low Energy Device</a></li>
- <li><a href="#Connection_Notification">Receiving Notifications on Connection State Change</a></li>
- <li><a href="#Retrieving_Services">Retrieving Bluetooth GATT Services</a></li>
- <li><a href="#Characteristic_Value">Accessing Bluetooth GATT Characteristic Value</a></li>
- <li><a href="#Characterictic_Notification">Receiving Notification on Characterictic Value Change</a></li>
- <li><a href="#Descriptor_Value">Accessing Bluetooth GATT Descriptor Value</a></li>
- </ul>
- <p class="toc-title">Related Info</p>
- <ul class="toc">
- <li><a href="../../../../../org.tizen.guides/html/web/tizen/communication/bluetooth_w.htm">Bluetooth Guide</a></li>
- <li><a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html">Bluetooth API for Mobile Web</a></li>
- <li><a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html">Bluetooth API for Wearable Web</a></li>
- </ul>
- </div></div>
-</div>
-
-<div id="container"><div id="contents"><div class="content">
-<h1>Bluetooth: Managing a Bluetooth Low Energy Device</h1>
-<div class="cont"><div class="static-cont">
-
-
- <p>This tutorial demonstrates how you can manage Bluetooth Low Energy and exchange data with a peer device.</p>
-
- <table class="note">
-<tbody>
- <tr>
- <th class="note">Note</th>
- </tr>
- <tr>
- <td class="note">The Bluetooth API is optional for both Tizen mobile and wearable profiles, which means that it may not be supported in all mobile and wearable devices.</td>
- </tr>
- <tr>
- <td class="note">The Bluetooth API is not supported on any Tizen Emulators.</td>
- </tr>
- </tbody>
- </table>
-
- <h2 id="warm_up" name="warm_up">Warm-up</h2>
- <p>Become familiar with the Bluetooth API basics by learning about:</p>
- <ul>
- <li><a href="#Managing_BT_Adapter">Managing the Local Bluetooth Adapter</a> <p>Enable and disable the local Bluetooth adapter, and change the device name for it.</p></li>
- <li><a href="#Discovering_BT_Devices">Discovering Bluetooth Low Energy Devices</a> <p>Search for remote devices.</p></li>
- <li><a href="#Managing_Advertising">Managing the Advertising Options</a> <p>Manage what information is advertised to any Bluetooth Low Energy device in the proximity.</p></li>
- <li><a href="#Connecting">Connecting to a Bluetooth Low Energy Device</a> <p>Connect to one of the detected Bluetooth Low Energy devices.</p></li>
- <li><a href="#Connection_Notification">Receiving Notifications on Connection State Change</a> <p>Monitor the state of connection to a remote Bluetooth Low Energy device.</p></li>
- <li><a href="#Retrieving_Services">Retrieving Bluetooth GATT Services</a> <p>Check information about Bluetooth GATT services provided by a remote device.</p></li>
- <li><a href="#Characteristic_Value">Accessing Bluetooth GATT Characteristic Value</a> <p>Read and write a value of Bluetooth GATT characteristic of a remote device.</p></li>
- <li><a href="#Characterictic_Notification">Receiving Notification on Characterictic Value Change</a> <p>Monitor changes in a Bluetooth GATT characteristic value.</p></li>
- <li><a href="#Descriptor_Value">Accessing Bluetooth GATT Descriptor Value</a> <p>Read and write a value of Bluetooth GATT characteristic descriptor of a remote device.</p></li>
- </ul>
-
-<div class="devicespecs-util mt5 clfix">
- <ul class="dutil">
- <li><a href="#" class="showA">Show All</a></li>
- <li class="none"><a href="#" class="hideA">Hide All</a></li>
- </ul>
- </div>
-
- <ul class="devicespecifications">
- <li>
- <div class="devicespec-tit">
- <h2 id="Managing_BT_Adapter" name="Managing_BT_Adapter" class="items-tit-h2">Managing the Local Bluetooth Adapter</h2>
- <span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
- </div>
- <div class="devicespec-con">
-
- <p>To enable the Bluetooth device, request a built-in Settings application to present the relevant switch to the user so that they can enable or disable the Bluetooth. For details see the <a href="bluetooth_tutorial_w.htm#Managing_BT_Adapter">Managing the Local Bluetooth Adapter</a> section of the Bluetooth Tutorial.</p>
-
- </div>
- </li>
- <li>
- <div class="devicespec-tit">
- <h2 id="Discovering_BT_Devices" name="Discovering_BT_Devices" class="items-tit-h2">Discovering Bluetooth Low Energy Devices</h2>
- <span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
- </div>
- <div class="devicespec-con">
-
- <p>Learning how to search for remote devices is a basic Bluetooth management skill:</p>
- <ol>
- <li><p>Define a scan events handler by implementing the <span style="font-family: Courier New,Courier,monospace">BluetoothLEScanCallback</span> (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEScanCallback">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEScanCallback">wearable</a> applications).
- A callback is invoked to notify that the scan has started, a remote device has been detected, and when the scan is finished.</p>
-<pre class="prettyprint">
-var callbacks = {
- onstarted: function() {
- console.log("Scan started");
- },
- ondevicefound: function(device) {
- console.log("Found device: " + device.name + " [" + device.address + "]");
- },
- onfinished: function(devices) {
- console.log("Scan finished. Found " + devices.length + " devices.");
- }
-};
-</pre>
- <table class="note">
- <tbody>
- <tr>
- <th class="note">Note</th>
- </tr>
- <tr>
- <td class="note">To allow other Bluetooth devices to find your device, you must set the device to be visible through the system settings.</td>
- </tr>
- </tbody>
- </table> </li>
-
- <li><p>Retrieve a <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> object with the <span style="font-family: Courier New,Courier,monospace">getLEAdapter()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothManager::getLEAdapter">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothManager::getLEAdapter">wearable</a> applications) method:</p>
-<pre class="prettyprint">var adapter = tizen.bluetooth.getLEAdapter();</pre>
- </li>
-
- <li><p>To search for remote devices, use the <span style="font-family: Courier New,Courier,monospace">startScan()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter::startScan">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter::startScan">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> interface.</p>
-<pre class="prettyprint">adapter.startScan(callbacks);</pre>
- </li>
- <li><p>Finally, when you find the right remote device or the user cancels the scanning, disable the scan using the <span style="font-family: Courier New,Courier,monospace">stopScan()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter::stopScan">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter::stopScan">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> interface.</p>
-<pre class="prettyprint">adapter.stopScan();</pre>
- </li>
-
- </ol>
-
- </div>
- </li>
-
- <li>
- <div class="devicespec-tit">
- <h2 id="Managing_Advertising" name="Managing_Advertising" class="items-tit-h2">Managing the Advertising Options</h2>
- <span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
- </div>
- <div class="devicespec-con">
-
- <p>Learning how to control what information are advertised by the device is a usefull Bluetooth Low Energy skill:</p>
- <p>Bluetooth Low Energy technology allows a device to broadcast some information without any need of connection between devices. Bluetooth Low Energy API provides methods to control this advertising/broadcasting.</p>
- <ol>
- <li><p>Retrieve a <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> object with the <span style="font-family: Courier New,Courier,monospace">getLEAdapter()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothManager::getLEAdapter">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothManager::getLEAdapter">wearable</a> applications):</p>
-<pre class="prettyprint">var adapter = tizen.bluetooth.getLEAdapter();</pre>
- </li>
-
- <li><p>Setup options and start advertising with the <span style="font-family: Courier New,Courier,monospace">startAdvertise()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter::startAdvertise">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter::startAdvertise">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> interface</p>
-<pre class="prettyprint">
-var advertiseData = new tizen.BluetoothLEAdvertiseData({
- includeName: true,
- serviceuuids: ["180f"] // 180F is 16bit Battery Service UUID
-});
-var connectable = true;
-
-adapter.startAdvertise(
- advertiseData,
- "ADVERTISE",
- function onstate(state)
- {
- console.log("Advertising configured: " + state);
- },
- function(error)
- {
- console.log("startAdvertise() failed: " + error.message);
- },
- "LOW_LATENCY",
- connectable
-);
-</pre>
- <table class="note">
- <tbody>
- <tr>
- <th class="note">Note</th>
- </tr>
- <tr>
- <td class="note">To learn how to make your mobile device visible to other Bluetooth devices see the <a href="bluetooth_tutorial_w.htm#Managing_BT_Adapter">Managing the Local Bluetooth Adapter</a> section of the Bluetooth Tutorial. </td>
- </tr>
- </tbody>
- </table>
- </li>
- <li><p>To disable the advertising <span style="font-family: Courier New,Courier,monospace">stopAdvertise()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter::stopAdvertise">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter::stopAdvertise">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> interface.</p>
-<pre class="prettyprint">adapter.stopAdvertise();</pre>
- </li>
- </ol>
- </div>
- </li>
-
- <li>
- <div class="devicespec-tit">
- <h2 id="Connecting" name="Connecting" class="items-tit-h2">Connecting to a Bluetooth Low Energy Device</h2>
- <span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
- </div>
- <div class="devicespec-con">
-
- <p>Learning how to connect to other devices is a basic Bluetooth Low Energy management skill:</p>
- <ol>
- <li><p>Retrieve a <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> object with the <span style="font-family: Courier New,Courier,monospace">getLEAdapter()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothManager::getLEAdapter">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothManager::getLEAdapter">wearable</a> applications):
- </p>
-<pre class="prettyprint">var adapter = tizen.bluetooth.getLEAdapter();
-</pre></li>
- <li><p>Define a success and error callbacks for a connect operation:</p>
-<pre class="prettyprint">
-function connectFail(error) {
- console.log("Failed to connect to device: " + e.message);
-}
-
-function connectSuccess() {
- console.log("Connected to device");
-}
-</pre>
- </li>
-
- <li><p>Define a callback for scan operation which will connect to any device found and stop the scan.</p>
- <p>Within the callback request establishing a connection with the found device using the <span style="font-family: Courier New,Courier,monospace">connect()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice::connect">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice::connect">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice">wearable</a> applications):
-<pre class="prettyprint">
-var remoteDevice = null;
-
-function onDeviceFound(device)
-{
- if (remoteDevice === null) {
- remoteDevice = device;
- console.log("Found device " + device.name + ". Connecting...");
-
- device.connect(connectSuccess, connectFail);
- }
-
- adapter.stopScan();
-}
-</pre>
- </li>
-
- <li><p>Having all callbacks ready, initiate the Bluetooth Low Energy scan using the <span style="font-family: Courier New,Courier,monospace">startScan()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter::startScan">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter::startScan">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> adapter:</p>
-<pre class="prettyprint">adapter.startScan({
- ondevicefound: onDeviceFound
-});</pre></li>
-
- <li><p>When the connection to the remote device is no longer required, disconnect from the device by calling the <span style="font-family: Courier New,Courier,monospace">disconnect()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice::disconnect">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice::disconnect">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface:</p>
-<pre class="prettyprint">remoteDevice.disconnect();</pre></li>
-
- </ol>
- </div>
- </li>
- <li>
- <div class="devicespec-tit">
- <h2 id="Connection_Notification" name="Connection_Notification" class="items-tit-h2">Receiving Notifications on Connection State Change</h2>
-<span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
- </div>
- <div class="devicespec-con">
-
- <p>Learning how to receive notifications whenever the device connection is established or lost is a useful Bluetooth management skill:</p>
- <ol>
-
- <li><p>Retrieve a <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> object with the <span style="font-family: Courier New,Courier,monospace">getLEAdapter()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothManager::getLEAdapter">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothManager::getLEAdapter">wearable</a> applications):
- </p>
-<pre class="prettyprint">var adapter = tizen.bluetooth.getLEAdapter();
-</pre></li>
- <li><p>Define a connection state change listener by implementing the <span style="font-family: Courier New,Courier,monospace">BluetoothLEConnectChangeCallback</span> (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEConnectChangeCallback">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEConnectChangeCallback">wearable</a> applications):</p>
-<pre class="prettyprint">
-var connectionListener = {
- onconnected: function(device) {
- console.log("Connected to the device: " + device.name + " [" + device.address + "]");
- },
- ondisconnected: function(device) {
- console.log("Disconnected from the device " + device.name + " [" + device.address + "]");
- }
-};
-</pre>
- </li>
-
- <li><p>Define a callback for scan operation which will connect to any device found and stop the scan.</p>
- <p>Within the callback register a connection state change listener using the <span style="font-family: Courier New,Courier,monospace">addConnectStateChangeListener()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice::addConnectStateChangeListener">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice::addConnectStateChangeListener">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface:
-<pre class="prettyprint">
-var remoteDevice = null;
-var watchId;
-
-function onDeviceFound(device)
-{
- if (remoteDevice === null) {
- remoteDevice = device;
- console.log("Found device " + device.name + ". Connecting...");
-
- watchId = remoteDevice.addConnectStateChangeListener(connectionListener);
-
- remoteDevice.connect();
- }
-
- adapter.stopScan();
-}
-</pre>
- </li>
-
- <li><p>Having all callbacks ready, initiate the Bluetooth Low Energy scan:</p>
-<pre class="prettyprint">adapter.startScan({
- ondevicefound: onDeviceFound
-});</pre></li>
-
- <li><p>When the notifications about the connection are no longer required, unregister the listener from the device by calling the <span style="font-family: Courier New,Courier,monospace">removeConnectStateChangeListener()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice::removeConnectStateChangeListener">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice::removeConnectStateChangeListener">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface:</p>
-<pre class="prettyprint">remoteDevice.removeConnectStateChangeListener(watchId);</pre></li>
- </ol>
- </div>
- </li>
- <li>
- <div class="devicespec-tit">
- <h2 id="Retrieving_Services" name="Retrieving_Services" class="items-tit-h2">Retrieving Bluetooth GATT Services</h2>
-<span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
- </div>
- <div class="devicespec-con">
-
- <p>Learning how to retrieve a list of GATT services (Generic Attribute) provided by a device is basic Bluetooth Low Energy management skill:</p>
- <ol>
-
- <li>Connect to any Bluetooth Low Energy device as described in the <a href="bluetooth_le_tutorial_w.htm#Connecting">Connecting to a Bluetooth Low Energy Device</a> section.</li>
- <li><p>Define a connection state change listener by implementing the <span style="font-family: Courier New,Courier,monospace">BluetoothLEConnectChangeCallback</span> (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEConnectChangeCallback">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEConnectChangeCallback">wearable</a> applications):</p>
-<pre class="prettyprint">
-function showGATTService(service, indent)
-{
- if (indent === undefined) {
- indent = "";
- }
-
- console.log(indent + "Service " + service.uuid + ". Has " + service.characteristics.length + " characteristics and " + service.services.length + " sub-services.");
-
- for (var i = 0; i < service.services.length; i++) {
- showGATTService(service.services[i], indent + " ");
- }
-}
-</pre>
- </li>
- <li><p>Retrieve a list of GATT service uuids from the <span style="font-family: Courier New,Courier,monospace">uuids</span> attribute (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice::uuids">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice::uuids">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface:</p>
-<pre class="prettyprint">var serviceUUIDs = remoteDevice.uuids;</pre>
- </li>
- <li><p>Retrieve GATT service information using the <span style="font-family: Courier New,Courier,monospace">getService()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice::getService">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice::getService">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface for every service uuid:</p>
-<pre class="prettyprint">
-var i = 0, service = null;
-
-for (i; i < serviceUUIDs.length; i++) {
-
- service = remoteDevice.getService(serviceUUIDs[i]);
-
- showGATTService(service);
-}</pre>
- </li>
-
- </ol>
- </div>
- </li>
- <li>
- <div class="devicespec-tit">
- <h2 id="Characteristic_Value" name="Characteristic_Value" class="items-tit-h2">Accessing Bluetooth GATT Characteristic Value</h2>
-<span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
- </div>
- <div class="devicespec-con">
-
- <p>Learning how to read and write a value of Bluetooth Characteristic is a useful Bluetooth Low Energy management skill:</p>
- <ol>
-
- <li><p>Connect to any Bluetooth Low Energy device as described in the <a href="bluetooth_le_tutorial_w.htm#Connecting">Connecting to a Bluetooth Low Energy Device</a> section.</p></li>
- <li><p>Retrieve a list of GATT service uuids from the <span style="font-family: Courier New,Courier,monospace">uuids</span> attribute (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice::uuids">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice::uuids">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface:</p>
-<pre class="prettyprint">var serviceUUIDs = remoteDevice.uuids;</pre>
- </li>
- <li><p>Select one of the GATT services and use the <span style="font-family: Courier New,Courier,monospace">getService()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice::getService">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice::getService">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface to retrieve an object representing the service. In this example we use the first service:</p>
-<pre class="prettyprint">var gattService = remoteDevice.getService(serviceUUIDs[0]);</pre>
- </li>
- <li><p>Select the interesting characteristic from the <span style="font-family: Courier New,Courier,monospace">characteristics</span> attribute (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTService::characteristics">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTService::characteristics">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTService</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTService">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTService">wearable</a> applications). In this example we use the first of them:</p>
-<pre class="prettyprint">var property = gattService.characteristics[0];</pre>
- </li>
- <li><p>Define a callback implementing the <span style="font-family: Courier New,Courier,monospace">ReadValueSuccessCallback</span> which (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#ReadValueSuccessCallback">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#ReadValueSuccessCallback">wearable</a> applications) will receive the value of the characteristic:</p>
-<pre class="prettyprint">
-function readSuccess(value)
-{
- console.log("Characteristic value: " + value);
-}
-
-function readFail(error)
-{
- console.log("readValue() failed: " + error);
-}
-</pre>
- </li>
- <li><p>To retrieve GATT Characteristic value, use the <span style="font-family: Courier New,Courier,monospace">readValue()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTCharacteristic::readValue">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTCharacteristic::readValue">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTCharacteristic</span> interface:</p>
-<pre class="prettyprint">
-if (!property.isReadable) {
- console.log("Property seems not to be readable. Attempting to read...");
-}
-property.readValue(readSuccess, readFail);</pre>
- </li>
- <li><p>To change the characteristic value, define callbacks and use the <span style="font-family: Courier New,Courier,monospace">writeValue()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTCharacteristic::writeValue">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTCharacteristic::writeValue">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTCharacteristic</span> interface:</p>
-<pre class="prettyprint">
-function writeSuccess(value)
-{
- console.log("Written");
-}
-
-function writeFail(error)
-{
- console.log("writeValue() failed: " + error);
-}
-
-if (!property.isWritable) {
- console.log("Property seems not to be writable. Attempting to write...");
-}
-var newValue = [82];
-
-property.writeValue(newValue, writeSuccess, writeFail);
-</pre>
- </li>
- </ol>
- </div>
- </li>
- <li>
- <div class="devicespec-tit">
- <h2 id="Characterictic_Notification" name="Characterictic_Notification" class="items-tit-h2">Receiving Notification on Characterictic Value Change</h2>
- <span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
- </div>
- <div class="devicespec-con">
-
- <p>Learning how to monitor a changes of a Bluetooth characteristic is a useful Bluetooth Low Energy management skill:</p>
- <ol>
-
- <li><p>Connect to any Bluetooth Low Energy device as described in the <a href="bluetooth_le_tutorial_w.htm#Connecting">Connecting to a Bluetooth Low Energy Device</a> section.</p></li>
- <li><p>Retrieve a list of GATT service uuids from the <span style="font-family: Courier New,Courier,monospace">uuids</span> attribute (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice::uuids">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice::uuids">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface:</p>
-<pre class="prettyprint">var serviceUUIDs = remoteDevice.uuids;</pre>
- </li>
- <li><p>Select one of the GATT services and use the <span style="font-family: Courier New,Courier,monospace">getService()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice::getService">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice::getService">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface to retrieve an object representing the service. In this example we use the first service:</p>
-<pre class="prettyprint">var gattService = remoteDevice.getService(serviceUUIDs[0]);</pre>
- </li>
- <li><p>Select the interesting characteristic from the <span style="font-family: Courier New,Courier,monospace">characteristics</span> attribute (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTService::characteristics">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTService::characteristics">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTService</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTService">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTService">wearable</a> applications). In this example we use the first of them:</p>
-<pre class="prettyprint">var property = gattService.characteristics[0];</pre>
- </li>
- <li><p>Define a callback implementing the <span style="font-family: Courier New,Courier,monospace">ReadValueSuccessCallback which</span> (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#ReadValueSuccessCallback">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#ReadValueSuccessCallback">wearable</a> applications) will receive the value of the characteristic every time the value changes:</p>
-<pre class="prettyprint">
-function onValueChange(value)
-{
- console.log("Characteristic value is now: " + value);
-}
-</pre>
- </li>
-
- <li><p>Register a value change listener using the <span style="font-family: Courier New,Courier,monospace">addValueChangeListener()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTCharacteristic::addValueChangeListener">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTCharacteristic::addValueChangeListener">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTCharacteristic</span> interface:</p>
-<pre class="prettyprint">var watchId = property.addValueChangeListener(onValueChange);</pre></li>
-
- <li><p>When the notifications about the connection are no longer required, unregister the listener from the device by calling the <span style="font-family: Courier New,Courier,monospace">removeValueChangeListener()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTCharacteristic::removeValueChangeListener">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTCharacteristic::removeValueChangeListener">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTCharacteristic</span> interface:</p>
-<pre class="prettyprint">property.removeValueChangeListener(watchId);</pre></li>
- </ol>
-
- </div>
- </li>
-
- <li>
- <div class="devicespec-tit">
- <h2 id="Descriptor_Value" name="Descriptor_Value" class="items-tit-h2">Accessing Bluetooth GATT Descriptor Value</h2>
- <span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
- </div>
- <div class="devicespec-con">
-
- <p>Learning how to read and write a value of Bluetooth Descriptor is a useful Bluetooth Low Energy management skill:</p>
- <ol>
-
- <li><p>Connect to any Bluetooth Low Energy device as described in the <a href="bluetooth_le_tutorial_w.htm#Connecting">Connecting to a Bluetooth Low Energy Device</a> section.</p></li>
- <li><p>Retrieve a list of GATT service uuids from the <span style="font-family: Courier New,Courier,monospace">uuids</span> attribute (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice::uuids">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice::uuids">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface:</p>
-<pre class="prettyprint">var serviceUUIDs = remoteDevice.uuids;</pre>
- </li>
- <li><p>Select one of the GATT services and use the <span style="font-family: Courier New,Courier,monospace">getService()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice::getService">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice::getService">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface to retrieve an object representing the service. In this example we use the first service:</p>
-<pre class="prettyprint">var gattService = remoteDevice.getService(serviceUUIDs[0]);</pre>
- </li>
- <li><p>Select the interesting characteristic from the <span style="font-family: Courier New,Courier,monospace">characteristics</span> attribute (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTService::characteristics">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTService::characteristics">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTService</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTService">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTService">wearable</a> applications). In this example we use the first of them:</p>
-<pre class="prettyprint">var characteristic = gattService.characteristics[0];</pre>
- <li><p>Select the interesting descriptor from the <span style="font-family: Courier New,Courier,monospace">descriptors</span> attribute (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTCharacteristic::descriptors">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTCharacteristic::descriptors">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTCharacteristic</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTCharacteristic">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTCharacteristic">wearable</a> applications). In this example we use the first of them:</p>
-<pre class="prettyprint">var descriptor = characteristic.descriptors[0];</pre>
- </li>
- <li><p>Define a callback implementing the <span style="font-family: Courier New,Courier,monospace">ReadValueSuccessCallback</span> (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#ReadValueSuccessCallback">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#ReadValueSuccessCallback">wearable</a> applications) which will receive the value of the descriptor:</p>
-<pre class="prettyprint">
-function readSuccess(value)
-{
- console.log("Descriptor value: " + value);
-}
-
-function readFail(error)
-{
- console.log("readValue() failed: " + error);
-}
-</pre>
- </li>
- <li><p>To retrieve GATT Descriptor value, use the <span style="font-family: Courier New,Courier,monospace">readValue()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTDescriptor::readValue">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTDescriptor::readValue">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTDescriptor</span> interface:</p>
-<pre class="prettyprint">
-descriptor.readValue(readSuccess, readFail);</pre>
- </li>
- <li><p>To change the descriptor value, define callbacks and use the <span style="font-family: Courier New,Courier,monospace">writeValue()</span> method (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTDescriptor::writeValue">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTDescriptor::writeValue">wearable</a> applications) of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTDescriptor</span> interface:</p>
-<pre class="prettyprint">
-function writeSuccess(value)
-{
- console.log("Written");
-}
-
-function writeFail(error)
-{
- console.log("writeValue() failed: " + error);
-}
-
-var newValue = [3];
-
-descriptor.writeValue(newValue, writeSuccess, writeFail);
-</pre>
- </li>
- </ol>
-
- </div>
- </li>
-
- </ul>
-</div>
-</div>
-
-<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>
<li><a href="#Creating_Bond">Creating a Bonding with a Bluetooth Device</a></li>
<li><a href="#Connecting_BT_device">Connecting to and Exchanging Data with a Bluetooth Device</a></li>
<li><a href="#Communicating_Health">Communicating with a Health Source Device</a></li>
+ <li>Bluetooth Low Energy</li>
+ <ul>
+ <li><a href="#Discovering_BT_LE_Devices">Discovering Bluetooth Low Energy Devices</a></li>
+ <li><a href="#Managing_Advertising">Managing the Advertising Options</a></li>
+ <li><a href="#Connecting">Connecting to a Bluetooth Low Energy Device</a></li>
+ <li><a href="#Connection_Notification">Receiving Notifications on Connection State Changes</a></li>
+ <li><a href="#Retrieving_Services">Retrieving Bluetooth GATT Services</a></li>
+ <li><a href="#Characteristic_Value">Accessing the Bluetooth GATT Characteristic Value</a></li>
+ <li><a href="#Characterictic_Notification">Receiving Notifications on Characteristic Value Changes</a></li>
+ <li><a href="#Descriptor_Value">Accessing the Bluetooth GATT Descriptor Value</a></li>
+ </ul>
</ul>
<p class="toc-title">Related Info</p>
<ul class="toc">
<li><a href="#Creating_Bond">Creating a Bonding with a Bluetooth Device</a> <p>Create and end a bonding with a Bluetooth device.</p></li>
<li><a href="#Connecting_BT_device">Connecting to and Exchanging Data with a Bluetooth Device</a> <p>Register a service as a server, connect as a client to the service provided by the server device, and exchange data with the device.</p></li>
<li><a href="#Communicating_Health">Communicating with a Health Source Device</a> <p>Act as a sink and communicate with a health source device.</p></li>
+ <li>Bluetooth Low Energy</li>
+ <ul>
+ <li><a href="#Discovering_BT_LE_Devices">Discovering Bluetooth Low Energy Devices</a> <p>Search for remote devices.</p></li>
+ <li><a href="#Managing_Advertising">Managing the Advertising Options</a> <p>Manage what information is advertised to any Bluetooth Low Energy device in the proximity.</p></li>
+ <li><a href="#Connecting">Connecting to a Bluetooth Low Energy Device</a> <p>Connect to a detected Bluetooth Low Energy device.</p></li>
+ <li><a href="#Connection_Notification">Receiving Notifications on Connection State Changes</a> <p>Monitor the connection state to a remote Bluetooth Low Energy device.</p></li>
+ <li><a href="#Retrieving_Services">Retrieving Bluetooth GATT Services</a> <p>Check information about the Bluetooth GATT services provided by a remote device.</p></li>
+ <li><a href="#Characteristic_Value">Accessing the Bluetooth GATT Characteristic Value</a> <p>Read and write a value of the Bluetooth GATT characteristic of a remote device.</p></li>
+ <li><a href="#Characterictic_Notification">Receiving Notifications on Characteristic Value Changes</a> <p>Monitor changes in a Bluetooth GATT characteristic value.</p></li>
+ <li><a href="#Descriptor_Value">Accessing the Bluetooth GATT Descriptor Value</a> <p>Read and write a value of the Bluetooth GATT characteristic descriptor of a remote device.</p></li>
+ </ul>
</ul>
<h2 id="task" name="task">Task</h2>
<p>In the <a href="task_bluetoothchat_w.htm">Bluetooth Chat</a> task, we will walk through how to use the device as a Bluetooth server or client in a chat application.</p>
</pre>
<p>When the channel is disconnected, the <span style="font-family: Courier New,Courier,monospace">onclose</span> event handler in the <span style="font-family: Courier New,Courier,monospace">BluetoothHealthChannelChangeCallback</span> interface is called.</p></li>
</ol>
+
+ <h2 id="Discovering_BT_LE_Devices" name="Discovering_BT_LE_Devices">Discovering Bluetooth Low Energy Devices</h2>
+
+ <p>Learning how to search for remote devices is a basic Bluetooth management skill:</p>
+ <ol>
+ <li>Define a scan event handler by implementing the <span style="font-family: Courier New,Courier,monospace">BluetoothLEScanCallback</span> callback (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEScanCallback">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEScanCallback">wearable</a> applications).
+ <p>The callback is invoked when a remote device has been detected.</p>
+<pre class="prettyprint">
+var callbacks =
+{
+ onsuccess: function(device)
+ {
+ console.log("Found device: " + device.name + " [" + device.address + "]");
+ }
+};
+</pre>
+ <table class="note">
+ <tbody>
+ <tr>
+ <th class="note">Note</th>
+ </tr>
+ <tr>
+ <td class="note">To allow other Bluetooth devices to find your device, you must set the device to be visible through the system settings.</td>
+ </tr>
+ </tbody>
+ </table> </li>
+
+ <li><p>Retrieve a <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> object (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter">wearable</a> applications) with the <span style="font-family: Courier New,Courier,monospace">getLEAdapter()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothManager</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothManager">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothManager">wearable</a> applications):</p>
+<pre class="prettyprint">var adapter = tizen.bluetooth.getLEAdapter();</pre>
+ </li>
+
+ <li><p>To search for remote devices, use the <span style="font-family: Courier New,Courier,monospace">startScan()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> interface:</p>
+<pre class="prettyprint">adapter.startScan(callbacks);</pre>
+ </li>
+ <li><p>When you find the right remote device or the user cancels the scanning, disable the scan using the <span style="font-family: Courier New,Courier,monospace">stopScan()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> interface:</p>
+<pre class="prettyprint">adapter.stopScan();</pre>
+ </li>
+
+ </ol>
+
+ <h2 id="Managing_Advertising" name="Managing_Advertising">Managing the Advertising Options</h2>
+ <p>The Bluetooth Low Energy technology allows a device to broadcast some information without a connection between devices. The Bluetooth Low Energy API provides methods to control this advertising (broadcasting).</p>
+ <p>Learning how to control what information is advertised by the device is a useful Bluetooth Low Energy skill:</p>
+
+ <ol>
+ <li><p>Retrieve a <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> object (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter">wearable</a> applications) with the <span style="font-family: Courier New,Courier,monospace">getLEAdapter()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothManager</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothManager">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothManager">wearable</a> applications):</p>
+<pre class="prettyprint">var adapter = tizen.bluetooth.getLEAdapter();</pre>
+ </li>
+
+ <li><p>Set up options and start advertising with the <span style="font-family: Courier New,Courier,monospace">startAdvertise()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> interface:</p>
+<pre class="prettyprint">
+var advertiseData = new tizen.BluetoothLEAdvertiseData(
+{
+ includeName: true,
+ serviceuuids: ["180f"] /* 180F is 16bit Battery Service UUID */
+});
+var connectable = true;
+
+adapter.startAdvertise(advertiseData, "ADVERTISE",
+ function onstate(state)
+ {
+ console.log("Advertising configured: " + state);
+ },
+ function(error)
+ {
+ console.log("startAdvertise() failed: " + error.message);
+ },
+ "LOW_LATENCY", connectable);
+</pre>
+ <table class="note">
+ <tbody>
+ <tr>
+ <th class="note">Note</th>
+ </tr>
+ <tr>
+ <td class="note">To learn how to make your mobile device visible to other Bluetooth devices, see <a href="bluetooth_tutorial_w.htm#Managing_BT_Adapter">Managing the Local Bluetooth Adapter of the Bluetooth Tutorial</a>.</td>
+ </tr>
+ </tbody>
+ </table>
+ </li>
+ <li><p>To disable the advertising, use the <span style="font-family: Courier New,Courier,monospace">stopAdvertise()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> interface:</p>
+<pre class="prettyprint">adapter.stopAdvertise();</pre>
+ </li>
+ </ol>
+
+ <h2 id="Connecting" name="Connecting">Connecting to a Bluetooth Low Energy Device</h2>
+
+ <p>Learning how to connect to other devices is a basic Bluetooth Low Energy management skill:</p>
+ <ol>
+ <li><p>Retrieve a <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> object (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter">wearable</a> applications) with the <span style="font-family: Courier New,Courier,monospace">getLEAdapter()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothManager</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothManager">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothManager">wearable</a> applications):</p>
+<pre class="prettyprint">var adapter = tizen.bluetooth.getLEAdapter();</pre>
+ </li>
+ <li><p>Define success and error callbacks for the connect operation:</p>
+<pre class="prettyprint">
+function connectFail(error)
+{
+ console.log("Failed to connect to device: " + e.message);
+}
+
+function connectSuccess()
+{
+ console.log("Connected to device");
+}
+</pre>
+ </li>
+
+ <li><p>Define a callback for the scan operation that connects to a found device and stops the scan.</p>
+ <p>Within the callback request, establish a connection with the found device using the <span style="font-family: Courier New,Courier,monospace">connect()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice">wearable</a> applications):</p>
+<pre class="prettyprint">
+var remoteDevice = null;
+
+function onDeviceFound(device)
+{
+ if (remoteDevice === null)
+ {
+ remoteDevice = device;
+ console.log("Found device " + device.name + ". Connecting...");
+
+ device.connect(connectSuccess, connectFail);
+ }
+
+ adapter.stopScan();
+}
+</pre>
+ </li>
+
+ <li><p>When the callbacks are completed, initiate the Bluetooth Low Energy scan using the <span style="font-family: Courier New,Courier,monospace">startScan()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> adapter:</p>
+<pre class="prettyprint">adapter.startScan({onsuccess: onDeviceFound});</pre></li>
+
+ <li><p>When the connection to the remote device is no longer required, disconnect from the device by calling the <span style="font-family: Courier New,Courier,monospace">disconnect()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface:</p>
+<pre class="prettyprint">remoteDevice.disconnect();</pre></li>
+
+ </ol>
+
+ <h2 id="Connection_Notification" name="Connection_Notification">Receiving Notifications on Connection State Changes</h2>
+
+ <p>Learning how to receive notifications whenever the device connection is established or lost is a useful Bluetooth management skill:</p>
+ <ol>
+
+ <li><p>Retrieve a <span style="font-family: Courier New,Courier,monospace">BluetoothLEAdapter</span> object (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter">wearable</a> applications) with the <span style="font-family: Courier New,Courier,monospace">getLEAdapter()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothManager</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothManager">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothManager">wearable</a> applications):</p>
+<pre class="prettyprint">var adapter = tizen.bluetooth.getLEAdapter();</pre>
+ </li>
+ <li><p>Define a connection state change listener by implementing the <span style="font-family: Courier New,Courier,monospace">BluetoothLEConnectChangeCallback</span> callback (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEConnectChangeCallback">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEConnectChangeCallback">wearable</a> applications):</p>
+<pre class="prettyprint">
+var connectionListener =
+{
+ onconnected: function(device)
+ {
+ console.log("Connected to the device: " + device.name + " [" + device.address + "]");
+ },
+ ondisconnected: function(device)
+ {
+ console.log("Disconnected from the device " + device.name + " [" + device.address + "]");
+ }
+};
+</pre>
+ </li>
+
+ <li><p>Define a callback for the scan operation that connects to a found device and stops the scan.</p>
+ <p>Within the callback, register a connection state change listener using the <span style="font-family: Courier New,Courier,monospace">addConnectStateChangeListener()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice">wearable</a> applications):</p>
+<pre class="prettyprint">
+var remoteDevice = null;
+var watchId;
+
+function onDeviceFound(device)
+{
+ if (remoteDevice === null)
+ {
+ remoteDevice = device;
+ console.log("Found device " + device.name + ". Connecting...");
+
+ watchId = remoteDevice.addConnectStateChangeListener(connectionListener);
+
+ remoteDevice.connect();
+ }
+
+ adapter.stopScan();
+}
+</pre>
+ </li>
+
+ <li><p>When the callbacks are completed, initiate the Bluetooth Low Energy scan:</p>
+<pre class="prettyprint">adapter.startScan({onsuccess: onDeviceFound});</pre></li>
+
+ <li><p>When the notifications about the connection are no longer required, unregister the listener from the device by calling the <span style="font-family: Courier New,Courier,monospace">removeConnectStateChangeListener()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface:</p>
+<pre class="prettyprint">remoteDevice.removeConnectStateChangeListener(watchId);</pre></li>
+ </ol>
+
+ <h2 id="Retrieving_Services" name="Retrieving_Services">Retrieving Bluetooth GATT Services</h2>
+
+ <p>Learning how to retrieve a list of GATT services (Generic Attribute) provided by a remote device is basic Bluetooth Low Energy management skill:</p>
+ <ol>
+
+ <li><a href="#Connecting">Connect to a Bluetooth Low Energy device</a>.</li>
+ <li><p>Define a connection state change listener by implementing the <span style="font-family: Courier New,Courier,monospace">BluetoothLEConnectChangeCallback</span> (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEConnectChangeCallback">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEConnectChangeCallback">wearable</a> applications):</p>
+<pre class="prettyprint">
+function showGATTService(service, indent)
+{
+ if (indent === undefined)
+ {
+ indent = "";
+ }
+
+ console.log(indent + "Service " + service.uuid + ". Has " + service.characteristics.length
+ + " characteristics and " + service.services.length + " sub-services.");
+
+ for (var i = 0; i < service.services.length; i++)
+ {
+ showGATTService(service.services[i], indent + " ");
+ }
+}
+</pre>
+ </li>
+ <li><p>Retrieve a list of GATT service UUIDs from the <span style="font-family: Courier New,Courier,monospace">uuids</span> attribute of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice">wearable</a> applications):</p>
+<pre class="prettyprint">var serviceUUIDs = remoteDevice.uuids;</pre>
+ </li>
+ <li><p>Retrieve GATT service information using the <span style="font-family: Courier New,Courier,monospace">getService()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface for every service UUID:</p>
+<pre class="prettyprint">
+var i = 0, service = null;
+
+for (i; i < serviceUUIDs.length; i++)
+{
+
+ service = remoteDevice.getService(serviceUUIDs[i]);
+
+ showGATTService(service);
+}</pre>
+ </li>
+
+ </ol>
+
+ <h2 id="Characteristic_Value" name="Characteristic_Value">Accessing the Bluetooth GATT Characteristic Value</h2>
+
+ <p>Learning how to read and write a value of the Bluetooth characteristic is a useful Bluetooth Low Energy management skill:</p>
+ <ol>
+
+ <li><a href="#Connecting">Connect to a Bluetooth Low Energy device</a>.</li>
+ <li><p>Retrieve a list of GATT service UUIDs from the <span style="font-family: Courier New,Courier,monospace">uuids</span> attribute of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice">wearable</a> applications):</p>
+<pre class="prettyprint">var serviceUUIDs = remoteDevice.uuids;</pre>
+ </li>
+ <li><p>Select a GATT service and use the <span style="font-family: Courier New,Courier,monospace">getService()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface to retrieve an object representing the service. In this example, the first service is used:</p>
+<pre class="prettyprint">var gattService = remoteDevice.getService(serviceUUIDs[0]);</pre>
+ </li>
+ <li><p>Select an interesting characteristic from the <span style="font-family: Courier New,Courier,monospace">characteristics</span> attribute of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTService</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTService">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTService">wearable</a> applications). In this example, the first characteristic is used:</p>
+<pre class="prettyprint">var property = gattService.characteristics[0];</pre>
+ </li>
+ <li><p>Define a callback implementing the <span style="font-family: Courier New,Courier,monospace">ReadValueSuccessCallback</span> callback (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#ReadValueSuccessCallback">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#ReadValueSuccessCallback">wearable</a> applications), which receives the value of the characteristic:</p>
+<pre class="prettyprint">
+function readSuccess(value)
+{
+ console.log("Characteristic value: " + value);
+}
+
+function readFail(error)
+{
+ console.log("readValue() failed: " + error);
+}
+</pre>
+ </li>
+ <li><p>To retrieve the GATT characteristic value, use the <span style="font-family: Courier New,Courier,monospace">readValue()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTCharacteristic</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTCharacteristic">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTCharacteristic">wearable</a> applications):</p>
+<pre class="prettyprint">
+if (!property.isReadable)
+{
+ console.log("Property seems not to be readable. Attempting to read...");
+}
+property.readValue(readSuccess, readFail);</pre>
+ </li>
+ <li><p>To change the characteristic value, define callbacks and use the <span style="font-family: Courier New,Courier,monospace">writeValue()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTCharacteristic</span> interface:</p>
+<pre class="prettyprint">
+function writeSuccess(value)
+{
+ console.log("Written");
+}
+
+function writeFail(error)
+{
+ console.log("writeValue() failed: " + error);
+}
+
+if (!property.isWritable)
+{
+ console.log("Property seems not to be writable. Attempting to write...");
+}
+var newValue = [82];
+
+property.writeValue(newValue, writeSuccess, writeFail);
+</pre>
+ </li>
+ </ol>
+
+ <h2 id="Characterictic_Notification" name="Characterictic_Notification">Receiving Notifications on Characteristic Value Changes</h2>
+
+ <p>Learning how to monitor a changes in a Bluetooth characteristic is a useful Bluetooth Low Energy management skill:</p>
+ <ol>
+
+ <li><a href="#Connecting">Connect to a Bluetooth Low Energy device</a>.</li>
+ <li><p>Retrieve a list of GATT service UUIDs from the <span style="font-family: Courier New,Courier,monospace">uuids</span> attribute of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice">wearable</a> applications):</p>
+<pre class="prettyprint">var serviceUUIDs = remoteDevice.uuids;</pre>
+ </li>
+ <li><p>Select a GATT service and use the <span style="font-family: Courier New,Courier,monospace">getService()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface to retrieve an object representing the service. In this example, the first service is used:</p>
+<pre class="prettyprint">var gattService = remoteDevice.getService(serviceUUIDs[0]);</pre>
+ </li>
+ <li><p>Select an interesting characteristic from the <span style="font-family: Courier New,Courier,monospace">characteristics</span> attribute of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTService</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTService">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTService">wearable</a> applications). In this example, the first characteristic is used:</p>
+<pre class="prettyprint">var property = gattService.characteristics[0];</pre>
+ </li>
+ <li><p>Define a callback implementing the <span style="font-family: Courier New,Courier,monospace">ReadValueSuccessCallback</span> callback (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#ReadValueSuccessCallback">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#ReadValueSuccessCallback">wearable</a> applications), which receives the value of the characteristic every time the value changes:</p>
+<pre class="prettyprint">
+function onValueChange(value)
+{
+ console.log("Characteristic value is now: " + value);
+}
+</pre>
+ </li>
+
+ <li><p>Register a value change listener using the <span style="font-family: Courier New,Courier,monospace">addValueChangeListener()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTCharacteristic</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTCharacteristic">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTCharacteristic">wearable</a> applications):</p>
+<pre class="prettyprint">var watchId = property.addValueChangeListener(onValueChange);</pre></li>
+
+ <li><p>When the notifications about the connection are no longer required, unregister the listener from the device by calling the <span style="font-family: Courier New,Courier,monospace">removeValueChangeListener()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTCharacteristic</span> interface:</p>
+<pre class="prettyprint">property.removeValueChangeListener(watchId);</pre></li>
+ </ol>
+
+ <h2 id="Descriptor_Value" name="Descriptor_Value">Accessing the Bluetooth GATT Descriptor Value</h2>
+
+ <p>Learning how to read and write a value of the Bluetooth descriptor is a useful Bluetooth Low Energy management skill:</p>
+ <ol>
+
+ <li><a href="#Connecting">Connect to a Bluetooth Low Energy device</a>.</li>
+ <li><p>Retrieve a list of GATT service UUIDs from the <span style="font-family: Courier New,Courier,monospace">uuids</span> attribute of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice">wearable</a> applications):</p>
+<pre class="prettyprint">var serviceUUIDs = remoteDevice.uuids;</pre>
+ </li>
+ <li><p>Select a GATT service and use the <span style="font-family: Courier New,Courier,monospace">getService()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothLEDevice</span> interface to retrieve an object representing the service. In this example, the first service is used:</p>
+<pre class="prettyprint">var gattService = remoteDevice.getService(serviceUUIDs[0]);</pre>
+ </li>
+ <li><p>Select an interesting characteristic from the <span style="font-family: Courier New,Courier,monospace">characteristics</span> attribute of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTService</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTService">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTService">wearable</a> applications). In this example, the first characteristic is used:</p>
+<pre class="prettyprint">var characteristic = gattService.characteristics[0];</pre></li>
+ <li><p>Select an interesting descriptor from the <span style="font-family: Courier New,Courier,monospace">descriptors</span> attribute of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTCharacteristic</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTCharacteristic">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTCharacteristic">wearable</a> applications). In this example, the first descriptor is used:</p>
+<pre class="prettyprint">var descriptor = characteristic.descriptors[0];</pre>
+ </li>
+ <li><p>Define a callback implementing the <span style="font-family: Courier New,Courier,monospace">ReadValueSuccessCallback</span> callback (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#ReadValueSuccessCallback">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#ReadValueSuccessCallback">wearable</a> applications), which receives the value of the descriptor:</p>
+<pre class="prettyprint">
+function readSuccess(value)
+{
+ console.log("Descriptor value: " + value);
+}
+
+function readFail(error)
+{
+ console.log("readValue() failed: " + error);
+}
+</pre>
+ </li>
+ <li><p>To retrieve the GATT descriptor value, use the <span style="font-family: Courier New,Courier,monospace">readValue()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTDescriptor</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/bluetooth.html#BluetoothGATTDescriptor">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothGATTDescriptor">wearable</a> applications):</p>
+<pre class="prettyprint">
+descriptor.readValue(readSuccess, readFail);</pre>
+ </li>
+ <li><p>To change the descriptor value, define callbacks and use the <span style="font-family: Courier New,Courier,monospace">writeValue()</span> method of the <span style="font-family: Courier New,Courier,monospace">BluetoothGATTDescriptor</span> interface:</p>
+<pre class="prettyprint">
+function writeSuccess(value)
+{
+ console.log("Written");
+}
+
+function writeFail(error)
+{
+ console.log("writeValue() failed: " + error);
+}
+
+var newValue = [3];
+
+descriptor.writeValue(newValue, writeSuccess, writeFail);
+</pre>
+ </li>
+ </ol>
<script type="text/javascript" src="../../../scripts/jquery.zclip.min.js"></script>
<topic href="html/web/tizen/communication/bluetooth_tutorial_w.htm" label="Bluetooth">
<topic href="html/web/tizen/communication/task_bluetoothchat_w.htm" label="Task: Bluetooth Chat"></topic>
</topic>
- <topic href="html/web/tizen/communication/bluetooth_le_tutorial_w.htm" label="Bluetooth Low Energy"/>
<topic href="html/web/tizen/communication/nfc_tutorial_w.htm" label="NFC">
<topic href="html/web/tizen/communication/task_contactsexchanger_w.htm" label="Task: Contacts Exchanger"></topic>
</topic>