From 02d06d76f3044a95e2fea6ce7bf9ed900bc1715e Mon Sep 17 00:00:00 2001
From: Lukasz Bardeli Code example: Code example: Code example: Code example: Deprecated.
- Deprecated since 2.3. Instead, let the user turn on/off Bluetooth through the Settings application. see the Bluetooth Tutorial. Deprecated.
+ Deprecated since 2.3. Instead, let the user turn on/off Bluetooth through the Settings application. See Managing Bluetooth Tutorial.
+
@@ -1336,44 +1371,44 @@ var adapter = tizen.bluetooth.getDefaultAdapter();
function powerOn()
{
- /* If adapter is not powered on */
- if (!adapter.powered)
- {
- /* Initiates power on */
- adapter.setPowered(true, function()
- {
- console.log("Bluetooth powered on success.");
- }, function(e)
- {
- console.log("Failed to power on Bluetooth: " + e.message);
- });
- }
+ /* If adapter is not powered on */
+ if (!adapter.powered)
+ {
+ /* Initiates power on */
+ adapter.setPowered(true, function()
+ {
+ console.log("Bluetooth powered on success.");
+ }, function(e)
+ {
+ console.log("Failed to power on Bluetooth: " + e.message);
+ });
+ }
}
function powerOff()
{
- /* If powered on */
- if (adapter.powered)
- {
- /* Initiates power off */
- adapter.setPowered(false, function()
- {
- console.log("Bluetooth powered off successfully.");
- }, function(e)
- {
- console.log("Failed to power off Bluetooth: " + e.message);
- });
- }
+ /* If powered on */
+ if (adapter.powered)
+ {
+ /* Initiates power off */
+ adapter.setPowered(false, function()
+ {
+ console.log("Bluetooth powered off successfully.");
+ }, function(e)
+ {
+ console.log("Failed to power off Bluetooth: " + e.message);
+ });
+ }
}
var bt_always_on = tizen.systeminfo.getCapability("http://tizen.org/capability/network.bluetooth.always_on");
if (bt_always_on === true)
{
- console.log("Bluetooth cannot be turn off or on because this device must be always enabled.");
+ console.log("Bluetooth cannot be turn off or on because this device must be always enabled.");
}
else
{
- powerOn();
+ powerOn();
}
@@ -1419,18 +1454,18 @@ else
Code example: Code example: Code example: Return value: Exceptions: Code example: Code example: Code example: Code example: Code example: Code example:
@@ -4044,7 +4086,7 @@ adapter.startScan(function onsuccess(device)
var adapter = tizen.bluetooth.getLEAdapter();
adapter.startScan(function onsuccess(device)
{
- console.log("Found device: " + device.txpowerlevel);
+ console.log("Found device: " + device.txpowerlevel);
});
Code example: Code example: Code example: Return value: Exceptions: with error type InvalidValuesError, If GATT server is not available. with error type NotSupportedError, If the feature is not supported.
+ with error type InvalidValuesError: If GATT server is not available.
+
+ with error type NotSupportedError: If the feature is not supported.
+ Code example: Output example: Code example: Code example: Return value: Exceptions:
Since:
@@ -5343,7 +5405,8 @@ adapter.getDevice("12:34:56:78:9A:BC", function(device)
Since:
@@ -5353,7 +5416,7 @@ adapter.getDevice("12:34:56:78:9A:BC", function(device)
Since:
@@ -5376,6 +5439,42 @@ By default, this attribute is set to null.
Code example:
-
-BluetoothAdapter getDefaultAdapter ()
+
+
+
- BluetoothLEAdapter getLEAdapter ()
BluetoothAdapter
-void setName (DOMString name, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
+
- void setPowered (boolean state, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
- void setChangeListener (BluetoothAdapterChangeCallback listener)
- void unsetChangeListener ()
- void discoverDevices (BluetoothDiscoverDevicesSuccessCallback successCallback, optional ErrorCallback? errorCallback)
- void stopDiscovery (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
- void getKnownDevices (BluetoothDeviceArraySuccessCallback successCallback, optional ErrorCallback? errorCallback)
- void getDevice (BluetoothAddress address, BluetoothDeviceSuccessCallback successCallback, optional ErrorCallback? errorCallback)
- void createBonding (BluetoothAddress address, BluetoothDeviceSuccessCallback successCallback, optional ErrorCallback? errorCallback)
- void destroyBonding (BluetoothAddress address, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
- void registerRFCOMMServiceByUUID (BluetoothUUID uuid, DOMString name, BluetoothServiceSuccessCallback successCallback, optional ErrorCallback? errorCallback)
- BluetoothProfileHandler getBluetoothProfileHandler (BluetoothProfileType profileType)
+
BluetoothLEAdapter
-void startScan (BluetoothLEScanCallback successCallback, optional ErrorCallback? errorCallback)
+
- void stopScan ()
- void startAdvertise (BluetoothLEAdvertiseData advertiseData, BluetoothAdvertisePacketType packetType, BluetoothLEAdvertiseCallback successCallback, optional ErrorCallback? errorCallback, optional BluetoothAdvertisingMode? mode, optional boolean? connectable)
- void stopAdvertise ()
+
+
BluetoothGATTService
@@ -209,55 +225,67 @@ For more information on the Bluetooth features, see BluetoothGATTCharacteristic
-void readValue (ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback)
+
- void writeValue (byte[] value, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
- long addValueChangeListener (ReadValueSuccessCallback callback)
- void removeValueChangeListener (long watchID)
+
+
BluetoothGATTDescriptor
-void readValue (ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback)
+
- void writeValue (byte[] value, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
+
+
BluetoothLEScanCallback
-void onsuccess (BluetoothLEDevice device)
+
BluetoothLEAdvertiseCallback
-void onstate (BluetoothAdvertisingState state)
+
BluetoothLEConnectChangeCallback
-void onconnected (BluetoothLEDevice device)
+
- void ondisconnected (BluetoothLEDevice device)
+
ReadValueSuccessCallback
-void onread (byte[] value)
+
BluetoothDevice
-void connectToServiceByUUID (BluetoothUUID uuid, BluetoothSocketSuccessCallback successCallback, optional ErrorCallback? errorCallback)
+
BluetoothLEDevice
-void connect (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
+
- void disconnect (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
- BluetoothGATTService getService (BluetoothUUID uuid)
- BluetoothUUID[] getServiceAllUuids ()
- long addConnectStateChangeListener (BluetoothLEConnectChangeCallback listener)
- void removeConnectStateChangeListener (long watchID)
+
+
+
+
+
BluetoothSocket
-unsigned long writeData (byte[] data)
+
- byte[] readData ()
- void close ()
+
BluetoothClass
-boolean hasService (unsigned short service)
+
BluetoothClassDeviceMajor
@@ -273,7 +301,7 @@ For more information on the Bluetooth features, see BluetoothServiceHandler
-void unregister (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
+
BluetoothProfileHandler
@@ -281,61 +309,71 @@ For more information on the Bluetooth features, see BluetoothHealthProfileHandler
-void registerSinkApplication (unsigned short dataType, DOMString name, BluetoothHealthApplicationSuccessCallback successCallback, optional ErrorCallback? errorCallback)
+
- void connectToSource (BluetoothDevice peer, BluetoothHealthApplication application, BluetoothHealthChannelSuccessCallback successCallback, optional ErrorCallback? errorCallback)
+
BluetoothHealthApplication
-void unregister (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
+
BluetoothHealthChannel
-void close ()
+
- unsigned long sendData (byte[] data)
- void setListener (BluetoothHealthChannelChangeCallback listener)
- void unsetListener ()
+
BluetoothAdapterChangeCallback
-void onstatechanged (boolean powered)
+
- void onnamechanged (DOMString name)
- void onvisibilitychanged (boolean visible)
+
BluetoothDeviceSuccessCallback
-void onsuccess (BluetoothDevice device)
+
BluetoothDeviceArraySuccessCallback
-void onsuccess (BluetoothDevice[] devices)
+
BluetoothDiscoverDevicesSuccessCallback
-void onstarted ()
+
- void ondevicefound (BluetoothDevice device)
- void ondevicedisappeared (BluetoothAddress address)
- void onfinished (BluetoothDevice[] foundDevices)
+
BluetoothSocketSuccessCallback
-void onsuccess (BluetoothSocket socket)
+
BluetoothServiceSuccessCallback
-void onsuccess (BluetoothServiceHandler handler)
+
BluetoothHealthApplicationSuccessCallback
-void onsuccess (BluetoothHealthApplication application)
+
BluetoothHealthChannelSuccessCallback
-void onsuccess (BluetoothHealthChannel channel)
+
@@ -643,8 +681,8 @@ This dictionary is used as an input parameter of the BluetoothLEAdvertiseData co
BluetoothHealthChannelChangeCallback
-void onmessage (byte[] data)
+
- void onclose ()
+
var advertData =
{
- includeName: false, uuids: ["f236-41a4"], solicitationuuids: ["5857-4d3f"],
- appearance: 192, includeTxPowerLevel: false
+ includeName: false, uuids: ["f236-41a4"], solicitationuuids: ["5857-4d3f"],
+ appearance: 192, includeTxPowerLevel: false
}
@@ -678,8 +716,8 @@ This represents the data to be advertised as well as the scan response data for
var advertData =
{
- includeName: false, uuids: ["f236-41a4"], solicitationuuids: ["5857-4d3f"],
- appearance: 192, includeTxPowerLevel: false
+ includeName: false, uuids: ["f236-41a4"], solicitationuuids: ["5857-4d3f"],
+ appearance: 192, includeTxPowerLevel: false
}
var advertise = new tizen.BluetoothLEAdvertiseData(advertData);
@@ -925,11 +963,11 @@ Instead, use http://tizen.org/privilege/bluetooth.
try
{
- var adapter = tizen.bluetooth.getDefaultAdapter();
+ var adapter = tizen.bluetooth.getDefaultAdapter();
}
catch (err)
{
- console.log(err.name + ": " + err.message);
+ console.log(err.name + ": " + err.message);
}
@@ -985,11 +1023,11 @@ Instead, use http://tizen.org/privilege/bluetooth.
try
{
- var adapter = tizen.bluetooth.getLEAdapter();
+ var adapter = tizen.bluetooth.getLEAdapter();
}
catch (err)
{
- console.log(err.name + ": " + err.message);
+ console.log(err.name + ": " + err.message);
}
@@ -1012,10 +1050,6 @@ catch (err)
optional SuccessCallback? successCallback,
optional ErrorCallback? errorCallback) raises(WebAPIException);
- void setPowered(boolean state,
- optional SuccessCallback? successCallback,
- optional ErrorCallback? errorCallback) raises(WebAPIException);
-
void setChangeListener(BluetoothAdapterChangeCallback listener) raises(WebAPIException);
void unsetChangeListener() raises(WebAPIException);
@@ -1236,35 +1270,36 @@ var bt_always_on = tizen.systeminfo.getCapability("http://tizen.org/capability/n
function changeName(newName)
{
- if (adapter.name != newName)
- {
- /* Initiate change name */
- adapter.setName(newName, function()
- {
- console.log("Adapter name changed to " + adapter.name);
- }, function(e)
- {
- console.log("Failed to change name: " + e.message);
- });
- }
+ if (adapter.name != newName)
+ {
+ /* Initiate change name */
+ adapter.setName(newName, function()
+ {
+ console.log("Adapter name changed to " + adapter.name);
+ }, function(e)
+ {
+ console.log("Failed to change name: " + e.message);
+ });
+ }
}
if (bt_always_on === false)
{
- changeName("myDevice");
+ changeName("myDevice");
}
-setPowered
void setPowered(boolean state, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
var changeListener =
{
- onstatechanged: function(powered)
- {
- console.log("Power state is changed into: " + powered);
- },
- onnamechanged: function(name)
- {
- console.log("Name is changed to: " + name);
- },
- onvisibilitychanged: function(visible)
- {
- console.log("Visibility is changed into: " + visible);
- }
+ onstatechanged: function(powered)
+ {
+ console.log("Power state is changed into: " + powered);
+ },
+ onnamechanged: function(name)
+ {
+ console.log("Name is changed to: " + name);
+ },
+ onvisibilitychanged: function(visible)
+ {
+ console.log("Visibility is changed into: " + visible);
+ }
};
var adapter = tizen.bluetooth.getDefaultAdapter();
@@ -1469,20 +1504,20 @@ var adapter = tizen.bluetooth.getDefaultAdapter();
var changeListener =
{
- onstatechanged: function(powered)
- {
- console.log("Power state is changed into: " + powered);
- if (!powered)
- adapter.unsetChangeListener();
- },
- onnamechanged: function(name)
- {
- console.log("Name is changed to: " + name);
- },
- onvisibilitychanged: function(visible)
- {
- console.log("Visibility is changed into: " + visible);
- }
+ onstatechanged: function(powered)
+ {
+ console.log("Power state is changed into: " + powered);
+ if (!powered)
+ adapter.unsetChangeListener();
+ },
+ onnamechanged: function(name)
+ {
+ console.log("Name is changed to: " + name);
+ },
+ onvisibilitychanged: function(visible)
+ {
+ console.log("Visibility is changed into: " + visible);
+ }
};
adapter.setChangeListener(changeListener);
@@ -1572,41 +1607,41 @@ var adapter = tizen.bluetooth.getDefaultAdapter();
function startDiscovery()
{
- var discoverDevicesSuccessCallback =
- {
- onstarted: function()
- {
- console.log("Device discovery started...");
- },
- ondevicefound: function(device)
- {
- console.log("Found device - name: " + device.name + ", Address: " + device.address);
- },
- ondevicedisappeared: function(address)
- {
- console.log("Device disappeared: " + address);
- },
- onfinished: function(devices)
+ var discoverDevicesSuccessCallback =
+ {
+ onstarted: function()
+ {
+ console.log("Device discovery started...");
+ },
+ ondevicefound: function(device)
+ {
+ console.log("Found device - name: " + device.name + ", Address: "+ device.address);
+ },
+ ondevicedisappeared: function(address)
+ {
+ console.log("Device disappeared: " + address);
+ },
+ onfinished: function(devices)
+ {
+ console.log("Found Devices");
+ for (var i = 0; i < devices.length; i++)
{
- console.log("Found Devices");
- for (var i = 0; i < devices.length; i++)
- {
- console.log("Name: " + devices[i].name + ", Address: " + devices[i].address);
- }
- console.log("Total: " + devices.length);
+ console.log("Name: " + devices[i].name + ", Address: " + devices[i].address);
}
- };
-
- /* Starts searching for nearby devices, for about 12 sec */
- adapter.discoverDevices(discoverDevicesSuccessCallback, function(e)
- {
- console.log("Failed to search devices: " + e.message + "(" + e.name + ")");
- });
+ console.log("Total: " + devices.length);
+ }
+ };
+
+ /* Starts searching for nearby devices, for about 12 sec */
+ adapter.discoverDevices(discoverDevicesSuccessCallback, function(e)
+ {
+ console.log("Failed to search devices: " + e.message + "(" + e.name + ")");
+ });
}
function onSetPoweredError(e)
{
- console.log("Could not turn on device, reason: " + e.message + "(" + e.name + ")");
+ console.log("Could not turn on device, reason: " + e.message + "(" + e.name + ")");
}
adapter.setPowered(true, startDiscovery, onSetPoweredError);
@@ -1684,57 +1719,57 @@ var adapter = tizen.bluetooth.getDefaultAdapter();
/* Calls this method whenever user finds one of the device */
function cancelDiscovery()
{
- adapter.stopDiscovery(function()
- {
- console.log("Stop discovery success.");
- }, function(e)
- {
- console.log("Error while stopDiscovery:" + e.message);
- });
+ adapter.stopDiscovery(function()
+ {
+ console.log("Stop discovery success.");
+ }, function(e)
+ {
+ console.log("Error while stopDiscovery:" + e.message);
+ });
}
function startDiscovery()
{
- var discoverDevicesSuccessCallback =
- {
- onstarted: function()
- {
- console.log("Device discovery started...");
- },
- ondevicefound: function(device)
- {
- console.log("Found device - name: " + device.name + ", Address: " + device.address);
- /* Shows the device to user to check if this is the device user is looking for */
- /* For example, add this to list view */
-
- cancelDiscovery();
- },
- ondevicedisappeared: function(address)
+ var discoverDevicesSuccessCallback =
+ {
+ onstarted: function()
+ {
+ console.log("Device discovery started...");
+ },
+ ondevicefound: function(device)
+ {
+ console.log("Found device - name: " + device.name + ", Address: "+ device.address);
+ /* Shows the device to user to check if this is the device user is looking for */
+ /* For example, add this to list view */
+
+ cancelDiscovery();
+ },
+ ondevicedisappeared: function(address)
+ {
+ console.log("Device disappeared: " + address);
+ /* Removes from list, as it is no longer valid */
+ },
+ onfinished: function(devices)
+ {
+ console.log("Found Devices");
+ for (var i = 0; i < devices.length; i++)
{
- console.log("Device disappeared: " + address);
- /* Removes from list, as it is no longer valid */
- },
- onfinished: function(devices)
- {
- console.log("Found Devices");
- for (var i = 0; i < devices.length; i++)
- {
- console.log("Name: " + devices[i].name + ", Address: " + devices[i].address);
- }
- console.log("Total: " + devices.length);
+ console.log("Name: " + devices[i].name + ", Address: " + devices[i].address);
}
- };
-
- /* Starts searching for nearby devices, for about 12 sec */
- adapter.discoverDevices(discoverDevicesSuccessCallback, function(e)
- {
- console.log("Failed to search devices: " + e.message + "(" + e.name + ")");
- });
+ console.log("Total: " + devices.length);
+ }
+ };
+
+ /* Starts searching for nearby devices, for about 12 sec */
+ adapter.discoverDevices(discoverDevicesSuccessCallback, function(e)
+ {
+ console.log("Failed to search devices: " + e.message + "(" + e.name + ")");
+ });
}
function onSetPoweredError(e)
{
- console.log("Could not turn on device, reason: " + e.message + "(" + e.name + ")");
+ console.log("Could not turn on device, reason: " + e.message + "(" + e.name + ")");
}
adapter.setPowered(true, startDiscovery, onSetPoweredError);
@@ -1820,22 +1855,22 @@ var adapter = tizen.bluetooth.getDefaultAdapter();
function onGotDevices(devices)
{
- console.log("Devices");
- for (var i = 0; i < devices.length; i++)
- {
- console.log(" Name: " + devices[i].name + ", Address: " + devices[i].address);
- }
- console.log("Total: " + devices.length);
+ console.log("Devices");
+ for (var i = 0; i < devices.length; i++)
+ {
+ console.log(" Name: " + devices[i].name + ", Address: " + devices[i].address);
+ }
+ console.log("Total: " + devices.length);
}
function onError(e)
{
- console.log("Error: " + e.message);
+ console.log("Error: " + e.message);
}
function onBluetoothsetPowered()
{
- adapter.getKnownDevices(onGotDevices, onError);
+ adapter.getKnownDevices(onGotDevices, onError);
}
/* Turns on Bluetooth */
@@ -1919,15 +1954,15 @@ Instead, use http://tizen.org/privilege/bluetooth.
@@ -2466,11 +2509,11 @@ Instead, use http://tizen.org/privilege/bluetooth.
var adapter = tizen.bluetooth.getLEAdapter();
adapter.startScan(function onsuccess(device)
{
- if (device.address == "11:22:33:44:55:66")
- {
- console.log("Found device: " + device.name);
- adapter.stopScan();
- }
+ if (device.address == "11:22:33:44:55:66")
+ {
+ console.log("Found device: " + device.name);
+ adapter.stopScan();
+ }
});
@@ -2568,11 +2611,11 @@ var battery_svc_uuid_16 = "180f"; /* Service UUID, 16-bit UUID is supported (e.g
var heart_rate_svc_uuid_16 = "180d"; /* Service solicitation UUID, 16-bit UUID is supported (e.g. 180d) */
var advertiseOptions =
{
- includeName: true, /* Whether the device name should be included */
- includeTxPowerLevel: true, /* Whether the transmission power level should be included */
- appearance: 192, /* External appearance of device, 192 - Generic Watch */
- uuids: [battery_svc_uuid_16],
- solicitationuuids: [heart_rate_svc_uuid_16]
+ includeName: true, /* Whether the device name should be included */
+ includeTxPowerLevel: true, /* Whether the transmission power level should be included */
+ appearance: 192, /* External appearance of device, 192 - Generic Watch */
+ uuids: [battery_svc_uuid_16],
+ solicitationuuids: [heart_rate_svc_uuid_16]
};
var advertiseData = new tizen.BluetoothLEAdvertiseData(advertiseOptions);
@@ -2580,10 +2623,10 @@ var connectable = true;
adapter.startAdvertise(advertiseData, "ADVERTISE", function onstate(state)
{
- console.log("Advertiser state: " + state);
+ console.log("Advertiser state: " + state);
}, function(e)
{
- console.log("Failed to startAdvertise: " + e.message);
+ console.log("Failed to startAdvertise: " + e.message);
}, "LOW_LATENCY", connectable);
@@ -2632,18 +2675,18 @@ var battery_svc_uuid_16 = "180f"; /* Service UUID, 16-bit UUID is supported (e.g
var heart_rate_svc_uuid_16 = "180d"; /* Service solicitation UUID, 16-bit UUID is supported (e.g. 180d) */
var advertiseOptions =
{
- includeName: true, /* Whether the device name should be included */
- includeTxPowerLevel: true, /* Whether the transmission power level should be included */
- appearance: 192, /* External appearance of device, 192 - Generic Watch */
- uuids: [battery_svc_uuid_16],
- solicitationuuids: [heart_rate_svc_uuid_16]
+ includeName: true, /* Whether the device name should be included */
+ includeTxPowerLevel: true, /* Whether the transmission power level should be included */
+ appearance: 192, /* External appearance of device, 192 - Generic Watch */
+ uuids: [battery_svc_uuid_16],
+ solicitationuuids: [heart_rate_svc_uuid_16]
};
var advertiseData = new tizen.BluetoothLEAdvertiseData(advertiseOptions);
adapter.startAdvertise(advertiseData, "ADVERTISE", function onstate(state)
{
- console.log("Advertiser state: " + state);
+ console.log("Advertiser state: " + state);
});
adapter.stopAdvertise();
@@ -2670,16 +2713,16 @@ adapter.stopAdvertise();
function gotDeviceInfo(device)
{
- console.log("Device Name: " + device.name);
- console.log("Device Address: " + device.address);
- console.log("Device Class: " + device.deviceClass.major);
- console.log("Is Bonded: " + (device.isBonded ? "Yes" : "No"));
+ console.log("Device Name: " + device.name);
+ console.log("Device Address: " + device.address);
+ console.log("Device Class: " + device.deviceClass.major);
+ console.log("Is Bonded: " + (device.isBonded ? "Yes" : "No"));
}
function onError(e)
{
- console.log("Could not get device info:" + e.message);
+ console.log("Could not get device info:" + e.message);
}
var adapter = tizen.bluetooth.getDefaultAdapter();
@@ -2009,14 +2044,14 @@ Instead, use http://tizen.org/privilege/bluetooth.
@@ -2282,6 +2321,10 @@ function unregisterChatService()
+
function onBondingSuccess(device)
{
- console.log("Device Name:" + device.name);
- console.log("Device Address:" + device.address);
- console.log("Device Service UUIDs:" + device.uuids.join("\n"));
+ console.log("Device Name:" + device.name);
+ console.log("Device Address:" + device.address);
+ console.log("Device Service UUIDs:" + device.uuids.join("\n"));
}
function onError(e)
{
- console.log("Could not create bonding, reason:" + e.message);
+ console.log("Could not create bonding, reason:" + e.message);
}
var adapter = tizen.bluetooth.getDefaultAdapter();
@@ -2100,23 +2135,23 @@ var adapter = tizen.bluetooth.getDefaultAdapter();
function gotDevice(device)
{
- if (device.isBonded)
- {
- /* Initiates destroying bonding */
- adapter.destroyBonding(device.address, function()
- {
- console.log("Succeeded to destroy the bond success with:" + device.address);
- }, function(e)
- {
- console.log("Failed to destroy the bond with " + device.address + ", reason: " + e.message);
- });
- }
+ if (device.isBonded)
+ {
+ /* Initiates destroying bonding */
+ adapter.destroyBonding(device.address, function()
+ {
+ console.log("Succeeded to destroy the bond success with:" + device.address);
+ }, function(e)
+ {
+ console.log("Failed to destroy the bond with " + device.address + ", reason: " + e.message);
+ });
+ }
}
var deviceAddress = "35:F4:59:D1:7A:03";
adapter.getDevice(deviceAddress, gotDevice, function(e)
{
- console.log("Failed to get device info for " + deviceAddress + ", reason: " + e.message);
+ console.log("Failed to get device info for " + deviceAddress + ", reason: " + e.message);
});
@@ -2213,47 +2248,51 @@ var serviceSocket = null;
function chatServiceSuccessCb(recordHandler)
{
- console.log("Chat service registration succeeds!");
- chatServiceHandler = recordHandler;
- recordHandler.onconnect = function(socket)
- {
- console.log("Client connected: " + socket.peer.name + "," + socket.peer.address);
- serviceSocket = socket;
- /* Messages received from remote device */
- socket.onmessage = function()
- {
- var data = socket.readData();
- /* Handles message code goes here */
- };
+ console.log("Chat service registration succeeds!");
+ chatServiceHandler = recordHandler;
+ recordHandler.onconnect = function(socket)
+ {
+ console.log("Client connected: " + socket.peer.name + "," + socket.peer.address);
+ serviceSocket = socket;
+ /* Messages received from remote device */
+ socket.onmessage = function()
+ {
+ var data = socket.readData();
+ /* Handles message code goes here */
+ };
- socket.onclose = function()
- {
- console.log('The socket is closed.');
- serviceSocket = null;
- };
- };
+ socket.onclose = function()
+ {
+ console.log("The socket is closed.");
+ serviceSocket = null;
+ };
+ };
};
function publishChatService()
{
- var CHAT_SERVICE_UUID = "5BCE9431-6C75-32AB-AFE0-2EC108A30860";
- adapter.registerRFCOMMServiceByUUID(CHAT_SERVICE_UUID, "Chat service", chatServiceSuccessCb,
- /* Error handler: function(e) {console.log("Could not register service record, Error: " + e.message);} */);
+ var CHAT_SERVICE_UUID = "5BCE9431-6C75-32AB-AFE0-2EC108A30860";
+ adapter.registerRFCOMMServiceByUUID(CHAT_SERVICE_UUID, "Chat service", chatServiceSuccessCb,
+ /* Error handler */
+ function(e)
+ {
+ console.log( "Could not register service record, Error: " + e.message);
+ });
}
function unregisterChatService()
{
- if (chatServiceHandler != null)
- {
- chatServiceHandler.unregister(function()
- {
- console.log("Chat service is unregistered");
- chatServiceHandler = null;
- }, function(e)
- {
- console.log("Failed to unregister service: " + e.message);
- });
- }
+ if (chatServiceHandler != null)
+ {
+ chatServiceHandler.unregister(function()
+ {
+ console.log("Chat service is unregistered");
+ chatServiceHandler = null;
+ }, function(e)
+ {
+ console.log("Failed to unregister service: " + e.message);
+ });
+ }
}
@@ -2305,11 +2348,11 @@ var healthCapability = tizen.systeminfo.getCapability("http://tizen.org/feature/
if (healthCapability)
{
- healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH");
+ healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH");
}
else
{
- console.log("Bluetooth Health Profile is not supported on this device.");
+ console.log("Bluetooth Health Profile is not supported on this device.");
}
function onconnected(device)
{
- console.log("Connected to device");
- var service = device.getService(device.uuids[0]);
- console.log("Service got");
+ console.log("Connected to device");
+ var service = device.getService(device.uuids[0]);
+ console.log("Service got");
}
var adapter = tizen.bluetooth.getLEAdapter();
adapter.startScan(function onsuccess(device)
{
- console.log("[Found device] address: " + device.address);
- device.connect(onconnected.bind(null, device), onerror);
+ console.log("[Found device] address: " + device.address);
+ device.connect(onconnected.bind(null, device), onerror);
});
@@ -2717,7 +2760,7 @@ console.log("Service UUID " + service.uuid);
var service = device.getService(device.uuids[0]);
for (var i = 0; i service.services.length; ++i)
{
- console.log("Subservices UUID " + service.services[i].uuid);
+ console.log("Subservices UUID " + service.services[i].uuid);
}
@@ -2737,7 +2780,7 @@ for (var i = 0; i service.services.length; ++i)
var service = device.getService(device.uuids[0]);
for (var i = 0; i service.characteristics.length; ++i)
{
- console.log("Subservices UUID " + service.characteristics[i].isWritable);
+ console.log("Subservices UUID " + service.characteristics[i].isWritable);
}
@@ -2938,35 +2981,35 @@ Instead, use http://tizen.org/privilege/bluetooth.
function onerror(e)
{
- console.log("Failed to connect to device: " + e.message);
+ console.log("Failed to connect to device: " + e.message);
}
function proccessDevice(device)
{
- device.connect(onConnected, onerror);
- function onConnected()
- {
- var service = device.getService(device.uuids[0]);
- if (service.characteristics.length > 0)
+ device.connect(onConnected, onerror);
+ function onConnected()
+ {
+ var service = device.getService(device.uuids[0]);
+ if (service.characteristics.length > 0)
+ {
+ var characteristic = service.characteristics[0];
+ characteristic.readValue(function(val)
{
- var characteristic = service.characteristics[0];
- characteristic.readValue(function(val)
- {
- console.log("Value read: " + val);
- device.disconnect();
- });
- }
- }
+ console.log("Value read: " + val);
+ device.disconnect();
+ });
+ }
+ }
}
var adapter = tizen.bluetooth.getLEAdapter();
adapter.startScan(function onsuccess(device)
{
- if (device.address == "11:22:33:44:55:66")
- {
- console.log("Found device: " + device.name);
- proccessDevice(device);
- }
+ if (device.address == "11:22:33:44:55:66")
+ {
+ console.log("Found device: " + device.name);
+ proccessDevice(device);
+ }
});
@@ -3041,39 +3084,39 @@ Instead, use http://tizen.org/privilege/bluetooth.
function onerror(e)
{
- console.log("Failed to connect to device: " + e.message);
+ console.log("Failed to connect to device: " + e.message);
}
function proccessDevice(device)
{
- device.connect(onConnected, onerror);
- function onConnected()
- {
- var service = device.getService(device.uuids[0]);
- if (service.characteristics.length > 0)
+ device.connect(onConnected, onerror);
+ function onConnected()
+ {
+ var service = device.getService(device.uuids[0]);
+ if (service.characteristics.length > 0)
+ {
+ var characteristic = service.characteristics[0];
+ var data = new Array(1, 2, 3, 4, 5, 6);
+ characteristic.writeValue(data, function()
{
- var characteristic = service.characteristics[0];
- var data = new Array(1, 2, 3, 4, 5, 6);
- characteristic.writeValue(data, function()
- {
- console.log("Value written");
- device.disconnect();
- }, function(e)
- {
- console.log("Failed to write: " + e.message);
- });
- }
- }
+ console.log("Value written");
+ device.disconnect();
+ }, function(e)
+ {
+ console.log("Failed to write: " + e.message);
+ });
+ }
+ }
}
var adapter = tizen.bluetooth.getLEAdapter();
adapter.startScan(function onsuccess(device)
{
- if (device.address == "11:22:33:44:55:66")
- {
- console.log("Found device: " + device.name);
- proccessDevice(device);
- }
+ if (device.address == "11:22:33:44:55:66")
+ {
+ console.log("Found device: " + device.name);
+ proccessDevice(device);
+ }
});
@@ -3127,35 +3170,34 @@ Instead, use http://tizen.org/privilege/bluetooth.
function proccessDevice(device)
{
- function onConnected()
- {
- var service = device.getService("5BCE9431-6C75-32AB-AFE0-2EC108A30860");
- if (service.characteristics.length > 0)
- {
- var characteristic = service.characteristics[0];
- var watchID;
-
- watchID = characteristic.addValueChangeListener(function(value)
- {
- console.log("Characteristic value changed: " + value);
- characteristic.removeValueChangeListener(watchID);
- device.disconnect();
- });
- }
- }
+ function onConnected()
+ {
+ var service = device.getService("5BCE9431-6C75-32AB-AFE0-2EC108A30860");
+ if (service.characteristics.length > 0)
+ {
+ var characteristic = service.characteristics[0];
+ var watchID;
- device.connect(onConnected);
+ watchID = characteristic.addValueChangeListener(function(value)
+ {
+ console.log("Characteristic value changed: " + value);
+ characteristic.removeValueChangeListener(watchID);
+ device.disconnect();
+ });
+ }
+ }
+ device.connect(onConnected);
}
var adapter = tizen.bluetooth.getLEAdapter();
adapter.startScan(function onsuccess(device)
{
- if (device.address == "11:22:33:44:55:66")
- {
- console.log("Found device: " + device.name);
- adapter.stopScan();
- proccessDevice(device);
- }
+ if (device.address == "11:22:33:44:55:66")
+ {
+ console.log("Found device: " + device.name);
+ adapter.stopScan();
+ proccessDevice(device);
+ }
});
@@ -3273,36 +3315,36 @@ Instead, use http://tizen.org/privilege/bluetooth.
function onerror(e)
{
- console.log("Failed to connect to device: " + e.message);
+ console.log("Failed to connect to device: " + e.message);
}
function proccessDevice(device)
{
- device.connect(onConnected, onerror);
- function onConnected()
- {
- var service = device.getService(device.uuids[0]);
- if (service.characteristics.length > 0)
+ device.connect(onConnected, onerror);
+ function onConnected()
+ {
+ var service = device.getService(device.uuids[0]);
+ if (service.characteristics.length > 0)
+ {
+ var characteristic = service.characteristics[0];
+ var descriptor = characteristic.descriptors[0];
+ descriptor.readValue(function(val)
{
- var characteristic = service.characteristics[0];
- var descriptor = characteristic.descriptors[0];
- descriptor.readValue(function(val)
- {
- console.log("Value read: " + val);
- device.disconnect();
- });
- }
- }
+ console.log("Value read: " + val);
+ device.disconnect();
+ });
+ }
+ }
}
var adapter = tizen.bluetooth.getLEAdapter();
adapter.startScan(function onsuccess(device)
{
- if (device.address == "11:22:33:44:55:66")
- {
- console.log("Found device: " + device.name);
- proccessDevice(device);
- }
+ if (device.address == "11:22:33:44:55:66")
+ {
+ console.log("Found device: " + device.name);
+ proccessDevice(device);
+ }
});
@@ -3377,40 +3419,40 @@ Instead, use http://tizen.org/privilege/bluetooth.
function onerror(e)
{
- console.log("Failed to connect to device: " + e.message);
+ console.log("Failed to connect to device: " + e.message);
}
function proccessDevice(device)
{
- device.connect(onConnected, onerror);
- function onConnected()
- {
- var service = device.getService(device.uuids[0]);
- if (service.characteristics.length > 0)
+ device.connect(onConnected, onerror);
+ function onConnected()
+ {
+ var service = device.getService(device.uuids[0]);
+ if (service.characteristics.length > 0)
+ {
+ var characteristic = service.characteristics[0];
+ var data = new Array(1, 2, 3, 4, 5, 6);
+ var descriptor = characteristic.descriptors[0];
+ descriptor.writeValue(data, function()
{
- var characteristic = service.characteristics[0];
- var data = new Array(1, 2, 3, 4, 5, 6);
- var descriptor = characteristic.descriptors[0];
- descriptor.writeValue(data, function()
- {
- console.log("Value written");
- device.disconnect();
- }, function(e)
- {
- console.log("Failed to write: " + e.message);
- });
- }
- }
+ console.log("Value written");
+ device.disconnect();
+ }, function(e)
+ {
+ console.log("Failed to write: " + e.message);
+ });
+ }
+ }
}
var adapter = tizen.bluetooth.getLEAdapter();
adapter.startScan(function onsuccess(device)
{
- if (device.address == "11:22:33:44:55:66")
- {
- console.log("Found device: " + device.name);
- proccessDevice(device);
- }
+ if (device.address == "11:22:33:44:55:66")
+ {
+ console.log("Found device: " + device.name);
+ proccessDevice(device);
+ }
});
@@ -3666,7 +3708,7 @@ A BluetoothDevice object can be retrieved using one of the following AP
var adapter = tizen.bluetooth.getDefaultAdapter();
adapter.getDevice("11:22:33:44:55:66", function(device)
{
- console.log("Device Name: " + device.name);
+ console.log("Device Name: " + device.name);
});
@@ -3685,7 +3727,7 @@ adapter.getDevice("11:22:33:44:55:66", function(device)
var adapter = tizen.bluetooth.getDefaultAdapter();
adapter.getDevice("11:22:33:44:55:66", function(device)
{
- console.log("Device Address: " + device.address);
+ console.log("Device Address: " + device.address);
});
@@ -3704,7 +3746,7 @@ adapter.getDevice("11:22:33:44:55:66", function(device)
var adapter = tizen.bluetooth.getDefaultAdapter();
adapter.getDevice("11:22:33:44:55:66", function(device)
{
- console.log("Device Major Class: " + device.deviceClass.major);
+ console.log("Device Major Class: " + device.deviceClass.major);
});
@@ -3723,7 +3765,7 @@ adapter.getDevice("11:22:33:44:55:66", function(device)
var adapter = tizen.bluetooth.getDefaultAdapter();
adapter.getDevice("11:22:33:44:55:66", function(device)
{
- console.log("Is bonded: " + (device.isBonded ? "Yes" : "No"));
+ console.log("Is bonded: " + (device.isBonded ? "Yes" : "No"));
});
@@ -3742,7 +3784,7 @@ adapter.getDevice("11:22:33:44:55:66", function(device)
var adapter = tizen.bluetooth.getDefaultAdapter();
adapter.getDevice("11:22:33:44:55:66", function(device)
{
- console.log("Is trusted: " + (device.isTrusted ? "Yes" : "No"));
+ console.log("Is trusted: " + (device.isTrusted ? "Yes" : "No"));
});
@@ -3761,7 +3803,7 @@ adapter.getDevice("11:22:33:44:55:66", function(device)
var adapter = tizen.bluetooth.getDefaultAdapter();
adapter.getDevice("11:22:33:44:55:66", function(device)
{
- console.log("Is connected: " + (device.isConnected ? "Yes" : "No"));
+ console.log("Is connected: " + (device.isConnected ? "Yes" : "No"));
});
@@ -3782,24 +3824,24 @@ var adapter = tizen.bluetooth.getDefaultAdapter();
var CHAT_SERVICE_UUID = "5BCE9431-6C75-32AB-AFE0-2EC108A30860";
adapter.getDevice("11:22:33:44:55:66", function(device)
{
- var uuids = device.uuids;
- var services = "";
- for (var i = 0; i < uuids.length; i++)
- {
- services += uuids[i] + "\n";
- }
- console.log("Services found: " + services);
- if (uuids.indexOf(CHAT_SERVICE_UUID) != -1)
- {
- /* Connects to service */
- device.connectToServiceByUUID(CHAT_SERVICE_UUID, function(socket)
- {
- /* Connected to service, handle socket */
- }, function(e)
- {
- console.log("Could not connect to chat service !!!. Error: " + e.message);
- });
- }
+ var uuids = device.uuids;
+ var services = "";
+ for (var i = 0; i < uuids.length; i++)
+ {
+ services += uuids[i] + "\n";
+ }
+ console.log("Services found: " + services);
+ if (uuids.indexOf(CHAT_SERVICE_UUID) != -1)
+ {
+ /* Connects to service */
+ device.connectToServiceByUUID(CHAT_SERVICE_UUID, function(socket)
+ {
+ /* Connected to service, handle socket */
+ }, function(e)
+ {
+ console.log("Could not connect to chat service !!!. Error: " + e.message);
+ });
+ }
});
@@ -3887,57 +3929,57 @@ var clientSocket = null;
/* Calls a method that is invoked when user wants to send a message to a remote device */
function sendMessage(msg)
{
- /* Validates socket state, if everything is ok */
- if (clientSocket != null && clientSocket.state == "OPEN")
- {
- /* Sends the message */
- clientSocket.writeData(msg);
- }
+ /* Validates socket state, if everything is ok */
+ if (clientSocket != null && clientSocket.state == "OPEN")
+ {
+ /* Sends the message */
+ clientSocket.writeData(msg);
+ }
}
/* Calls a method that is invoked when a socket is open */
function onSocketConnected(socket)
{
- clientSocket = socket;
- console.log("Opening a socket successfully!!!");
- socket.onmessage = function()
- {
- var data = socket.readData();
- var recvmsg = "";
- for (var i = 0; i < data.length; i++)
- {
- recvmsg += String.fromCharCode(data[i]);
- }
- console.log("server msg >> " + recvmsg);
- };
-
- socket.onclose = function()
- {
- console.log("socket disconnected.");
- };
+ clientSocket = socket;
+ console.log("Opening a socket successfully!!!");
+ socket.onmessage = function()
+ {
+ var data = socket.readData();
+ var recvmsg = "";
+ for (var i = 0; i < data.length; i++)
+ {
+ recvmsg += String.fromCharCode(data[i]);
+ }
+ console.log("server msg >> " + recvmsg);
+ };
+
+ socket.onclose = function()
+ {
+ console.log("socket disconnected.");
+ };
}
function onDeviceReady(device)
{
- /* Validates device and service uuid */
- if (device.uuids.indexOf("5BCE9431-6C75-32AB-AFE0-2EC108A30860") != -1)
- {
- /* Opens socket */
- device.connectToServiceByUUID("5BCE9431-6C75-32AB-AFE0-2EC108A30860", onSocketConnected, function(e)
- {
- console.log("Error connecting to service. Reason: " + e.message);
- });
- }
- else
- {
- console.log("Chat service is not supported by this device");
- }
+ /* Validates device and service uuid */
+ if (device.uuids.indexOf("5BCE9431-6C75-32AB-AFE0-2EC108A30860") != -1)
+ {
+ /* Opens socket */
+ device.connectToServiceByUUID("5BCE9431-6C75-32AB-AFE0-2EC108A30860", onSocketConnected, function(e)
+ {
+ console.log("Error connecting to service. Reason: " + e.message);
+ });
+ }
+ else
+ {
+ console.log("Chat service is not supported by this device");
+ }
}
function onSetPowered()
{
- /* Gets the BluetoothDevice object */
- adapter.getDevice("35:F4:59:D1:7A:03", onDeviceReady, function(e) {console.log("Error: " + e.message);});
+ /* Gets the BluetoothDevice object */
+ adapter.getDevice("35:F4:59:D1:7A:03", onDeviceReady, function(e) {console.log("Error: " + e.message); });
}
adapter.setPowered(true, onSetPowered, function(e) {console.log("Could not turn on Bluetooth adapter. reason: " + e.message); });
@@ -4006,7 +4048,7 @@ A BluetoothLEDevice object can be retrieved by using one of the followi
var adapter = tizen.bluetooth.getLEAdapter();
adapter.startScan(function onsuccess(device)
{
- console.log("Found device: " + device.address);
+ console.log("Found device: " + device.address);
});
@@ -4025,14 +4067,14 @@ adapter.startScan(function onsuccess(device)
var adapter = tizen.bluetooth.getLEAdapter();
adapter.startScan(function onsuccess(device)
{
- console.log("Found device: " + device.name);
+ console.log("Found device: " + device.name);
});
function onerror(e)
{
- console.log("Failed to connect to device: " + e.message);
+ console.log("Failed to connect to device: " + e.message);
}
function onconnected()
{
- console.log("Connected to device");
+ console.log("Connected to device");
}
var adapter = tizen.bluetooth.getLEAdapter();
adapter.startScan(function onsuccess(device)
{
- if (device.address == "11:22:33:44:55:66")
- {
- console.log("Found device: " + device.name);
- device.connect(onconnected, onerror);
+ if (device.address == "11:22:33:44:55:66")
+ {
+ console.log("Found device: " + device.name);
+ device.connect(onconnected, onerror);
}
});
@@ -4354,27 +4396,27 @@ Instead, use http://tizen.org/privilege/bluetooth.
function onerror(e)
{
- console.log("Error occurred: " + e.message);
+ console.log("Error occurred: " + e.message);
}
function onDeviceFound(device)
{
- function ondisconnect()
- {
- console.log("Disconnected");
- }
-
- function onconnected()
- {
- console.log("Connected to device");
- device.disconnect(ondisconnect, onerror);
- }
-
- if (device.address == "11:22:33:44:55:66")
- {
- console.log("Found device: " + device.name);
- device.connect(onconnected, onerror);
- }
+ function ondisconnect()
+ {
+ console.log("Disconnected");
+ }
+
+ function onconnected()
+ {
+ console.log("Connected to device");
+ device.disconnect(ondisconnect, onerror);
+ }
+
+ if (device.address == "11:22:33:44:55:66")
+ {
+ console.log("Found device: " + device.name);
+ device.connect(onconnected, onerror);
+ }
}
var adapter = tizen.bluetooth.getLEAdapter();
@@ -4438,23 +4480,23 @@ Instead, use http://tizen.org/privilege/bluetooth.
function onconnected(device)
{
- console.log("Connected to device");
- var service = device.getService(device.uuids[0]);
- console.log("Service got");
+ console.log("Connected to device");
+ var service = device.getService(device.uuids[0]);
+ console.log("Service got");
}
function onerror(e)
{
- console.log("Error occurred: " + e.message);
+ console.log("Error occurred: " + e.message);
}
function onDeviceFound(device)
{
- if (device.address == "11:22:33:44:55:66")
- {
- console.log("Found device: " + device.name);
- device.connect(onconnected.bind(null, device), onerror);
- }
+ if (device.address == "11:22:33:44:55:66")
+ {
+ console.log("Found device: " + device.name);
+ device.connect(onconnected.bind(null, device), onerror);
+ }
}
var adapter = tizen.bluetooth.getLEAdapter();
@@ -4483,41 +4525,56 @@ adapter.startScan(onDeviceFound, onerror);
Privilege:
-
+
+/*Below variable should represent valid address of discoverable bluetooth low energy device */
+var remoteAddress = "11:22:33:44:55:66";
+
function onconnected(device)
{
- console.log("Connected to device");
- var services = device.getServiceAllUuids();
- console.log("Services length " + services.length);
+ console.log("Connected to device");
+ var services = device.getServiceAllUuids();
+ console.log("Services length " + services.length);
}
function onerror(e)
{
- console.log("Error occurred: " + e.message);
+ console.log("Error occurred: " + e.message);
}
function onDeviceFound(device)
{
- if (device.address == "11:22:33:44:55:66")
- {
- console.log("Found device: " + device.name);
- device.connect(onconnected.bind(null, device), onerror);
- }
+ if (device.address == remoteAddress)
+ {
+ device.connect(onconnected.bind(null, device), onerror);
+ }
}
var adapter = tizen.bluetooth.getLEAdapter();
adapter.startScan(onDeviceFound, onerror);
Connected to device
+ Services length 2
+
+addConnectStateChangeListener
@@ -4556,29 +4613,29 @@ adapter.startScan(onDeviceFound, onerror);
function onerror(e)
{
- console.log("Error occurred: " + e.message);
+ console.log("Error occurred: " + e.message);
}
function onDeviceFound(device)
{
- var onConnectionStateChange =
- {
- onconnected: function(device)
- {
- console.log("Device " + device.name + " connected");
- },
- ondisconnected: function(device)
- {
- console.log("Device " + device.name + " disconnected");
- }
- }
-
- if (device.address === "11:22:33:44:55:66")
- {
- console.log("Found device: " + device.name);
- device.addConnectStateChangeListener(onConnectionStateChange);
- device.connect();
- }
+ var onConnectionStateChange =
+ {
+ onconnected: function(device)
+ {
+ console.log("Device " + device.name + " connected");
+ },
+ ondisconnected: function(device)
+ {
+ console.log("Device " + device.name + " disconnected");
+ }
+ }
+
+ if (device.address === "11:22:33:44:55:66")
+ {
+ console.log("Found device: " + device.name);
+ device.addConnectStateChangeListener(onConnectionStateChange);
+ device.connect();
+ }
}
var adapter = tizen.bluetooth.getLEAdapter();
@@ -4612,30 +4669,30 @@ adapter.startScan(onDeviceFound, onerror);
function onerror(e)
{
- console.log("Error occurred: " + e.message);
+ console.log("Error occurred: " + e.message);
}
function onDeviceFound(device)
{
- var onConnectionStateChange =
- {
- onconnected: function(device)
- {
- console.log("Device " + device.name + " connected");
- },
- ondisconnected: function(device)
- {
- console.log("Device " + device.name + " disconnected");
- device.removeConnectStateChangeListener(listenerID);
- }
- }
-
- if (device.address === "11:22:33:44:55:66")
- {
- console.log("Found device: " + device.name);
- listenerID = device.addConnectStateChangeListener(onConnectionStateChange);
- device.connect();
- }
+ var onConnectionStateChange =
+ {
+ onconnected: function(device)
+ {
+ console.log("Device " + device.name + " connected");
+ },
+ ondisconnected: function(device)
+ {
+ console.log("Device " + device.name + " disconnected");
+ device.removeConnectStateChangeListener(listenerID);
+ }
+ }
+
+ if (device.address === "11:22:33:44:55:66")
+ {
+ console.log("Found device: " + device.name);
+ listenerID = device.addConnectStateChangeListener(onConnectionStateChange);
+ device.connect();
+ }
}
var adapter = tizen.bluetooth.getLEAdapter();
@@ -4806,46 +4863,46 @@ var adapter = tizen.bluetooth.getDefaultAdapter();
function onSocketConnected(socket)
{
- console.log("Opened connection to remote device");
- socket.onmessage = function()
- {
- console.log("Message received: " + socket.readData());
- };
-
- socket.onclose = function()
- {
- console.log("Socket closed with " + socket.peer.name);
- };
-
- /* Sends data to peer */
- var textmsg = "Test";
- var sendtextmsg = new Array();
- for (var i = 0; i < textmsg.length; i++)
- {
- sendtextmsg[i] = textmsg.charCodeAt(i);
- }
- socket.writeData(sendtextmsg);
+ console.log("Opened connection to remote device");
+ socket.onmessage = function()
+ {
+ console.log("Message received: " + socket.readData());
+ };
+
+ socket.onclose = function()
+ {
+ console.log("Socket closed with " + socket.peer.name);
+ };
+
+ /* Sends data to peer */
+ var textmsg = "Test";
+ var sendtextmsg = new Array();
+ for (var i = 0; i < textmsg.length; i++)
+ {
+ sendtextmsg[i] = textmsg.charCodeAt(i);
+ }
+ socket.writeData(sendtextmsg);
}
function onSocketError(e)
{
- console.log("Error connecting to service. Reason: " + e.message);
+ console.log("Error connecting to service. Reason: " + e.message);
}
function onDeviceReady(device)
{
- /* Validates device and service uuid */
- if (device.uuids.indexOf("5BCE9431-6C75-32AB-AFE0-2EC108A30860") != -1)
- {
- /* Opens socket */
- device.connectToServiceByUUID("5BCE9431-6C75-32AB-AFE0-2EC108A30860", onSocketConnected, onSocketError);
- }
+ /* Validates device and service uuid */
+ if (device.uuids.indexOf("5BCE9431-6C75-32AB-AFE0-2EC108A30860") != -1)
+ {
+ /* Opens socket */
+ device.connectToServiceByUUID("5BCE9431-6C75-32AB-AFE0-2EC108A30860", onSocketConnected, onSocketError);
+ }
}
function onSetPowered()
{
- /* Gets the BluetoothDevice object */
- adapter.getDevice("35:F4:59:D1:7A:03", onDeviceReady, function(e) {console.log("Error: " + e.message);});
+ /* Gets the BluetoothDevice object */
+ adapter.getDevice("35:F4:59:D1:7A:03", onDeviceReady, function(e) {console.log("Error: " + e.message);});
}
adapter.setPowered(true, onSetPowered, function(e) {console.log("Could not turn on Bluetooth adapter. reason: " + e.message);});
@@ -4904,41 +4961,41 @@ var adapter = tizen.bluetooth.getDefaultAdapter();
function onError(e)
{
- console.log("Error connecting to service. Reason: " + e.message);
+ console.log("Error connecting to service. Reason: " + e.message);
}
function onSocketConnected(socket)
{
- console.log("Opening socket success!!!");
+ console.log("Opening socket success!!!");
- socket.onmessage = function()
- {
- /* Gets a message from peer, reads it */
- var data = socket.readData();
+ socket.onmessage = function()
+ {
+ /* Gets a message from peer, reads it */
+ var data = socket.readData();
- /* Code to evaluate message goes here */
- };
+ /* Code to evaluate message goes here */
+ };
- socket.onclose = function()
- {
- console.log("Socket closed with " + socket.peer.name);
- };
+ socket.onclose = function()
+ {
+ console.log("Socket closed with " + socket.peer.name);
+ };
}
function onDeviceReady(device)
{
- /* Validates device and service uuid */
- if (device.uuids.indexOf("5BCE9431-6C75-32AB-AFE0-2EC108A30860") != -1)
- {
- /* Opens socket */
- device.connectToServiceByUUID("5BCE9431-6C75-32AB-AFE0-2EC108A30860", onSocketConnected, onError);
- }
+ /* Validates device and service uuid */
+ if (device.uuids.indexOf("5BCE9431-6C75-32AB-AFE0-2EC108A30860") != -1)
+ {
+ /* Opens socket */
+ device.connectToServiceByUUID("5BCE9431-6C75-32AB-AFE0-2EC108A30860", onSocketConnected, onError);
+ }
}
function onSetPowered()
{
- /* Gets the BluetoothDevice object */
- adapter.getDevice("35:F4:59:D1:7A:03", onDeviceReady, function(e) {console.log("Error: " + e.message);});
+ /* Gets the BluetoothDevice object */
+ adapter.getDevice("35:F4:59:D1:7A:03", onDeviceReady, function(e) {console.log("Error: " + e.message);});
}
adapter.setPowered(true, onSetPowered, function(e) {console.log("Could not turn on Bluetooth adapter. reason: " + e.message);});
@@ -5001,7 +5058,7 @@ Instead, use http://tizen.org/privilege/bluetooth.
readonly attribute octet minor;
- readonly attribute unsigned short [] services ;
+ readonly attribute unsigned short [] services;
boolean hasService(unsigned short service) raises(WebAPIException);
};
@@ -5052,22 +5109,22 @@ var adapter = tizen.bluetooth.getDefaultAdapter();
function evaluateDevice(address)
{
- adapter.getDevice(address, function(device)
- {
- if (device.deviceClass.major == tizen.bluetooth.deviceMajor.COMPUTER)
- {
- /* Shows computer icon for this device */
- console.log("Device is computer");
- }
- else if (device.deviceClass.major == tizen.bluetooth.deviceMajor.PHONE)
- {
- /* Shows phone icon */
- console.log("Device is a Phone");
- }
- }, function(e)
- {
- console.log("Couldn't get any device with the given address: " + e.message);
- });
+ adapter.getDevice(address, function(device)
+ {
+ if (device.deviceClass.major == tizen.bluetooth.deviceMajor.COMPUTER)
+ {
+ /* Shows computer icon for this device */
+ console.log("Device is computer");
+ }
+ else if (device.deviceClass.major == tizen.bluetooth.deviceMajor.PHONE)
+ {
+ /* Shows phone icon */
+ console.log("Device is a Phone");
+ }
+ }, function(e)
+ {
+ console.log("Couldn't get any device with the given address: " + e.message);
+ });
}
evaluateDevice("11:22:33:44:55:66");
@@ -5140,6 +5197,10 @@ Instead, use http://tizen.org/privilege/bluetooth.
+
@@ -5160,13 +5221,13 @@ Instead, use http://tizen.org/privilege/bluetooth.
var adapter = tizen.bluetooth.getDefaultAdapter();
adapter.getDevice("12:34:56:78:9A:BC", function(device)
{
- if (device.deviceClass.hasService(tizen.bluetooth.deviceService.POSITIONING))
- {
- console.log("Device supports Positioning service");
- }
+ if (device.deviceClass.hasService(tizen.bluetooth.deviceService.POSITIONING))
+ {
+ console.log("Device supports Positioning service");
+ }
}, function(e)
{
- console.log("Couldn't get device for given address: " + e.message);
+ console.log("Couldn't get device for given address: " + e.message);
});
+var adapter = tizen.bluetooth.getDefaultAdapter();
+
+function chatServiceSuccessCb(handler)
+{
+ console.log("Chat service " + handler.name + " with UUID " + handler.uuid + " is successfully registered!");
+ console.log("There is " + (handler.isConnected ? "a" : "no") + " device using this service");
+
+ handler.onconnect = function(socket)
+ {
+ console.log("Client is connected: " + socket.peer.name + "," + socket.peer.address);
+ socket.onmessage = function()
+ {
+ var data = socket.readData();
+ /* Handle message code goes here */
+ };
+
+ /* Expected close */
+ socket.onclose = function()
+ {
+ console.log("The socket is closed.");
+ };
+ };
+}
+
+function errorCb(e)
+{
+ console.log("Could not register service record, Error: " + e.message);
+}
+
+var CHAT_SERVICE_UUID = "5BCE9431-6C75-32AB-AFE0-2EC108A30860";
+adapter.registerRFCOMMServiceByUUID(CHAT_SERVICE_UUID, "Chat service", chatServiceSuccessCb, errorCb);
+
+
+
Code example:
+var adapter = tizen.bluetooth.getDefaultAdapter(); +var healthCapability = tizen.systeminfo.getCapability("http://tizen.org/feature/network.bluetooth.health"); + +if (healthCapability) +{ + var healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH"); + console.log("Bluetooth profile type is " + healthProfileHandler.profileType); +} +else +{ + console.log("Bluetooth Health Profile is not supported on this device."); +} ++
-For example, pulse oximeter is 4100 and blood pressure monitor is 4103. +For example, pulse oximeter is 4100 and blood pressure monitor is 4103. See example.
@@ -5788,7 +5907,7 @@ For example, pulse oximeter is 4100 and blood pressure monitor is 4103.
Since:
@@ -5815,6 +5934,30 @@ By default, this attribute is set to null.
Code example:
Since:
@@ -5986,7 +6129,7 @@ function stopSink()
Since:
@@ -5996,7 +6139,7 @@ function stopSink()
Since:
@@ -6012,6 +6155,28 @@ function stopSink()
Since:
+var adapter = tizen.bluetooth.getDefaultAdapter();
+var healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH");
+
+function healthRegisterSuccess(app)
+{
+ console.log("Registered application: " + app.name);
+ console.log("Data type used for communication is " + app.dataType);
+
+ app.onconnect = function(channel)
+ {
+ console.log("Health device is connected");
+ }
+}
+
+function healthRegisterError(e)
+{
+ console.log("Failed to register application: " + e.message);
+};
+
+healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError);
+
+
Code example:
+var adapter = tizen.bluetooth.getDefaultAdapter(); +var healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH"); + +function healthRegisterSuccess(app) +{ + app.onconnect = function(channel) + { + console.log("Health device " + (channel.isConnected ? "is" : "is not") + " connected to " + channel.peer.name + " remote device"); + console.log("Channel type is " + channel.channelType + " and health application name used for communication is " + channel.application.name); + } +} + +function healthRegisterError(e) +{ + console.log("Failed to register application: " + e.message); +}; + +healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError); ++
Code example:
var advertData = { - includeName: false, uuids: ["f236-41a4"], solicitationuuids: ["5857-4d3f"], - appearance: 192, includeTxPowerLevel: false + includeName: false, uuids: ["f236-41a4"], solicitationuuids: ["5857-4d3f"], + appearance: 192, includeTxPowerLevel: false }@@ -717,8 +716,8 @@ This represents the data to be advertised as well as the scan response data for
Code example:
var advertData = { - includeName: false, uuids: ["f236-41a4"], solicitationuuids: ["5857-4d3f"], - appearance: 192, includeTxPowerLevel: false + includeName: false, uuids: ["f236-41a4"], solicitationuuids: ["5857-4d3f"], + appearance: 192, includeTxPowerLevel: false } var advertise = new tizen.BluetoothLEAdvertiseData(advertData);@@ -964,11 +963,11 @@ Instead, use http://tizen.org/privilege/bluetooth.
Code example:
try { - var adapter = tizen.bluetooth.getDefaultAdapter(); + var adapter = tizen.bluetooth.getDefaultAdapter(); } catch (err) { - console.log(err.name + ": " + err.message); + console.log(err.name + ": " + err.message); }@@ -1024,11 +1023,11 @@ Instead, use http://tizen.org/privilege/bluetooth.
Code example:
try { - var adapter = tizen.bluetooth.getLEAdapter(); + var adapter = tizen.bluetooth.getLEAdapter(); } catch (err) { - console.log(err.name + ": " + err.message); + console.log(err.name + ": " + err.message); }@@ -1051,10 +1050,6 @@ catch (err) optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); - void setPowered(boolean state, - optional SuccessCallback? successCallback, - optional ErrorCallback? errorCallback) raises(WebAPIException); - void setChangeListener(BluetoothAdapterChangeCallback listener) raises(WebAPIException); void unsetChangeListener() raises(WebAPIException); @@ -1275,21 +1270,21 @@ var bt_always_on = tizen.systeminfo.getCapability("http://tizen.org/capability/n function changeName(newName) { - if (adapter.name != newName) - { - /* Initiate change name */ - adapter.setName(newName, function() - { - console.log("Adapter name changed to " + adapter.name); - }, function(e) - { - console.log("Failed to change name: " + e.message); - }); - } + if (adapter.name != newName) + { + /* Initiate change name */ + adapter.setName(newName, function() + { + console.log("Adapter name changed to " + adapter.name); + }, function(e) + { + console.log("Failed to change name: " + e.message); + }); + } } if (bt_always_on === false) { - changeName("myDevice"); + changeName("myDevice"); } @@ -1303,7 +1298,7 @@ if (bt_always_on === false) For most Bluetooth actions, the Bluetooth adapter must be powered on.
Deprecated. - Deprecated since 2.3. Instead, let the user turn on/off Bluetooth through the Settings application. See Managing Bluetooth Tutorial. + Deprecated since 2.3. Instead, let the user turn on/off Bluetooth through the Settings application. See Managing Bluetooth Tutorial.
void setPowered(boolean state, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
Code example:
var changeListener = { - onstatechanged: function(powered) - { - console.log("Power state is changed into: " + powered); - }, - onnamechanged: function(name) - { - console.log("Name is changed to: " + name); - }, - onvisibilitychanged: function(visible) - { - console.log("Visibility is changed into: " + visible); - } + onstatechanged: function(powered) + { + console.log("Power state is changed into: " + powered); + }, + onnamechanged: function(name) + { + console.log("Name is changed to: " + name); + }, + onvisibilitychanged: function(visible) + { + console.log("Visibility is changed into: " + visible); + } }; var adapter = tizen.bluetooth.getDefaultAdapter(); @@ -1509,20 +1504,20 @@ var adapter = tizen.bluetooth.getDefaultAdapter(); var changeListener = { - onstatechanged: function(powered) - { - console.log("Power state is changed into: " + powered); - if (!powered) - adapter.unsetChangeListener(); - }, - onnamechanged: function(name) - { - console.log("Name is changed to: " + name); - }, - onvisibilitychanged: function(visible) - { - console.log("Visibility is changed into: " + visible); - } + onstatechanged: function(powered) + { + console.log("Power state is changed into: " + powered); + if (!powered) + adapter.unsetChangeListener(); + }, + onnamechanged: function(name) + { + console.log("Name is changed to: " + name); + }, + onvisibilitychanged: function(visible) + { + console.log("Visibility is changed into: " + visible); + } }; adapter.setChangeListener(changeListener); @@ -1612,41 +1607,41 @@ var adapter = tizen.bluetooth.getDefaultAdapter(); function startDiscovery() { - var discoverDevicesSuccessCallback = - { - onstarted: function() - { - console.log("Device discovery started..."); - }, - ondevicefound: function(device) + var discoverDevicesSuccessCallback = + { + onstarted: function() + { + console.log("Device discovery started..."); + }, + ondevicefound: function(device) + { + console.log("Found device - name: " + device.name + ", Address: "+ device.address); + }, + ondevicedisappeared: function(address) + { + console.log("Device disappeared: " + address); + }, + onfinished: function(devices) + { + console.log("Found Devices"); + for (var i = 0; i < devices.length; i++) { - console.log("Found device - name: " + device.name + ", Address: " + device.address); - }, - ondevicedisappeared: function(address) - { - console.log("Device disappeared: " + address); - }, - onfinished: function(devices) - { - console.log("Found Devices"); - for (var i = 0; i < devices.length; i++) - { - console.log("Name: " + devices[i].name + ", Address: " + devices[i].address); - } - console.log("Total: " + devices.length); + console.log("Name: " + devices[i].name + ", Address: " + devices[i].address); } - }; - - /* Starts searching for nearby devices, for about 12 sec */ - adapter.discoverDevices(discoverDevicesSuccessCallback, function(e) - { - console.log("Failed to search devices: " + e.message + "(" + e.name + ")"); - }); + console.log("Total: " + devices.length); + } + }; + + /* Starts searching for nearby devices, for about 12 sec */ + adapter.discoverDevices(discoverDevicesSuccessCallback, function(e) + { + console.log("Failed to search devices: " + e.message + "(" + e.name + ")"); + }); } function onSetPoweredError(e) { - console.log("Could not turn on device, reason: " + e.message + "(" + e.name + ")"); + console.log("Could not turn on device, reason: " + e.message + "(" + e.name + ")"); } adapter.setPowered(true, startDiscovery, onSetPoweredError); @@ -1724,57 +1719,57 @@ var adapter = tizen.bluetooth.getDefaultAdapter(); /* Calls this method whenever user finds one of the device */ function cancelDiscovery() { - adapter.stopDiscovery(function() - { - console.log("Stop discovery success."); - }, function(e) - { - console.log("Error while stopDiscovery:" + e.message); - }); + adapter.stopDiscovery(function() + { + console.log("Stop discovery success."); + }, function(e) + { + console.log("Error while stopDiscovery:" + e.message); + }); } function startDiscovery() { - var discoverDevicesSuccessCallback = - { - onstarted: function() - { - console.log("Device discovery started..."); - }, - ondevicefound: function(device) - { - console.log("Found device - name: " + device.name + ", Address: " + device.address); - /* Shows the device to user to check if this is the device user is looking for */ - /* For example, add this to list view */ - - cancelDiscovery(); - }, - ondevicedisappeared: function(address) - { - console.log("Device disappeared: " + address); - /* Removes from list, as it is no longer valid */ - }, - onfinished: function(devices) + var discoverDevicesSuccessCallback = + { + onstarted: function() + { + console.log("Device discovery started..."); + }, + ondevicefound: function(device) + { + console.log("Found device - name: " + device.name + ", Address: "+ device.address); + /* Shows the device to user to check if this is the device user is looking for */ + /* For example, add this to list view */ + + cancelDiscovery(); + }, + ondevicedisappeared: function(address) + { + console.log("Device disappeared: " + address); + /* Removes from list, as it is no longer valid */ + }, + onfinished: function(devices) + { + console.log("Found Devices"); + for (var i = 0; i < devices.length; i++) { - console.log("Found Devices"); - for (var i = 0; i < devices.length; i++) - { - console.log("Name: " + devices[i].name + ", Address: " + devices[i].address); - } - console.log("Total: " + devices.length); + console.log("Name: " + devices[i].name + ", Address: " + devices[i].address); } - }; - - /* Starts searching for nearby devices, for about 12 sec */ - adapter.discoverDevices(discoverDevicesSuccessCallback, function(e) - { - console.log("Failed to search devices: " + e.message + "(" + e.name + ")"); - }); + console.log("Total: " + devices.length); + } + }; + + /* Starts searching for nearby devices, for about 12 sec */ + adapter.discoverDevices(discoverDevicesSuccessCallback, function(e) + { + console.log("Failed to search devices: " + e.message + "(" + e.name + ")"); + }); } function onSetPoweredError(e) { - console.log("Could not turn on device, reason: " + e.message + "(" + e.name + ")"); + console.log("Could not turn on device, reason: " + e.message + "(" + e.name + ")"); } adapter.setPowered(true, startDiscovery, onSetPoweredError); @@ -1860,22 +1855,22 @@ var adapter = tizen.bluetooth.getDefaultAdapter(); function onGotDevices(devices) { - console.log("Devices"); - for (var i = 0; i < devices.length; i++) - { - console.log(" Name: " + devices[i].name + ", Address: " + devices[i].address); - } - console.log("Total: " + devices.length); + console.log("Devices"); + for (var i = 0; i < devices.length; i++) + { + console.log(" Name: " + devices[i].name + ", Address: " + devices[i].address); + } + console.log("Total: " + devices.length); } function onError(e) { - console.log("Error: " + e.message); + console.log("Error: " + e.message); } function onBluetoothsetPowered() { - adapter.getKnownDevices(onGotDevices, onError); + adapter.getKnownDevices(onGotDevices, onError); } /* Turns on Bluetooth */ @@ -1959,15 +1954,15 @@ Instead, use http://tizen.org/privilege/bluetooth.@@ -2463,7 +2462,7 @@ Instead, use http://tizen.org/privilege/bluetooth. var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - console.log("[Found device] address: " + device.address); + console.log("[Found device] address: " + device.address); }); @@ -2510,11 +2509,11 @@ Instead, use http://tizen.org/privilege/bluetooth. var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - if (device.address == "11:22:33:44:55:66") - { - console.log("Found device: " + device.name); - adapter.stopScan(); - } + if (device.address == "11:22:33:44:55:66") + { + console.log("Found device: " + device.name); + adapter.stopScan(); + } }); @@ -2612,11 +2611,11 @@ var battery_svc_uuid_16 = "180f"; /* Service UUID, 16-bit UUID is supported (e.g var heart_rate_svc_uuid_16 = "180d"; /* Service solicitation UUID, 16-bit UUID is supported (e.g. 180d) */ var advertiseOptions = { - includeName: true, /* Whether the device name should be included */ - includeTxPowerLevel: true, /* Whether the transmission power level should be included */ - appearance: 192, /* External appearance of device, 192 - Generic Watch */ - uuids: [battery_svc_uuid_16], - solicitationuuids: [heart_rate_svc_uuid_16] + includeName: true, /* Whether the device name should be included */ + includeTxPowerLevel: true, /* Whether the transmission power level should be included */ + appearance: 192, /* External appearance of device, 192 - Generic Watch */ + uuids: [battery_svc_uuid_16], + solicitationuuids: [heart_rate_svc_uuid_16] }; var advertiseData = new tizen.BluetoothLEAdvertiseData(advertiseOptions); @@ -2624,10 +2623,10 @@ var connectable = true; adapter.startAdvertise(advertiseData, "ADVERTISE", function onstate(state) { - console.log("Advertiser state: " + state); + console.log("Advertiser state: " + state); }, function(e) { - console.log("Failed to startAdvertise: " + e.message); + console.log("Failed to startAdvertise: " + e.message); }, "LOW_LATENCY", connectable); @@ -2676,18 +2675,18 @@ var battery_svc_uuid_16 = "180f"; /* Service UUID, 16-bit UUID is supported (e.g var heart_rate_svc_uuid_16 = "180d"; /* Service solicitation UUID, 16-bit UUID is supported (e.g. 180d) */ var advertiseOptions = { - includeName: true, /* Whether the device name should be included */ - includeTxPowerLevel: true, /* Whether the transmission power level should be included */ - appearance: 192, /* External appearance of device, 192 - Generic Watch */ - uuids: [battery_svc_uuid_16], - solicitationuuids: [heart_rate_svc_uuid_16] + includeName: true, /* Whether the device name should be included */ + includeTxPowerLevel: true, /* Whether the transmission power level should be included */ + appearance: 192, /* External appearance of device, 192 - Generic Watch */ + uuids: [battery_svc_uuid_16], + solicitationuuids: [heart_rate_svc_uuid_16] }; var advertiseData = new tizen.BluetoothLEAdvertiseData(advertiseOptions); adapter.startAdvertise(advertiseData, "ADVERTISE", function onstate(state) { - console.log("Advertiser state: " + state); + console.log("Advertiser state: " + state); }); adapter.stopAdvertise(); @@ -2714,16 +2713,16 @@ adapter.stopAdvertise();Code example:
function gotDeviceInfo(device) { - console.log("Device Name: " + device.name); - console.log("Device Address: " + device.address); - console.log("Device Class: " + device.deviceClass.major); - console.log("Is Bonded: " + (device.isBonded ? "Yes" : "No")); + console.log("Device Name: " + device.name); + console.log("Device Address: " + device.address); + console.log("Device Class: " + device.deviceClass.major); + console.log("Is Bonded: " + (device.isBonded ? "Yes" : "No")); } function onError(e) { - console.log("Could not get device info:" + e.message); + console.log("Could not get device info:" + e.message); } var adapter = tizen.bluetooth.getDefaultAdapter(); @@ -2049,14 +2044,14 @@ Instead, use http://tizen.org/privilege/bluetooth.@@ -2349,11 +2348,11 @@ var healthCapability = tizen.systeminfo.getCapability("http://tizen.org/feature/ if (healthCapability) { - healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH"); + healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH"); } else { - console.log("Bluetooth Health Profile is not supported on this device."); + console.log("Bluetooth Health Profile is not supported on this device."); }Code example:
function onBondingSuccess(device) { - console.log("Device Name:" + device.name); - console.log("Device Address:" + device.address); - console.log("Device Service UUIDs:" + device.uuids.join("\n")); + console.log("Device Name:" + device.name); + console.log("Device Address:" + device.address); + console.log("Device Service UUIDs:" + device.uuids.join("\n")); } function onError(e) { - console.log("Could not create bonding, reason:" + e.message); + console.log("Could not create bonding, reason:" + e.message); } var adapter = tizen.bluetooth.getDefaultAdapter(); @@ -2140,23 +2135,23 @@ var adapter = tizen.bluetooth.getDefaultAdapter(); function gotDevice(device) { - if (device.isBonded) - { - /* Initiates destroying bonding */ - adapter.destroyBonding(device.address, function() - { - console.log("Succeeded to destroy the bond success with:" + device.address); - }, function(e) - { - console.log("Failed to destroy the bond with " + device.address + ", reason: " + e.message); - }); - } + if (device.isBonded) + { + /* Initiates destroying bonding */ + adapter.destroyBonding(device.address, function() + { + console.log("Succeeded to destroy the bond success with:" + device.address); + }, function(e) + { + console.log("Failed to destroy the bond with " + device.address + ", reason: " + e.message); + }); + } } var deviceAddress = "35:F4:59:D1:7A:03"; adapter.getDevice(deviceAddress, gotDevice, function(e) { - console.log("Failed to get device info for " + deviceAddress + ", reason: " + e.message); + console.log("Failed to get device info for " + deviceAddress + ", reason: " + e.message); });@@ -2253,47 +2248,51 @@ var serviceSocket = null; function chatServiceSuccessCb(recordHandler) { - console.log("Chat service registration succeeds!"); - chatServiceHandler = recordHandler; - recordHandler.onconnect = function(socket) - { - console.log("Client connected: " + socket.peer.name + "," + socket.peer.address); - serviceSocket = socket; - /* Messages received from remote device */ - socket.onmessage = function() - { - var data = socket.readData(); - /* Handles message code goes here */ - }; + console.log("Chat service registration succeeds!"); + chatServiceHandler = recordHandler; + recordHandler.onconnect = function(socket) + { + console.log("Client connected: " + socket.peer.name + "," + socket.peer.address); + serviceSocket = socket; + /* Messages received from remote device */ + socket.onmessage = function() + { + var data = socket.readData(); + /* Handles message code goes here */ + }; - socket.onclose = function() - { - console.log('The socket is closed.'); - serviceSocket = null; - }; - }; + socket.onclose = function() + { + console.log("The socket is closed."); + serviceSocket = null; + }; + }; }; function publishChatService() { - var CHAT_SERVICE_UUID = "5BCE9431-6C75-32AB-AFE0-2EC108A30860"; - adapter.registerRFCOMMServiceByUUID(CHAT_SERVICE_UUID, "Chat service", chatServiceSuccessCb, - /* Error handler: function(e) {console.log("Could not register service record, Error: " + e.message);} */); + var CHAT_SERVICE_UUID = "5BCE9431-6C75-32AB-AFE0-2EC108A30860"; + adapter.registerRFCOMMServiceByUUID(CHAT_SERVICE_UUID, "Chat service", chatServiceSuccessCb, + /* Error handler */ + function(e) + { + console.log( "Could not register service record, Error: " + e.message); + }); } function unregisterChatService() { - if (chatServiceHandler != null) - { - chatServiceHandler.unregister(function() - { - console.log("Chat service is unregistered"); - chatServiceHandler = null; - }, function(e) - { - console.log("Failed to unregister service: " + e.message); - }); - } + if (chatServiceHandler != null) + { + chatServiceHandler.unregister(function() + { + console.log("Chat service is unregistered"); + chatServiceHandler = null; + }, function(e) + { + console.log("Failed to unregister service: " + e.message); + }); + } }
Code example:
function onconnected(device) { - console.log("Connected to device"); - var service = device.getService(device.uuids[0]); - console.log("Service got"); + console.log("Connected to device"); + var service = device.getService(device.uuids[0]); + console.log("Service got"); } var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - console.log("[Found device] address: " + device.address); - device.connect(onconnected.bind(null, device), onerror); + console.log("[Found device] address: " + device.address); + device.connect(onconnected.bind(null, device), onerror); });@@ -2761,7 +2760,7 @@ console.log("Service UUID " + service.uuid); var service = device.getService(device.uuids[0]); for (var i = 0; i service.services.length; ++i) { - console.log("Subservices UUID " + service.services[i].uuid); + console.log("Subservices UUID " + service.services[i].uuid); } @@ -2781,7 +2780,7 @@ for (var i = 0; i service.services.length; ++i) var service = device.getService(device.uuids[0]); for (var i = 0; i service.characteristics.length; ++i) { - console.log("Subservices UUID " + service.characteristics[i].isWritable); + console.log("Subservices UUID " + service.characteristics[i].isWritable); } @@ -2982,35 +2981,35 @@ Instead, use http://tizen.org/privilege/bluetooth.
Code example:
function onerror(e) { - console.log("Failed to connect to device: " + e.message); + console.log("Failed to connect to device: " + e.message); } function proccessDevice(device) { - device.connect(onConnected, onerror); - function onConnected() - { - var service = device.getService(device.uuids[0]); - if (service.characteristics.length > 0) + device.connect(onConnected, onerror); + function onConnected() + { + var service = device.getService(device.uuids[0]); + if (service.characteristics.length > 0) + { + var characteristic = service.characteristics[0]; + characteristic.readValue(function(val) { - var characteristic = service.characteristics[0]; - characteristic.readValue(function(val) - { - console.log("Value read: " + val); - device.disconnect(); - }); - } - } + console.log("Value read: " + val); + device.disconnect(); + }); + } + } } var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - if (device.address == "11:22:33:44:55:66") - { - console.log("Found device: " + device.name); - proccessDevice(device); - } + if (device.address == "11:22:33:44:55:66") + { + console.log("Found device: " + device.name); + proccessDevice(device); + } });@@ -3085,39 +3084,39 @@ Instead, use http://tizen.org/privilege/bluetooth.
Code example:
function onerror(e) { - console.log("Failed to connect to device: " + e.message); + console.log("Failed to connect to device: " + e.message); } function proccessDevice(device) { - device.connect(onConnected, onerror); - function onConnected() - { - var service = device.getService(device.uuids[0]); - if (service.characteristics.length > 0) + device.connect(onConnected, onerror); + function onConnected() + { + var service = device.getService(device.uuids[0]); + if (service.characteristics.length > 0) + { + var characteristic = service.characteristics[0]; + var data = new Array(1, 2, 3, 4, 5, 6); + characteristic.writeValue(data, function() { - var characteristic = service.characteristics[0]; - var data = new Array(1, 2, 3, 4, 5, 6); - characteristic.writeValue(data, function() - { - console.log("Value written"); - device.disconnect(); - }, function(e) - { - console.log("Failed to write: " + e.message); - }); - } - } + console.log("Value written"); + device.disconnect(); + }, function(e) + { + console.log("Failed to write: " + e.message); + }); + } + } } var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - if (device.address == "11:22:33:44:55:66") - { - console.log("Found device: " + device.name); - proccessDevice(device); - } + if (device.address == "11:22:33:44:55:66") + { + console.log("Found device: " + device.name); + proccessDevice(device); + } });@@ -3171,35 +3170,34 @@ Instead, use http://tizen.org/privilege/bluetooth.
Code example:
function proccessDevice(device) { - function onConnected() - { - var service = device.getService("5BCE9431-6C75-32AB-AFE0-2EC108A30860"); - if (service.characteristics.length > 0) - { - var characteristic = service.characteristics[0]; - var watchID; - - watchID = characteristic.addValueChangeListener(function(value) - { - console.log("Characteristic value changed: " + value); - characteristic.removeValueChangeListener(watchID); - device.disconnect(); - }); - } - } + function onConnected() + { + var service = device.getService("5BCE9431-6C75-32AB-AFE0-2EC108A30860"); + if (service.characteristics.length > 0) + { + var characteristic = service.characteristics[0]; + var watchID; - device.connect(onConnected); + watchID = characteristic.addValueChangeListener(function(value) + { + console.log("Characteristic value changed: " + value); + characteristic.removeValueChangeListener(watchID); + device.disconnect(); + }); + } + } + device.connect(onConnected); } var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - if (device.address == "11:22:33:44:55:66") - { - console.log("Found device: " + device.name); - adapter.stopScan(); - proccessDevice(device); - } + if (device.address == "11:22:33:44:55:66") + { + console.log("Found device: " + device.name); + adapter.stopScan(); + proccessDevice(device); + } });@@ -3317,36 +3315,36 @@ Instead, use http://tizen.org/privilege/bluetooth.
Code example:
function onerror(e) { - console.log("Failed to connect to device: " + e.message); + console.log("Failed to connect to device: " + e.message); } function proccessDevice(device) { - device.connect(onConnected, onerror); - function onConnected() - { - var service = device.getService(device.uuids[0]); - if (service.characteristics.length > 0) + device.connect(onConnected, onerror); + function onConnected() + { + var service = device.getService(device.uuids[0]); + if (service.characteristics.length > 0) + { + var characteristic = service.characteristics[0]; + var descriptor = characteristic.descriptors[0]; + descriptor.readValue(function(val) { - var characteristic = service.characteristics[0]; - var descriptor = characteristic.descriptors[0]; - descriptor.readValue(function(val) - { - console.log("Value read: " + val); - device.disconnect(); - }); - } - } + console.log("Value read: " + val); + device.disconnect(); + }); + } + } } var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - if (device.address == "11:22:33:44:55:66") - { - console.log("Found device: " + device.name); - proccessDevice(device); - } + if (device.address == "11:22:33:44:55:66") + { + console.log("Found device: " + device.name); + proccessDevice(device); + } });@@ -3421,40 +3419,40 @@ Instead, use http://tizen.org/privilege/bluetooth.
Code example:
function onerror(e) { - console.log("Failed to connect to device: " + e.message); + console.log("Failed to connect to device: " + e.message); } function proccessDevice(device) { - device.connect(onConnected, onerror); - function onConnected() - { - var service = device.getService(device.uuids[0]); - if (service.characteristics.length > 0) + device.connect(onConnected, onerror); + function onConnected() + { + var service = device.getService(device.uuids[0]); + if (service.characteristics.length > 0) + { + var characteristic = service.characteristics[0]; + var data = new Array(1, 2, 3, 4, 5, 6); + var descriptor = characteristic.descriptors[0]; + descriptor.writeValue(data, function() { - var characteristic = service.characteristics[0]; - var data = new Array(1, 2, 3, 4, 5, 6); - var descriptor = characteristic.descriptors[0]; - descriptor.writeValue(data, function() - { - console.log("Value written"); - device.disconnect(); - }, function(e) - { - console.log("Failed to write: " + e.message); - }); - } - } + console.log("Value written"); + device.disconnect(); + }, function(e) + { + console.log("Failed to write: " + e.message); + }); + } + } } var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - if (device.address == "11:22:33:44:55:66") - { - console.log("Found device: " + device.name); - proccessDevice(device); - } + if (device.address == "11:22:33:44:55:66") + { + console.log("Found device: " + device.name); + proccessDevice(device); + } });@@ -3710,7 +3708,7 @@ A BluetoothDevice object can be retrieved using one of the following AP var adapter = tizen.bluetooth.getDefaultAdapter(); adapter.getDevice("11:22:33:44:55:66", function(device) { - console.log("Device Name: " + device.name); + console.log("Device Name: " + device.name); }); @@ -3729,7 +3727,7 @@ adapter.getDevice("11:22:33:44:55:66", function(device) var adapter = tizen.bluetooth.getDefaultAdapter(); adapter.getDevice("11:22:33:44:55:66", function(device) { - console.log("Device Address: " + device.address); + console.log("Device Address: " + device.address); }); @@ -3748,7 +3746,7 @@ adapter.getDevice("11:22:33:44:55:66", function(device) var adapter = tizen.bluetooth.getDefaultAdapter(); adapter.getDevice("11:22:33:44:55:66", function(device) { - console.log("Device Major Class: " + device.deviceClass.major); + console.log("Device Major Class: " + device.deviceClass.major); }); @@ -3767,7 +3765,7 @@ adapter.getDevice("11:22:33:44:55:66", function(device) var adapter = tizen.bluetooth.getDefaultAdapter(); adapter.getDevice("11:22:33:44:55:66", function(device) { - console.log("Is bonded: " + (device.isBonded ? "Yes" : "No")); + console.log("Is bonded: " + (device.isBonded ? "Yes" : "No")); }); @@ -3786,7 +3784,7 @@ adapter.getDevice("11:22:33:44:55:66", function(device) var adapter = tizen.bluetooth.getDefaultAdapter(); adapter.getDevice("11:22:33:44:55:66", function(device) { - console.log("Is trusted: " + (device.isTrusted ? "Yes" : "No")); + console.log("Is trusted: " + (device.isTrusted ? "Yes" : "No")); }); @@ -3805,7 +3803,7 @@ adapter.getDevice("11:22:33:44:55:66", function(device) var adapter = tizen.bluetooth.getDefaultAdapter(); adapter.getDevice("11:22:33:44:55:66", function(device) { - console.log("Is connected: " + (device.isConnected ? "Yes" : "No")); + console.log("Is connected: " + (device.isConnected ? "Yes" : "No")); }); @@ -3826,24 +3824,24 @@ var adapter = tizen.bluetooth.getDefaultAdapter(); var CHAT_SERVICE_UUID = "5BCE9431-6C75-32AB-AFE0-2EC108A30860"; adapter.getDevice("11:22:33:44:55:66", function(device) { - var uuids = device.uuids; - var services = ""; - for (var i = 0; i < uuids.length; i++) - { - services += uuids[i] + "\n"; - } - console.log("Services found: " + services); - if (uuids.indexOf(CHAT_SERVICE_UUID) != -1) - { - /* Connects to service */ - device.connectToServiceByUUID(CHAT_SERVICE_UUID, function(socket) - { - /* Connected to service, handle socket */ - }, function(e) - { - console.log("Could not connect to chat service !!!. Error: " + e.message); - }); - } + var uuids = device.uuids; + var services = ""; + for (var i = 0; i < uuids.length; i++) + { + services += uuids[i] + "\n"; + } + console.log("Services found: " + services); + if (uuids.indexOf(CHAT_SERVICE_UUID) != -1) + { + /* Connects to service */ + device.connectToServiceByUUID(CHAT_SERVICE_UUID, function(socket) + { + /* Connected to service, handle socket */ + }, function(e) + { + console.log("Could not connect to chat service !!!. Error: " + e.message); + }); + } }); @@ -3931,57 +3929,57 @@ var clientSocket = null; /* Calls a method that is invoked when user wants to send a message to a remote device */ function sendMessage(msg) { - /* Validates socket state, if everything is ok */ - if (clientSocket != null && clientSocket.state == "OPEN") - { - /* Sends the message */ - clientSocket.writeData(msg); - } + /* Validates socket state, if everything is ok */ + if (clientSocket != null && clientSocket.state == "OPEN") + { + /* Sends the message */ + clientSocket.writeData(msg); + } } /* Calls a method that is invoked when a socket is open */ function onSocketConnected(socket) { - clientSocket = socket; - console.log("Opening a socket successfully!!!"); - socket.onmessage = function() - { - var data = socket.readData(); - var recvmsg = ""; - for (var i = 0; i < data.length; i++) - { - recvmsg += String.fromCharCode(data[i]); - } - console.log("server msg >> " + recvmsg); - }; - - socket.onclose = function() - { - console.log("socket disconnected."); - }; + clientSocket = socket; + console.log("Opening a socket successfully!!!"); + socket.onmessage = function() + { + var data = socket.readData(); + var recvmsg = ""; + for (var i = 0; i < data.length; i++) + { + recvmsg += String.fromCharCode(data[i]); + } + console.log("server msg >> " + recvmsg); + }; + + socket.onclose = function() + { + console.log("socket disconnected."); + }; } function onDeviceReady(device) { - /* Validates device and service uuid */ - if (device.uuids.indexOf("5BCE9431-6C75-32AB-AFE0-2EC108A30860") != -1) - { - /* Opens socket */ - device.connectToServiceByUUID("5BCE9431-6C75-32AB-AFE0-2EC108A30860", onSocketConnected, function(e) - { - console.log("Error connecting to service. Reason: " + e.message); - }); - } - else - { - console.log("Chat service is not supported by this device"); - } + /* Validates device and service uuid */ + if (device.uuids.indexOf("5BCE9431-6C75-32AB-AFE0-2EC108A30860") != -1) + { + /* Opens socket */ + device.connectToServiceByUUID("5BCE9431-6C75-32AB-AFE0-2EC108A30860", onSocketConnected, function(e) + { + console.log("Error connecting to service. Reason: " + e.message); + }); + } + else + { + console.log("Chat service is not supported by this device"); + } } function onSetPowered() { - /* Gets the BluetoothDevice object */ - adapter.getDevice("35:F4:59:D1:7A:03", onDeviceReady, function(e) {console.log("Error: " + e.message);}); + /* Gets the BluetoothDevice object */ + adapter.getDevice("35:F4:59:D1:7A:03", onDeviceReady, function(e) {console.log("Error: " + e.message); }); } adapter.setPowered(true, onSetPowered, function(e) {console.log("Could not turn on Bluetooth adapter. reason: " + e.message); }); @@ -4050,7 +4048,7 @@ A BluetoothLEDevice object can be retrieved by using one of the followi var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - console.log("Found device: " + device.address); + console.log("Found device: " + device.address); }); @@ -4069,7 +4067,7 @@ adapter.startScan(function onsuccess(device) var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - console.log("Found device: " + device.name); + console.log("Found device: " + device.name); }); @@ -4088,7 +4086,7 @@ adapter.startScan(function onsuccess(device) var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - console.log("Found device: " + device.txpowerlevel); + console.log("Found device: " + device.txpowerlevel); }); @@ -4107,7 +4105,7 @@ adapter.startScan(function onsuccess(device) var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - console.log("Found device: " + device.appearance); + console.log("Found device: " + device.appearance); }); @@ -4127,13 +4125,13 @@ adapter.startScan(function onsuccess(device) var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - var uuids = device.uuids; - var services = ""; - for (var i = 0; i < uuids.length; i++) - { - services += uuids[i] + "\n"; - } - console.log("Service found: " + services); + var uuids = device.uuids; + var services = ""; + for (var i = 0; i < uuids.length; i++) + { + services += uuids[i] + "\n"; + } + console.log("Service found: " + services); }); @@ -4153,13 +4151,13 @@ adapter.startScan(function onsuccess(device) var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - var uuids = device.solicitationuuids; - var services = ""; - for (var i = 0; i < uuids.length; i++) - { - services += uuids[i] + "\n"; - } - console.log("Service solicitations found: " + services); + var uuids = device.solicitationuuids; + var services = ""; + for (var i = 0; i < uuids.length; i++) + { + services += uuids[i] + "\n"; + } + console.log("Service solicitations found: " + services); }); @@ -4179,13 +4177,13 @@ adapter.startScan(function onsuccess(device) var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - var serviceData = device.serviceData; - var data = ""; - for (var i = 0; i < serviceData.length; i++) - { - data += serviceData[i].id + serviceData[i].data + "\n"; - } - console.log("Service data found: " + data); + var serviceData = device.serviceData; + var data = ""; + for (var i = 0; i < serviceData.length; i++) + { + data += serviceData[i].id + serviceData[i].data + "\n"; + } + console.log("Service data found: " + data); }); @@ -4204,9 +4202,9 @@ adapter.startScan(function onsuccess(device) var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - var manufacturerData = device.manufacturerData; - console.log("Manufacture id: " + manufacturerData.id); - console.log("Manufacture data: " + manufacturerData.data); + var manufacturerData = device.manufacturerData; + console.log("Manufacture id: " + manufacturerData.id); + console.log("Manufacture data: " + manufacturerData.data); }); @@ -4230,8 +4228,8 @@ The signal strength depends on distance (between the device and the beacon) and var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - console.log("Found device: " + device.name); - console.log("RSSI: " + device.rssi); + console.log("Found device: " + device.name); + console.log("RSSI: " + device.rssi); }); @@ -4312,21 +4310,21 @@ Instead, use http://tizen.org/privilege/bluetooth.
Code example:
function onerror(e) { - console.log("Failed to connect to device: " + e.message); + console.log("Failed to connect to device: " + e.message); } function onconnected() { - console.log("Connected to device"); + console.log("Connected to device"); } var adapter = tizen.bluetooth.getLEAdapter(); adapter.startScan(function onsuccess(device) { - if (device.address == "11:22:33:44:55:66") - { - console.log("Found device: " + device.name); - device.connect(onconnected, onerror); + if (device.address == "11:22:33:44:55:66") + { + console.log("Found device: " + device.name); + device.connect(onconnected, onerror); } });@@ -4398,27 +4396,27 @@ Instead, use http://tizen.org/privilege/bluetooth.
Code example:
function onerror(e) { - console.log("Error occurred: " + e.message); + console.log("Error occurred: " + e.message); } function onDeviceFound(device) { - function ondisconnect() - { - console.log("Disconnected"); - } - - function onconnected() - { - console.log("Connected to device"); - device.disconnect(ondisconnect, onerror); - } - - if (device.address == "11:22:33:44:55:66") - { - console.log("Found device: " + device.name); - device.connect(onconnected, onerror); - } + function ondisconnect() + { + console.log("Disconnected"); + } + + function onconnected() + { + console.log("Connected to device"); + device.disconnect(ondisconnect, onerror); + } + + if (device.address == "11:22:33:44:55:66") + { + console.log("Found device: " + device.name); + device.connect(onconnected, onerror); + } } var adapter = tizen.bluetooth.getLEAdapter(); @@ -4482,23 +4480,23 @@ Instead, use http://tizen.org/privilege/bluetooth.Code example:
function onconnected(device) { - console.log("Connected to device"); - var service = device.getService(device.uuids[0]); - console.log("Service got"); + console.log("Connected to device"); + var service = device.getService(device.uuids[0]); + console.log("Service got"); } function onerror(e) { - console.log("Error occurred: " + e.message); + console.log("Error occurred: " + e.message); } function onDeviceFound(device) { - if (device.address == "11:22:33:44:55:66") - { - console.log("Found device: " + device.name); - device.connect(onconnected.bind(null, device), onerror); - } + if (device.address == "11:22:33:44:55:66") + { + console.log("Found device: " + device.name); + device.connect(onconnected.bind(null, device), onerror); + } } var adapter = tizen.bluetooth.getLEAdapter(); @@ -4545,27 +4543,27 @@ adapter.startScan(onDeviceFound, onerror);@@ -5396,7 +5394,8 @@ adapter.getDevice("12:34:56:78:9A:BC", function(device)Code example:
-/* Below variable should represent valid address of discoverable bluetooth low energy device */ +/*Below variable should represent valid address of discoverable bluetooth low energy device */ var remoteAddress = "11:22:33:44:55:66"; function onconnected(device) { - console.log("Connected to device"); - var services = device.getServiceAllUuids(); - console.log("Services length " + services.length); + console.log("Connected to device"); + var services = device.getServiceAllUuids(); + console.log("Services length " + services.length); } function onerror(e) { - console.log("Error occurred: " + e.message); + console.log("Error occurred: " + e.message); } function onDeviceFound(device) { - if (device.address == remoteAddress) - { - device.connect(onconnected.bind(null, device), onerror); - } + if (device.address == remoteAddress) + { + device.connect(onconnected.bind(null, device), onerror); + } } var adapter = tizen.bluetooth.getLEAdapter(); @@ -4615,29 +4613,29 @@ adapter.startScan(onDeviceFound, onerror);Code example:
function onerror(e) { - console.log("Error occurred: " + e.message); + console.log("Error occurred: " + e.message); } function onDeviceFound(device) { - var onConnectionStateChange = - { - onconnected: function(device) - { - console.log("Device " + device.name + " connected"); - }, - ondisconnected: function(device) - { - console.log("Device " + device.name + " disconnected"); - } - } - - if (device.address === "11:22:33:44:55:66") - { - console.log("Found device: " + device.name); - device.addConnectStateChangeListener(onConnectionStateChange); - device.connect(); - } + var onConnectionStateChange = + { + onconnected: function(device) + { + console.log("Device " + device.name + " connected"); + }, + ondisconnected: function(device) + { + console.log("Device " + device.name + " disconnected"); + } + } + + if (device.address === "11:22:33:44:55:66") + { + console.log("Found device: " + device.name); + device.addConnectStateChangeListener(onConnectionStateChange); + device.connect(); + } } var adapter = tizen.bluetooth.getLEAdapter(); @@ -4671,30 +4669,30 @@ adapter.startScan(onDeviceFound, onerror);Code example:
function onerror(e) { - console.log("Error occurred: " + e.message); + console.log("Error occurred: " + e.message); } function onDeviceFound(device) { - var onConnectionStateChange = - { - onconnected: function(device) - { - console.log("Device " + device.name + " connected"); - }, - ondisconnected: function(device) - { - console.log("Device " + device.name + " disconnected"); - device.removeConnectStateChangeListener(listenerID); - } - } - - if (device.address === "11:22:33:44:55:66") - { - console.log("Found device: " + device.name); - listenerID = device.addConnectStateChangeListener(onConnectionStateChange); - device.connect(); - } + var onConnectionStateChange = + { + onconnected: function(device) + { + console.log("Device " + device.name + " connected"); + }, + ondisconnected: function(device) + { + console.log("Device " + device.name + " disconnected"); + device.removeConnectStateChangeListener(listenerID); + } + } + + if (device.address === "11:22:33:44:55:66") + { + console.log("Found device: " + device.name); + listenerID = device.addConnectStateChangeListener(onConnectionStateChange); + device.connect(); + } } var adapter = tizen.bluetooth.getLEAdapter(); @@ -4865,46 +4863,46 @@ var adapter = tizen.bluetooth.getDefaultAdapter(); function onSocketConnected(socket) { - console.log("Opened connection to remote device"); - socket.onmessage = function() - { - console.log("Message received: " + socket.readData()); - }; - - socket.onclose = function() - { - console.log("Socket closed with " + socket.peer.name); - }; - - /* Sends data to peer */ - var textmsg = "Test"; - var sendtextmsg = new Array(); - for (var i = 0; i < textmsg.length; i++) - { - sendtextmsg[i] = textmsg.charCodeAt(i); - } - socket.writeData(sendtextmsg); + console.log("Opened connection to remote device"); + socket.onmessage = function() + { + console.log("Message received: " + socket.readData()); + }; + + socket.onclose = function() + { + console.log("Socket closed with " + socket.peer.name); + }; + + /* Sends data to peer */ + var textmsg = "Test"; + var sendtextmsg = new Array(); + for (var i = 0; i < textmsg.length; i++) + { + sendtextmsg[i] = textmsg.charCodeAt(i); + } + socket.writeData(sendtextmsg); } function onSocketError(e) { - console.log("Error connecting to service. Reason: " + e.message); + console.log("Error connecting to service. Reason: " + e.message); } function onDeviceReady(device) { - /* Validates device and service uuid */ - if (device.uuids.indexOf("5BCE9431-6C75-32AB-AFE0-2EC108A30860") != -1) - { - /* Opens socket */ - device.connectToServiceByUUID("5BCE9431-6C75-32AB-AFE0-2EC108A30860", onSocketConnected, onSocketError); - } + /* Validates device and service uuid */ + if (device.uuids.indexOf("5BCE9431-6C75-32AB-AFE0-2EC108A30860") != -1) + { + /* Opens socket */ + device.connectToServiceByUUID("5BCE9431-6C75-32AB-AFE0-2EC108A30860", onSocketConnected, onSocketError); + } } function onSetPowered() { - /* Gets the BluetoothDevice object */ - adapter.getDevice("35:F4:59:D1:7A:03", onDeviceReady, function(e) {console.log("Error: " + e.message);}); + /* Gets the BluetoothDevice object */ + adapter.getDevice("35:F4:59:D1:7A:03", onDeviceReady, function(e) {console.log("Error: " + e.message);}); } adapter.setPowered(true, onSetPowered, function(e) {console.log("Could not turn on Bluetooth adapter. reason: " + e.message);}); @@ -4963,41 +4961,41 @@ var adapter = tizen.bluetooth.getDefaultAdapter(); function onError(e) { - console.log("Error connecting to service. Reason: " + e.message); + console.log("Error connecting to service. Reason: " + e.message); } function onSocketConnected(socket) { - console.log("Opening socket success!!!"); + console.log("Opening socket success!!!"); - socket.onmessage = function() - { - /* Gets a message from peer, reads it */ - var data = socket.readData(); + socket.onmessage = function() + { + /* Gets a message from peer, reads it */ + var data = socket.readData(); - /* Code to evaluate message goes here */ - }; + /* Code to evaluate message goes here */ + }; - socket.onclose = function() - { - console.log("Socket closed with " + socket.peer.name); - }; + socket.onclose = function() + { + console.log("Socket closed with " + socket.peer.name); + }; } function onDeviceReady(device) { - /* Validates device and service uuid */ - if (device.uuids.indexOf("5BCE9431-6C75-32AB-AFE0-2EC108A30860") != -1) - { - /* Opens socket */ - device.connectToServiceByUUID("5BCE9431-6C75-32AB-AFE0-2EC108A30860", onSocketConnected, onError); - } + /* Validates device and service uuid */ + if (device.uuids.indexOf("5BCE9431-6C75-32AB-AFE0-2EC108A30860") != -1) + { + /* Opens socket */ + device.connectToServiceByUUID("5BCE9431-6C75-32AB-AFE0-2EC108A30860", onSocketConnected, onError); + } } function onSetPowered() { - /* Gets the BluetoothDevice object */ - adapter.getDevice("35:F4:59:D1:7A:03", onDeviceReady, function(e) {console.log("Error: " + e.message);}); + /* Gets the BluetoothDevice object */ + adapter.getDevice("35:F4:59:D1:7A:03", onDeviceReady, function(e) {console.log("Error: " + e.message);}); } adapter.setPowered(true, onSetPowered, function(e) {console.log("Could not turn on Bluetooth adapter. reason: " + e.message);}); @@ -5060,7 +5058,7 @@ Instead, use http://tizen.org/privilege/bluetooth. readonly attribute octet minor; - readonly attribute unsigned short [] services ; + readonly attribute unsigned short [] services; boolean hasService(unsigned short service) raises(WebAPIException); };@@ -5111,22 +5109,22 @@ var adapter = tizen.bluetooth.getDefaultAdapter(); function evaluateDevice(address) { - adapter.getDevice(address, function(device) - { - if (device.deviceClass.major == tizen.bluetooth.deviceMajor.COMPUTER) - { - /* Shows computer icon for this device */ - console.log("Device is computer"); - } - else if (device.deviceClass.major == tizen.bluetooth.deviceMajor.PHONE) - { - /* Shows phone icon */ - console.log("Device is a Phone"); - } - }, function(e) - { - console.log("Couldn't get any device with the given address: " + e.message); - }); + adapter.getDevice(address, function(device) + { + if (device.deviceClass.major == tizen.bluetooth.deviceMajor.COMPUTER) + { + /* Shows computer icon for this device */ + console.log("Device is computer"); + } + else if (device.deviceClass.major == tizen.bluetooth.deviceMajor.PHONE) + { + /* Shows phone icon */ + console.log("Device is a Phone"); + } + }, function(e) + { + console.log("Couldn't get any device with the given address: " + e.message); + }); } evaluateDevice("11:22:33:44:55:66"); @@ -5223,13 +5221,13 @@ Instead, use http://tizen.org/privilege/bluetooth. var adapter = tizen.bluetooth.getDefaultAdapter(); adapter.getDevice("12:34:56:78:9A:BC", function(device) { - if (device.deviceClass.hasService(tizen.bluetooth.deviceService.POSITIONING)) - { - console.log("Device supports Positioning service"); - } + if (device.deviceClass.hasService(tizen.bluetooth.deviceService.POSITIONING)) + { + console.log("Device supports Positioning service"); + } }, function(e) { - console.log("Couldn't get device for given address: " + e.message); + console.log("Couldn't get device for given address: " + e.message); });
Since: @@ -5406,7 +5405,8 @@ adapter.getDevice("12:34:56:78:9A:BC", function(device)
Since: @@ -5445,29 +5445,29 @@ var adapter = tizen.bluetooth.getDefaultAdapter(); function chatServiceSuccessCb(handler) { - console.log("Chat service " + handler.name + " with UUID " + handler.uuid + " is successfully registered!"); - console.log("There is " + (handler.isConnected ? "a" : "no") + " device using this service"); + console.log("Chat service " + handler.name + " with UUID " + handler.uuid + " is successfully registered!"); + console.log("There is " + (handler.isConnected ? "a" : "no") + " device using this service"); - handler.onconnect = function(socket) - { - console.log("Client is connected: " + socket.peer.name + "," + socket.peer.address); - socket.onmessage = function() - { - var data = socket.readData(); - /* Handle message code here */ - }; + handler.onconnect = function(socket) + { + console.log("Client is connected: " + socket.peer.name + "," + socket.peer.address); + socket.onmessage = function() + { + var data = socket.readData(); + /* Handle message code goes here */ + }; - /* Expected close */ - socket.onclose = function() - { - console.log('The socket is closed.'); - }; - }; + /* Expected close */ + socket.onclose = function() + { + console.log("The socket is closed."); + }; + }; } function errorCb(e) { - console.log("Could not register service record, Error: " + e.message); + console.log("Could not register service record, Error: " + e.message); } var CHAT_SERVICE_UUID = "5BCE9431-6C75-32AB-AFE0-2EC108A30860"; @@ -5546,46 +5546,50 @@ var chatServiceHandler = null; function chatServiceSuccessCb(handler) { - console.log("Chat service registration was successful!"); + console.log("Chat service registration was successful!"); - chatServiceHandler = handler; - handler.onconnect = function(socket) - { - console.log("Client is connected: " + socket.peer.name + "," + socket.peer.address); - socket.onmessage = function() - { - var data = socket.readData(); - /* Handle message code here */ - }; + chatServiceHandler = handler; + handler.onconnect = function(socket) + { + console.log("Client is connected: " + socket.peer.name + "," + socket.peer.address); + socket.onmessage = function() + { + var data = socket.readData(); + /* Handle message code goes here */ + }; - /* Expected close */ - socket.onclose = function() - { - console.log('The socket is closed.'); - }; - }; + /* Expected close */ + socket.onclose = function() + { + console.log("The socket is closed."); + }; + }; } function publishChatService() { - var CHAT_SERVICE_UUID = "5BCE9431-6C75-32AB-AFE0-2EC108A30860"; - adapter.registerRFCOMMServiceByUUID(CHAT_SERVICE_UUID, "Chat service", chatServiceSuccessCb, - /* Error handler: function(e) {console.log("Could not register service record, Error: " + e.message);} */); + var CHAT_SERVICE_UUID = "5BCE9431-6C75-32AB-AFE0-2EC108A30860"; + adapter.registerRFCOMMServiceByUUID(CHAT_SERVICE_UUID, "Chat service", chatServiceSuccessCb, + /* Error handler */ + function(e) + { + console.log("Could not register service record, Error: " + e.message); + }); } function unRegisterChatService() { - if (chatServiceHandler != null) - { - chatServiceHandler.unregister(function() - { - chatServiceHandler = null; - console.log("Chat service is unregistered."); + if (chatServiceHandler != null) + { + chatServiceHandler.unregister(function() + { + chatServiceHandler = null; + console.log("Chat service is unregistered."); }, function(e) - { - console.log("Error: " + e.message); - }); - } + { + console.log("Error: " + e.message); + }); + } } @@ -5624,12 +5628,12 @@ var healthCapability = tizen.systeminfo.getCapability("http://tizen.org/feature/ if (healthCapability) { - var healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH"); - console.log("Bluetooth profile type is " + healthProfileHandler.profileType); + var healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH"); + console.log("Bluetooth profile type is " + healthProfileHandler.profileType); } else { - console.log("Bluetooth Health Profile is not supported on this device."); + console.log("Bluetooth Health Profile is not supported on this device."); } @@ -5734,12 +5738,12 @@ var healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH"); function healthRegisterSuccess(app) { - console.log("Registered application: " + app.name); + console.log("Registered application: " + app.name); } function healthRegisterError(e) { - console.log("Failed to register application: " + e.message); + console.log("Failed to register application: " + e.message); }; healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError); @@ -5825,33 +5829,33 @@ var registerHealthApp = null; function healthConnectSuccess(channel) { - console.log("Health device is connected"); - var status = "Name of remote device: " + channel.peer.name + - "channel type of device profile: " + channel.channelType + - "health application name: " + channel.appication.name; - console.log(status); + console.log("Health device is connected"); + var status = "Name of remote device: " + channel.peer.name + + "channel type of device profile: " + channel.channelType + + "health application name: " + channel.appication.name; + console.log(status); } function healthConnectError(e) { - console.log("Failed to connect to source: " + e.message); + console.log("Failed to connect to source: " + e.message); }; function gotDeviceInfo(device) { - healthProfileHandler.connectToSource(device, registerHealthApp, healthConnectSuccess, healthConnectError); + healthProfileHandler.connectToSource(device, registerHealthApp, healthConnectSuccess, healthConnectError); } function healthRegisterSuccess(app) { - console.log("Registered application: " + app.name); - registerHealthApp = app; - adapter.getDevice("35:F4:59:D1:7A:03", gotDeviceInfo); + console.log("Registered application: " + app.name); + registerHealthApp = app; + adapter.getDevice("35:F4:59:D1:7A:03", gotDeviceInfo); } function healthRegisterError(e) { - console.log("Failed to register application: " + e.message); + console.log("Failed to register application: " + e.message); }; healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError); @@ -5936,18 +5940,18 @@ var healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH"); function healthRegisterSuccess(app) { - console.log("Registered application: " + app.name); - console.log("Data type used for communication is " + app.dataType); + console.log("Registered application: " + app.name); + console.log("Data type used for communication is " + app.dataType); - app.onconnect = function(channel) - { - console.log("Health device is connected"); - } + app.onconnect = function(channel) + { + console.log("Health device is connected"); + } } function healthRegisterError(e) { - console.log("Failed to register application: " + e.message); + console.log("Failed to register application: " + e.message); }; healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError); @@ -6028,51 +6032,51 @@ var healthApp = null; function healthRegisterSuccess(app) { - console.log("Registered application: " + app.name); - healthApp = app; - healthApp.onconnect = function(channel) - { - console.log("Connected!!"); - }; + console.log("Registered application: " + app.name); + healthApp = app; + healthApp.onconnect = function(channel) + { + console.log("Connected!!"); + }; } function healthRegisterError(e) { - console.log("Failed to register application: " + e.message); + console.log("Failed to register application: " + e.message); }; function startSink() { - try - { - healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError); - } - catch (e) - { - console.log("Error: " + e.message); - } + try + { + healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError); + } + catch (e) + { + console.log("Error: " + e.message); + } } function stopSink() { - try - { - if (healthApp != null) + try + { + if (healthApp != null) + { + healthApp.unregister(function() { - healthApp.unregister(function() - { - healthApp = null; - console.log("Health application is unregistered."); - }, function(e) - { - console.log("Error: " + e.message); - }); - } - } - catch (err) - { - console.log("Error: " + err.message); - } + healthApp = null; + console.log("Health application is unregistered."); + }, function(e) + { + console.log("Error: " + e.message); + }); + } + } + catch (err) + { + console.log("Error: " + err.message); + } } @@ -6157,16 +6161,16 @@ var healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH"); function healthRegisterSuccess(app) { - app.onconnect = function(channel) - { - console.log("Health device " + (channel.isConnected ? "is" : "is not") + " connected to " + channel.peer.name + " remote device"); - console.log("Channel type is " + channel.channelType + " and health application name used for communication is " + channel.application.name); - } + app.onconnect = function(channel) + { + console.log("Health device " + (channel.isConnected ? "is" : "is not") + " connected to " + channel.peer.name + " remote device"); + console.log("Channel type is " + channel.channelType + " and health application name used for communication is " + channel.application.name); + } } function healthRegisterError(e) { - console.log("Failed to register application: " + e.message); + console.log("Failed to register application: " + e.message); }; healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError); @@ -6226,17 +6230,17 @@ var healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH"); function healthRegisterSuccess(app) { - console.log("Registered application: " + app.name); - app.onconnect = function(channel) - { - console.log("Health device is connected"); - channel.close(); - } + console.log("Registered application: " + app.name); + app.onconnect = function(channel) + { + console.log("Health device is connected"); + channel.close(); + } } function healthRegisterError(e) { - console.log("Failed to register application: " + e.message); + console.log("Failed to register application: " + e.message); }; healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError); @@ -6309,22 +6313,22 @@ var textmsg = "Test"; var dataToSend = new Array(); for (var i = 0; i < textmsg.length; i++) { - dataToSend[i] = textmsg.charCodeAt(i); + dataToSend[i] = textmsg.charCodeAt(i); } function healthRegisterSuccess(app) { - console.log("Registered application: " + app.name); - app.onconnect = function(channel) - { - console.log("Health device is connected"); - channel.sendData(dataToSend); - } + console.log("Registered application: " + app.name); + app.onconnect = function(channel) + { + console.log("Health device is connected"); + channel.sendData(dataToSend); + } } function healthRegisterError(e) { - console.log("Failed to register application: " + e.message); + console.log("Failed to register application: " + e.message); }; healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError); @@ -6387,29 +6391,29 @@ var healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH"); var channelCallback = { - onmessage: function(data) - { - console.log("data is received") - }, - onclose: function() - { - console.log("channel is closed"); - } + onmessage: function(data) + { + console.log("data is received") + }, + onclose: function() + { + console.log("channel is closed"); + } }; function healthRegisterSuccess(app) { - console.log("Registered application: " + app.name); - app.onconnect = function(channel) - { - console.log("Health device is connected"); - channel.setListener(channelCallback); - } + console.log("Registered application: " + app.name); + app.onconnect = function(channel) + { + console.log("Health device is connected"); + channel.setListener(channelCallback); + } } function healthRegisterError(e) { - console.log("Failed to register application: " + e.message); + console.log("Failed to register application: " + e.message); }; healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError); @@ -6462,31 +6466,31 @@ var connectedChannel = null; var channelCallback = { - onmessage: function(data) - { - console.log("data is received") - }, - onclose: function() - { - console.log("channel is closed"); - connectedChannel.unsetListener(); - } + onmessage: function(data) + { + console.log("data is received") + }, + onclose: function() + { + console.log("channel is closed"); + connectedChannel.unsetListener(); + } }; function healthRegisterSuccess(app) { - console.log("Registered application: " + app.name); - app.onconnect = function(channel) - { - console.log("Health device is connected"); - connectedChannel = channel; - connectedChannel.setListener(channelCallback); - } + console.log("Registered application: " + app.name); + app.onconnect = function(channel) + { + console.log("Health device is connected"); + connectedChannel = channel; + connectedChannel.setListener(channelCallback); + } } function healthRegisterError(e) { - console.log("Failed to register application: " + e.message); + console.log("Failed to register application: " + e.message); }; healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError); @@ -7129,10 +7133,6 @@ To guarantee that the Bluetooth Low Energy application runs on a device with Blu optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); - void setPowered(boolean state, - optional SuccessCallback? successCallback, - optional ErrorCallback? errorCallback) raises(WebAPIException); - void setChangeListener(BluetoothAdapterChangeCallback listener) raises(WebAPIException); void unsetChangeListener() raises(WebAPIException); @@ -7249,6 +7249,7 @@ To guarantee that the Bluetooth Low Energy application runs on a device with Blu readonly attribute BluetoothLESolicitationUUID[]? solicitationuuids; readonly attribute BluetoothLEServiceData[]? serviceData; readonly attribute BluetoothLEManufacturerData? manufacturerData; + readonly attribute long rssi; void connect(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); @@ -7284,7 +7285,7 @@ To guarantee that the Bluetooth Low Energy application runs on a device with Blu readonly attribute octet minor; - readonly attribute unsigned short [] services ; + readonly attribute unsigned short [] services; boolean hasService(unsigned short service) raises(WebAPIException); }; -- 2.7.4