diff --git a/docs/application/web/api/6.0/device_api/mobile/tizen/bluetooth.html b/docs/application/web/api/6.0/device_api/mobile/tizen/bluetooth.html index bdb05ddf4f..5daa2005d1 100644 --- a/docs/application/web/api/6.0/device_api/mobile/tizen/bluetooth.html +++ b/docs/application/web/api/6.0/device_api/mobile/tizen/bluetooth.html @@ -32,6 +32,8 @@ Advertise for remote devices (including Bluetooth LE devices)
  • Act as a GATT client (Generic Attribute Profile client)
  • +
  • +Configure the local GATT server (Generic Attribute Profile)
  • For more information on the Bluetooth features, see Bluetooth Guide. @@ -73,6 +75,15 @@

    Table of Contents

  • 1.10. Bytes
  • +
  • + 1.11. BluetoothGATTServiceVariant +
  • +
  • + 1.12. BluetoothGATTCharacteristicVariant +
  • +
  • + 1.13. BluetoothGATTDescriptorVariant +
  • 2. Interfaces
  • @@ -190,6 +225,8 @@

    Summary of Interfaces and Methods

    BluetoothAdapter getDefaultAdapter ()
    BluetoothLEAdapter getLEAdapter ()
    +
    +BluetoothGATTServer getGATTServer ()
    byte[] toByteArray (Bytes data)
    DOMString toDOMString (Bytes data)
    @@ -221,8 +258,11 @@

    Summary of Interfaces and Methods

    void startScan (BluetoothLEScanCallback successCallback, optional ErrorCallback? errorCallback)
    void stopScan ()
    +
    boolean isScanning ()
    void startAdvertise (BluetoothLEAdvertiseData advertiseData, BluetoothAdvertisePacketType packetType, BluetoothLEAdvertiseCallback successCallback, optional ErrorCallback? errorCallback, optional BluetoothAdvertisingMode? mode, optional boolean? connectable)
    void stopAdvertise ()
    +
    long addConnectStateChangeListener (BluetoothLEConnectChangeCallback listener)
    +
    void removeConnectStateChangeListener (long watchID)
    @@ -230,6 +270,14 @@

    Summary of Interfaces and Methods

    +BluetoothGATTServerServiceInit + + + +BluetoothGATTServerService +
    void unregister (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    + + BluetoothGATTCharacteristic
    void readValue (ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback)
    @@ -239,6 +287,18 @@

    Summary of Interfaces and Methods

    +BluetoothGATTServerCharacteristicInit + + + +BluetoothGATTServerCharacteristic + +
    void notifyAboutValueChange (Bytes value, BluetoothAddress? clientAddress, optional NotificationCallback? notificationCallback, optional ErrorCallback? errorCallback)
    +
    void setReadValueRequestCallback (ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, optional ErrorCallback? sendResponseErrorCallback)
    +
    void setWriteValueRequestCallback (WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, optional ErrorCallback? sendResponseErrorCallback)
    + + + BluetoothGATTDescriptor
    void readValue (ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback)
    @@ -246,6 +306,27 @@

    Summary of Interfaces and Methods

    +BluetoothGATTServerDescriptorInit + + + +BluetoothGATTServerDescriptor + +
    void setReadValueRequestCallback (ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, optional ErrorCallback? sendResponseErrorCallback)
    +
    void setWriteValueRequestCallback (WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, optional ErrorCallback? sendResponseErrorCallback)
    + + + +BluetoothGATTServer + +
    void start (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +
    void stop (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +
    void registerService (BluetoothGATTServerServiceInit service, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +
    void unregisterAllServices (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +
    void getConnectionMtu (BluetoothAddress clientAddress, ConnectionMtuCallback callback, optional ErrorCallback? errorCallback)
    + + + BluetoothLEScanCallback
    void onsuccess (BluetoothLEDevice device)
    @@ -265,6 +346,32 @@

    Summary of Interfaces and Methods

    void onread (byte[] value)
    +GATTRequestReply + + + +ReadValueRequestCallback +
    +GATTRequestReply? onreadrequest (BluetoothAddress clientAddress, long offset)
    + + +WriteValueRequestCallback +
    +GATTRequestReply? onwriterequest (BluetoothAddress clientAddress, byte[] value, long offset, boolean replyRequired)
    + + +NotificationCallback + +
    void onnotificationsuccess (BluetoothAddress clientAddress)
    +
    void onnotificationfail (BluetoothAddress clientAddress, WebAPIException error)
    +
    void onnotificationfinish (BluetoothAddress clientAddress)
    + + + +ConnectionMtuCallback +
    void onsuccess (long mtu)
    + + BluetoothDevice
    void connectToServiceByUUID (BluetoothUUID uuid, BluetoothSocketSuccessCallback successCallback, optional ErrorCallback? errorCallback)
    @@ -273,12 +380,17 @@

    Summary of Interfaces and Methods

    void connect (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    void disconnect (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +
    boolean isConnected ()
    BluetoothGATTService getService (BluetoothUUID uuid)
    BluetoothUUID[] getServiceAllUuids ()
    long addConnectStateChangeListener (BluetoothLEConnectChangeCallback listener)
    void removeConnectStateChangeListener (long watchID)
    +
    unsigned long getAttMtu ()
    +
    void requestAttMtuChange (unsigned long newAttMtu)
    +
    long addAttMtuChangeListener (ConnectionMtuCallback callback)
    +
    void removeAttMtuChangeListener (long watchId)
    @@ -524,6 +636,36 @@

    1. Type Definitions

    1.0

    +
    +

    1.11. BluetoothGATTServiceVariant

    +
    + The type of objects which are either BluetoothGATTService or BluetoothGATTServerService, depending on the context in which they appear. +
    +
      typedef (BluetoothGATTService or BluetoothGATTServerService) BluetoothGATTServiceVariant;
    +

    Since: + 6.0 +

    +
    +
    +

    1.12. BluetoothGATTCharacteristicVariant

    +
    + The type of objects which are either BluetoothGATTCharacteristic or BluetoothGATTServerCharacteristic, depending on the context in which they appear. +
    +
      typedef (BluetoothGATTCharacteristic or BluetoothGATTServerCharacteristic) BluetoothGATTCharacteristicVariant;
    +

    Since: + 6.0 +

    +
    +
    +

    1.13. BluetoothGATTDescriptorVariant

    +
    + The type of objects which are either BluetoothGATTDescriptor or BluetoothGATTServerDescriptor, depending on the context in which they appear. +
    +
      typedef (BluetoothGATTDescriptor or BluetoothGATTServerDescriptor) BluetoothGATTDescriptorVariant;
    +

    Since: + 6.0 +

    +

    2. Interfaces

    @@ -705,7 +847,7 @@

    Attributes

    BluetoothLESolicitationUUID[]? solicitationuuids; unsigned long? appearance; boolean? includeTxPowerLevel; - BluetoothLEServiceData? serviceData; + BluetoothLEServiceData[]? servicesData; BluetoothLEManufacturerData? manufacturerData; };

    Since: @@ -740,8 +882,9 @@

    Attributes

    attribute BluetoothLESolicitationUUID[]? solicitationuuids; attribute unsigned long? appearance; attribute boolean? includeTxPowerLevel; - attribute BluetoothLEServiceData? serviceData; - attribute BluetoothLEManufacturerData? manufacturerData; + attribute BluetoothLEServiceData[]? servicesData; + attribute BluetoothLEServiceData? serviceData; + attribute BluetoothLEManufacturerData? manufacturerData; };

    Since: 2.3.1 @@ -876,16 +1019,39 @@

    Attributes

    -
  • +
  • +BluetoothLEServiceData[] + servicesData [nullable]
    + The array of objects representing service data for advertise. +
    +

    Since: + 6.0 +

    +

    Remark: + Only 16-bit BluetoothLEServiceData::uuid values can be advertised. Duplicated uuid values in servicesData are not allowed for advertising. +

    +

    Remark: + If this attribute is in neither null nor undefined, the value of deprecated BluetoothLEAdvertiseData::serviceData attribute is ignored. +

    +
    +

    Code example:

    var advertise = new tizen.BluetoothLEAdvertiseData();
    +
    +var firstService = new tizen.BluetoothLEServiceData("11e5", "0x1811");
    +var secondService = new tizen.BluetoothLEServiceData("a5e8", "0x1815");
    +advertise.servicesData = [firstService, secondService];
    +
    +
    +
  • +
  • BluetoothLEServiceData serviceData [nullable]
    The service data for advertise or scan response data.
    +

    Deprecated. + Deprecated since 6.0. Instead, use BluetoothLEAdvertiseData::servicesData. +

    Since: 2.3.1

    -

    Remark: - Only 16-bit BluetoothLEServiceData::uuid values can be advertised. -

    Code example:

    var advertise = new tizen.BluetoothLEAdvertiseData();
     var service = new tizen.BluetoothLEServiceData("11e5", "0x1811");
    @@ -922,6 +1088,7 @@ 

    Attributes

    readonly attribute BluetoothClassDeviceService deviceService; BluetoothAdapter getDefaultAdapter() raises(WebAPIException); BluetoothLEAdapter getLEAdapter() raises(WebAPIException); + BluetoothGATTServer getGATTServer() raises(WebAPIException); byte[] toByteArray(Bytes data) raises(WebAPIException); DOMString toDOMString(Bytes data) raises(WebAPIException); Uint8Array toUint8Array(Bytes data) raises(WebAPIException); @@ -1093,6 +1260,50 @@

    Methods

    +
    +getGATTServer +
    +
    +
    + Gets the BluetoothGATTServer object, which allows starting, stopping the local GATT server, and configuring its services. +
    +
    BluetoothGATTServer getGATTServer();
    +

    Since: + 6.0 +

    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Return value:

    + +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      • + with error type NotSupportedError, if the feature is not supported. +

      • +
      • + with error type AbortError, if any other error occurs. +

      • +
      +
    +
    +
    +

    Code example:

    var server = tizen.bluetooth.getGATTServer();
    +
    +
    +
    toByteArray
    @@ -1143,15 +1354,20 @@

    Methods

    Code example:

    var dataInt8Array = new Int8Array([-21, 31]);
     var dataUint8Array = new Uint8Array([240, 129]);
     var dataString = "0x18b1";
    -console.log("converted from Int8Array: " + tizen.bluetooth.toByteArray(dataInt8Array));
    -console.log("converted from Uint8Array: " + tizen.bluetooth.toByteArray(dataUint8Array));
    -console.log("converted from DOMString: " + tizen.bluetooth.toByteArray(dataString));
    +
    +var fromInt8Array = tizen.bluetooth.toByteArray(dataInt8Array);
    +var fromUint8Array = tizen.bluetooth.toByteArray(dataUint8Array);
    +var fromString = tizen.bluetooth.toByteArray(dataString);
    +
    +console.log("converted from Int8Array: " + JSON.stringify(fromInt8Array));
    +console.log("converted from Uint8Array: " + JSON.stringify(fromUint8Array));
    +console.log("converted from DOMString: " + JSON.stringify(fromString));
     
    -

    Output example:

    converted from Int8Array: Int8Array(2) [-21, 31]
    -converted from Uint8Array: Int8Array(2) [-16, -127]
    -converted from DOMString: Int8Array(2) [24, -79]
    +

    Output example:

    converted from Int8Array: [235, 31]
    +converted from Uint8Array: [240, 129]
    +converted from DOMString: [244, 177]
     
    @@ -1255,15 +1471,20 @@

    Methods

    Code example:

    var dataInt8Array = new Int8Array([-21, 31]);
     var dataUint8Array = new Uint8Array([240, 129]);
     var dataString = "0x18b1";
    -console.log("converted from Int8Array: " + tizen.bluetooth.toUint8Array(dataInt8Array));
    -console.log("converted from Uint8Array: " + tizen.bluetooth.toUint8Array(dataUint8Array));
    -console.log("converted from DOMString: " + tizen.bluetooth.toUint8Array(dataString));
    +
    +var fromInt8Array = tizen.bluetooth.toUint8Array(dataInt8Array);
    +var fromUint8Array = tizen.bluetooth.toUint8Array(dataUint8Array);
    +var fromString = tizen.bluetooth.toUint8Array(dataString);
    +
    +console.log("converted from Int8Array: " + JSON.stringify(fromInt8Array));
    +console.log("converted from Uint8Array: " + JSON.stringify(fromUint8Array));
    +console.log("converted from DOMString: " + JSON.stringify(fromString));
     
    -

    Output example:

    converted from Int8Array: Uint8Array(2) [235, 31]
    -converted from Uint8Array: Uint8Array(2) [240, 129]
    -converted from DOMString: Uint8Array(2) [24, 177]
    +

    Output example:

    converted from Int8Array: {"0":235, "1":31}
    +converted from Uint8Array: {"0":240, "1":129}
    +converted from DOMString: {"0":24, "1":177}
     
    @@ -1302,9 +1523,13 @@

    Methods

  • -

    Code example:

    tizen.bluetooth.uuidTo128bit("1234");
    -tizen.bluetooth.uuidTo128bit("ab5690ef");
    -tizen.bluetooth.uuidTo128bit("abcdef01-2345-6789-abcd-ef0123456789");
    +

    Code example:

    var uuidFrom16bits = tizen.bluetooth.uuidTo128bit("1234");
    +var uuidFrom32bits = tizen.bluetooth.uuidTo128bit("ab5690ef");
    +var uuidFrom128bits = tizen.bluetooth.uuidTo128bit("abcdef01-2345-6789-abcd-ef0123456789");
    +
    +console.log(uuidFrom16bits);
    +console.log(uuidFrom32bits);
    +console.log(uuidFrom128bits);
     
    @@ -2672,10 +2897,13 @@

    Methods

      [NoInterfaceObject] interface BluetoothLEAdapter {
         void startScan(BluetoothLEScanCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
         void stopScan() raises(WebAPIException);
    +    boolean isScanning() raises(WebAPIException);
         void startAdvertise(BluetoothLEAdvertiseData advertiseData, BluetoothAdvertisePacketType packetType,
                             BluetoothLEAdvertiseCallback successCallback, optional ErrorCallback? errorCallback,
                             optional BluetoothAdvertisingMode? mode, optional boolean? connectable) raises(WebAPIException);
         void stopAdvertise() raises(WebAPIException);
    +    long addConnectStateChangeListener(BluetoothLEConnectChangeCallback listener) raises(WebAPIException);
    +    void removeConnectStateChangeListener(long watchID);
       };

    Since: 2.3.1 @@ -2802,6 +3030,56 @@

    Methods

    +
    +isScanning +
    +
    +
    + Checks if scanning for Bluetooth Low Energy devices is currently in progress. +
    +
    boolean isScanning();
    +

    Since: + 6.0 +

    +
    +

    Return value:

    + +
    +
    +

    Exceptions:

    + +
    +
    +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
    +var scanningStarted = adapter.isScanning();
    +console.log("Scanning status: " + scanningStarted);
    +if (!scanningStarted)
    +{
    +  adapter.startScan(function onsuccess(device)
    +  {
    +    console.log("Scanning status: " + adapter.isScanning());
    +    adapter.stopScan();
    +  });
    +}
    +
    +
    +
    +

    Output example:

    Scanning status: false
    +Scanning status: true
    +
    +
    +
    startAdvertise
    @@ -2881,6 +3159,9 @@

    Methods

  • with error type QuotaExceededError, if any input attribute is not compatible with the maximum data size for this attribute.

  • +
  • + with error type InvalidValuesError, if advertising services data contains duplicated UUIDs. +

  • with error type InvalidStateError, if device is currently in progress of advertising, if the local Bluetooth le adapter is currently not enabled.

  • @@ -2981,52 +3262,182 @@

    Methods

    - - - -
    -

    2.9. BluetoothGATTService

    +
    +addConnectStateChangeListener +
    +
    - Bluetooth Low Energy Service. The service can be retrieved with BluetoothLEDevice.getService(). -
    -
      [NoInterfaceObject] interface BluetoothGATTService {
    -    readonly attribute BluetoothUUID uuid;
    -    readonly attribute BluetoothUUID? serviceUuid;
    -    readonly attribute BluetoothGATTService[] services;
    -    readonly attribute BluetoothGATTCharacteristic[] characteristics;
    -  };
    + Registers a listener that is called whenever a GATT connection with another device is established or terminated. +
    +
    long addConnectStateChangeListener(BluetoothLEConnectChangeCallback listener);

    Since: - 2.3.1 -

    + 6.0 +

    +
    +

    +The BluetoothLEConnectChangeCallback, registered with this function, is called in the following cases: +

    + +
    +
    +

    Parameters:

    + +
    +
    +

    Return value:

    + +
    +
    +

    Exceptions:

    + +
    -

    Code example:

    function onconnected(device)
    +

    Code example:

    /* This application is running the local GATT Server and does not connect to remote GATT servers. */
    +/* To be able to notify connected clients about characteristic values' changes, it saves their data. */
    +var connectedClients = [];
    +
    +function onConnected(device)
     {
    -  console.log("Connected to device");
    -  var service = device.getService(device.uuids[0]);
    -  console.log("Service got");
    +  console.log("A client connected: " + device.address);
    +  connectedClients.push(device);
     }
     
    -var adapter = tizen.bluetooth.getLEAdapter();
    -adapter.startScan(function onsuccess(device)
    +function onDisconnected(device)
     {
    -  console.log("[Found device] address: " + device.address);
    -  device.connect(onconnected.bind(null, device), onerror);
    -});
    +  console.log("A client disconnected: " + device.address);
    +  connectedClients = connectedClients.filter(function(connectedClient)
    +  {
    +    return connectedClient.address !== device.address;
    +  });
    +}
    +
    +tizen.bluetooth.getLEAdapter().addConnectStateChangeListener(
    +    {onconnected: onConnected, ondisconnected: onDisconnected});
     
    -
    -

    Attributes

    -
    +
    +

    2.9. BluetoothGATTService

    +
    + Bluetooth Low Energy service. The service can be retrieved with BluetoothLEDevice::getService(). +
    +
      [NoInterfaceObject] interface BluetoothGATTService {
    +    readonly attribute BluetoothUUID uuid;
    +    readonly attribute BluetoothUUID? serviceUuid;
    +    readonly attribute BluetoothGATTServiceVariant[] services;
    +    readonly attribute BluetoothGATTCharacteristicVariant[] characteristics;
    +  };
    +

    Since: + 2.3.1 +

    +
    +

    Code example:

    function onconnected(device)
    +{
    +  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);
    +});
    +
    +
    +
    +

    Attributes

    +
    +
    +

    2.10. BluetoothGATTServerServiceInit

    +
    + A dictionary for specifying GATT service parameters. +
    +
      dictionary BluetoothGATTServerServiceInit {
    +    BluetoothUUID serviceUuid;
    +    boolean isPrimary = true;
    +    BluetoothGATTServerServiceInit[]? includedServices = null;
    +    BluetoothGATTServerCharacteristicInit[]? characteristics = null;
    +  };
    +

    Since: + 6.0 +

    +
    +

    +This dictionary defines the GATT services to be registered to the local GATT server. +

    +
    +
    +

    Code example:

    /* serviceA and serviceB are objects of type BluetoothGATTServerServiceInit. */
    +/* hrmCharacteristic is a BluetoothGATTServerCharacteristicInit object. */
    +var serviceParameters =
    +{
    +  serviceUuid: "4b102e75",
    +  isPrimary: true,
    +  includedServices: [serviceA, serviceB],
    +  characteristics: [hrmCharacteristic]
    +};
    +
    +
    +
    +
    +

    2.11. BluetoothGATTServerService

    +
    + The class representing a Bluetooth GATT service provided by the local GATT server. +
    +
      [NoInterfaceObject] interface BluetoothGATTServerService : BluetoothGATTService {
    +    readonly attribute boolean isPrimary;
    +    void unregister(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +  };
    +

    Since: + 6.0 +

    + +
    +

    Attributes

    + +
    +
    +

    Methods

    +
    +
    +unregister +
    +
    +
    + Unregisters the service and all its characteristics from the local GATT server. +
    +
    void unregister(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • + InvalidStateError - If the service cannot be unregistered in the current state of the GATT server.
    • +
    • + AbortError - If any other error occurs
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +

    Remark: + GATT services included in other GATT services cannot be unregistered. +

    +

    Remark: + If this method is called for the only GATT service, currently registered in the local running GATT server, the server stops running. +

    +
    +

    Parameters:

    +
      +
    • +successCallback [optional] [nullable]: + Callback function that is called when the service is successfully unregistered from the local GATT server. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      • + with error type AbortError, if any other error occurs. +

      • +
      +
    +
    +
    +

    Code example:

    /* The service has been registered in the GATT server for a while. Now it is no longer needed. */
    +function onsuccess()
    +{
    +  console.log("Service unregistered");
    +}
    +
    +function onerror(error)
    +{
    +  console.log("Failed to unregister service: " + error.message);
    +}
    +
    +tizen.bluetooth.getGATTServer().services[0].unregister(onsuccess, onerror);
    +
    +
    +
    +
    +
    +
    -

    2.10. BluetoothGATTCharacteristic

    +

    2.12. BluetoothGATTCharacteristic

    A characteristic provided by Bluetooth Low Energy service.
      [NoInterfaceObject] interface BluetoothGATTCharacteristic {
    -    readonly attribute BluetoothGATTDescriptor[] descriptors;
    +    readonly attribute BluetoothGATTDescriptorVariant[] descriptors;
         readonly attribute boolean isBroadcast;
         readonly attribute boolean hasExtendedProperties;
         readonly attribute boolean isNotify;
    @@ -3130,13 +3688,16 @@ 

    Attributes

    @@ -3343,6 +3910,9 @@

    Methods

    Privilege: http://tizen.org/privilege/bluetooth

    +

    Remark: + BluetothGATTServerCharacteristic objects do not support this function. An attempt to call it for such an object will result in an exception. +

    Parameters:

    @@ -3434,6 +4007,9 @@

    Methods

    Privilege: http://tizen.org/privilege/bluetooth

    +

    Remark: + BluetothGATTServerCharacteristic objects do not support this function. An attempt to call it for such an object will result in an exception. +

    Parameters:

    Exceptions:

    -
    @@ -3511,6 +4092,9 @@

    Methods

    Remark: Example of using can be find at addValueChangeListener code example.

    +

    Remark: + Value change listeners cannot be registered and thus unregistered for BluetothGATTServerCharacteristic objects. An attempt to remove value change listener for such an object will result in no operation. +

    Parameters:

    -
    -

    2.11. BluetoothGATTDescriptor

    +
    +

    2.13. BluetoothGATTServerCharacteristicInit

    - Bluetooth Low Energy Descriptor. + A dictionary for specifying GATT characteristic parameters.
    -
      [NoInterfaceObject] interface BluetoothGATTDescriptor {
    -    readonly attribute BluetoothUUID? uuid;
    -    void readValue(ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    -    void writeValue(Bytes value, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    -                    raises(WebAPIException);
    +
      dictionary BluetoothGATTServerCharacteristicInit {
    +    BluetoothUUID uuid;
    +    BluetoothGATTServerDescriptorInit[]? descriptors = null;
    +    boolean isBroadcast = false;
    +    boolean hasExtendedProperties = false;
    +    boolean isNotify = false;
    +    boolean isIndication = false;
    +    boolean isReadable = false;
    +    boolean isSignedWrite = false;
    +    boolean isWritable = false;
    +    boolean isWriteNoResponse = false;
    +    boolean readPermission = false;
    +    boolean writePermission = false;
    +    boolean encryptedReadPermission = false;
    +    boolean encryptedWritePermission = false;
    +    boolean encryptedSignedReadPermission = false;
    +    boolean encryptedSignedWritePermission = false;
    +    ReadValueRequestCallback? readValueRequestCallback = null;
    +    SuccessCallback? readValueSendResponseSuccessCallback = null;
    +    ErrorCallback? readValueSendResponseErrorCallback = null;
    +    WriteValueRequestCallback? writeValueRequestCallback = null;
    +    SuccessCallback? writeValueSendResponseSuccessCallback = null;
    +    ErrorCallback? writeValueSendResponseErrorCallback = null;
       };

    Since: - 2.3.1 + 6.0

    -
    +
    +

    +This dictionary is used as a definition of a characteristic to be registered in a service of the local GATT server.
    readValueRequestCallback and writeValueRequestCallback are callbacks called when a client reads or writes the value of the characteristic respectively. They can be set or replaced with another functions, after registering the service containing the characteristic, with BluetoothGATTServerCharacteristic.setReadValueRequestCallback() and BluetoothGATTServerCharacteristic.setWriteValueRequestCallback().
    readValueSendResponseSuccessCallback and writeValueSendResponseSuccessCallback are success callbacks called when a response sent from readValueRequestCallback or writeValueRequestCallback reaches client. They can be set or replaced with another functions, after registering the service containing the characteristic, with BluetoothGATTServerCharacteristic.setReadValueRequestCallback() and BluetoothGATTServerCharacteristic.setWriteValueRequestCallback().
    readValueSendResponseErrorCallback and writeValueSendResponseErrorCallback are error callbacks called when an attempt to send a response to a client from readValueRequestCallback or writeValueRequestCallback fails. They can be set or replaced with another functions, after registering the service containing the characteristic, with BluetoothGATTServerCharacteristic.setReadValueRequestCallback() and BluetoothGATTServerCharacteristic.setWriteValueRequestCallback(). +

    +
    +
    +

    Code example:

    /* nameDescriptor, placeDescriptor are BluetoothGATTServerDescriptorInit objects */
    +/* readValueCallback, writeValueCallback are read/write request callbacks */
    +/* readValueSendResponseSuccessCallback and writeValueSendResponseSuccessCallback */
    +/* are success callbacks */
    +/* and writeValueSendResponseErrorCallback and readValueSendResponseErrorCallback */
    +/* are error callbacks */
    +var characteristicParameters =
    +{
    +  uuid: "0180",
    +  descriptors: [nameDescriptor, placeDescriptor],
    +  /* Characteristic's properties */
    +  isBroadcast: false,
    +  hasExtendedProperties: false,
    +  isNotify: false,
    +  isIndication: false,
    +  isReadable: true,
    +  isSignedWrite: false,
    +  isWritable: true,
    +  isWriteNoResponse: false,
    +  /* Characteristic's permissions */
    +  readPermission: true,
    +  writePermission: true,
    +  encryptedReadPermission: false,
    +  encryptedWritePermission: false,
    +  encryptedSignedReadPermission: false,
    +  encryptedSignedWritePermission: false,
    +  readValueRequestCallback: readValueCallback,
    +  readValueSendResponseSuccessCallback: readValueSendResponseSuccessCallback,
    +  readValueSendResponseErrorCallback: readValueSendResponseErrorCallback,
    +  writeValueRequestCallback: writeValueCallback,
    +  writeValueSendResponseSuccessCallback: writeValueSendResponseSuccessCallback,
    +  writeValueSendResponseErrorCallback: writeValueSendResponseErrorCallback
    +};
    +
    +
    +
    +
    +

    2.14. BluetoothGATTServerCharacteristic

    +
    + A subclass representing GATT characteristic used to construct a service of the local Bluetooth GATT server. +It extends BluetoothGATTCharacteristic with permissions and methods implementing interactions of the characteristic with remote clients. +
    +
      [NoInterfaceObject] interface BluetoothGATTServerCharacteristic : BluetoothGATTCharacteristic {
    +    readonly attribute boolean readPermission;
    +    readonly attribute boolean writePermission;
    +    readonly attribute boolean encryptedReadPermission;
    +    readonly attribute boolean encryptedWritePermission;
    +    readonly attribute boolean encryptedSignedReadPermission;
    +    readonly attribute boolean encryptedSignedWritePermission;
    +    void notifyAboutValueChange(Bytes value, BluetoothAddress? clientAddress, optional NotificationCallback? notificationCallback,
    +                                optional ErrorCallback? errorCallback) raises(WebAPIException);
    +    void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback,
    +                                     optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                     optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException);
    +    void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback,
    +                                      optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                      optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException);
    +  };
    +

    Since: + 6.0 +

    + +

    Attributes

    -
    • +
        +
      • readonly -BluetoothUUID uuid [nullable]
        - UUID of the descriptor. +boolean readPermission
        + Indicates if clients have the permission to read the value of the characteristic.

        Since: 6.0

        -

        Remark: - uuid is set to null, if the value cannot be retrieved. -

        -
      -
    -
    -

    Methods

    -
    -
    -readValue -
    -
    -
    - Reads descriptor value from remote device. Updates descriptor value attribute. + +
  • + readonly +boolean writePermission
    + Indicates if clients have the permission to write the value of the characteristic.
    -
    void readValue(ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback);

    Since: - 2.3.1 + 6.0

    -
    -

    -The ErrorCallback is launched with these error types: +

  • +
  • + readonly +boolean encryptedReadPermission
    + Indicates if clients have the permission to read the value of the characteristic through encrypted connections. +
    +

    Since: + 6.0

    -
      -
    • +
    • +
    • + readonly +boolean encryptedWritePermission
      + Indicates if clients have the permission to write the value of the characteristic through encrypted connections. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedSignedReadPermission
      + Indicates if clients have the permission to perform signed reads of the characteristic's value. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedSignedWritePermission
      + Indicates if clients have the permission to perform signed writes of the characteristic's value. +
      +

      Since: + 6.0 +

      +
    • +
    +
  • +
    +

    Methods

    +
    +
    +notifyAboutValueChange +
    +
    +
    + Notifies the clients of the local GATT server of the changes in the characteristic. +
    +
    void notifyAboutValueChange(Bytes value, BluetoothAddress? clientAddress, optional NotificationCallback? notificationCallback,
    +                            optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +This function sends a BLE notification or indication about a change of characteristic's value to clients that registered for it. If a particular client is specified, only he gets the update. +Otherwise it is sent to all clients connected to the local GATT server, who registered for the updates.

    +

    +Clients can only register for characteristic's notifications or indications, if the characteristic defines a Client Characteristic Configuration Descriptor (CCCD), as described in the Bluetooth standard. +CCCD has to be defined as any other descriptor, using BluetoothGATTServerDescriptorInit. +

    +
    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • + InvalidValuesError - If any of the parameters is invalid.
    • +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +

    Remark: + To notify the clients the service with current characteristic must be registered (see BluetoothGATTServer::registerService()) and available for clients (see BluetoothGATTServer::start()). +

    +
    +

    Parameters:

    +
      +
    • +value: + The new value of the characteristic. +
    • +
    • +clientAddress [nullable]: + The address of the client to be notified about the value change. If a null is passed, all clients will be notified. +
    • +
    • +notificationCallback [optional] [nullable]: + The callback called for each attempt of a client notification. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure of sending notification. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server with at least one service which has at least one */
    +/* characteristic already exists */
    +var callback =
    +{
    +  onnotificationsuccess: function(clientAddress)
    +  {
    +    console.log(clientAddress + " notified about change.");
    +  },
    +  onnotificationfail: function(clientAddress, error)
    +  {
    +    console.error("Couldn't notify " + clientAddress + " about change:" + error.name);
    +  },
    +  onnotificationfinish: function(clientAddress)
    +  {
    +    console.log("Finished notifying about change.");
    +  }
    +};
    +
    +function errorCallback(error)
    +{
    +  console.error("Failed to notify about value change: " + error.name + ": " + error.message);
    +}
    +
    +server.services[0].characteristics[0].notifyAboutValueChange("1234", null, callback, errorCallback);
    +
    +
    +
    +
    +setReadValueRequestCallback +
    +
    +
    + Registers the callback called when a client reads the value of the characteristic from the local GATT server. +
    +
    void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback,
    +                                 optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                 optional ErrorCallback? sendResponseErrorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The callback, registered with this function, is called when a remote client requests to read the value of the characteristic. +The server can respond to such requests by returning a GATTRequestReply object from the callback. +If ReadValueRequestCallback for the characteristic is not registered, or it does not return a GATTRequestReply, clients will not be able to get the value of this characteristic.

    +

    +A callback set with this function overwrites any previously set ReadValueRequestCallback. +

    +

    +The errorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +

    +The sendResponseErrorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + InvalidValuesError - If GATTRequestReply::statusCode or GATTRequestReply::data is invalid.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +readValueRequestCallback: + The callback called when a client reads the value of the characteristic. +
    • +
    • +successCallback [optional] [nullable]: + Callback function that is called when the readValueRequestCallback is registered successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure of readValueRequestCallback registration. +
    • +
    • +sendResponseSuccessCallback [optional] [nullable]: + Callback function that is called when responses returned from readValueRequestCallbacks are sent successfully. +
    • +
    • +sendResponseErrorCallback [optional] [nullable]: + Callback function that is called when responses returned from readValueRequestCallbacks are not sent due to an error. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server with at least one service which has at least one */
    +/* characteristic already exists */
    +var callback = function(clientAddress, offset)
    +{
    +  console.log(clientAddress + " requested to read characteristic's value with offset: " + offset);
    +  return new tizen.GATTRequestReply(0, "0x1234");
    +};
    +
    +server.services[0].characteristics[0].setReadValueRequestCallback(callback);
    +
    +
    +
    +
    +setWriteValueRequestCallback +
    +
    +
    + Registers the callback called when a client writes the value of the characteristic of the local GATT server. +
    +
    void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback,
    +                                  optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                  optional ErrorCallback? sendResponseErrorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The callback, registered with this function, is called when a remote client requests to write the value of the characteristic. +The server can respond to such requests by returning a GATTRequestReply object from the callback. +If WriteValueRequestCallback for the characteristic is not registered, or it does not return a GATTRequestReply, clients will not be able to get the value of this characteristic.

    +

    +A callback set with this function overwrites any previously set WriteValueRequestCallback. +

    +

    +The errorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +

    +The sendResponseErrorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + InvalidValuesError - If GATTRequestReply::statusCode or GATTRequestReply::data is invalid.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +writeValueRequestCallback: + The callback called when a client writes the value of the characteristic. +
    • +
    • +successCallback [optional] [nullable]: + Callback function that is called when the writeValueRequestCallback is registered successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure of writeValueRequestCallback registration. +
    • +
    • +sendResponseSuccessCallback [optional] [nullable]: + Callback function that is called when responses returned from writeValueRequestCallbacks are sent successfully. +
    • +
    • +sendResponseErrorCallback [optional] [nullable]: + Callback function that is called when responses returned from writeValueRequestCallbacks are not sent due to an error. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server with at least one service which has at least one */
    +/* characteristic already exists */
    +var callback = function(clientAddress, value, offset, replyRequired)
    +{
    +  console.log(clientAddress + " requested to write characteristic's value: " + value +
    +              " with offset: " + offset);
    +  return replyRequired ? new tizen.GATTRequestReply(0, "0x1234") : null;
    +};
    +
    +server.services[0].characteristics[0].setWriteValueRequestCallback(callback);
    +
    +
    +
    +
    +
    +
    +
    +

    2.15. BluetoothGATTDescriptor

    +
    + Bluetooth Low Energy descriptor. +
    +
      [NoInterfaceObject] interface BluetoothGATTDescriptor {
    +    readonly attribute BluetoothUUID? uuid;
    +    void readValue(ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +    void writeValue(Bytes value, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +                    raises(WebAPIException);
    +  };
    +

    Since: + 2.3.1 +

    +
    +

    Attributes

    +
    • + readonly +BluetoothUUID uuid [nullable]
      + UUID of the descriptor. +
      +

      Since: + 6.0 +

      +

      Remark: + uuid is set to null, if the value cannot be retrieved. +

      +
    +
    +
    +

    Methods

    +
    +
    +readValue +
    +
    +
    + Reads descriptor value from remote device. Updates descriptor value attribute. +
    +
    void readValue(ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 2.3.1 +

    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • + UnknownError - If any other error occurs
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +

    Remark: + BluetothGATTServerDescriptor objects do not support this function. An attempt to call it for such an object will result in an exception. +

    +
    +

    Parameters:

    +
      +
    • +successCallback: + Callback function that is called when the descriptor value is read successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type InvalidStateError, if the local Bluetooth le adapter is currently not enabled. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      • + with error type NotSupportedError, if the method is called for BluetoothGATTServerDescriptor. +

      • +
      +
    +
    +
    +

    Code example:

    function onerror(e)
    +{
    +  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)
    +    {
    +      var characteristic = service.characteristics[0];
    +      var descriptor = characteristic.descriptors[0];
    +      descriptor.readValue(function(val)
    +      {
    +        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);
    +  }
    +});
    +
    +
    +
    +
    +writeValue +
    +
    +
    + Writes the descriptor value to the remote device. +
    +
    void writeValue(Bytes value, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 2.3.1 +

    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • UnknownError - If any other error occurs
    @@ -3582,16 +4729,601 @@

    Methods

    Privilege: http://tizen.org/privilege/bluetooth

    +

    Remark: + BluetothGATTServerDescriptor objects do not support this function. An attempt to call it for such an object will result in an exception. +

    +
    +

    Parameters:

    +
      +
    • +value: + The descriptor value to write. +
    • +
    • +successCallback [optional] [nullable]: + Callback function that is called when the descriptor value is written successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type InvalidStateError, if the local Bluetooth le adapter is currently not enabled. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      • + with error type NotSupportedError, if the method is called for BluetoothGATTServerDescriptor. +

      • +
      +
    +
    +
    +

    Code example:

    function onerror(e)
    +{
    +  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)
    +    {
    +      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);
    +          });
    +    }
    +  }
    +}
    +
    +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);
    +  }
    +});
    +
    +
    +
    +
    +
    +
    +
    +

    2.16. BluetoothGATTServerDescriptorInit

    +
    + A dictionary for specifying GATT descriptor parameters. +
    +
      dictionary BluetoothGATTServerDescriptorInit {
    +    BluetoothUUID uuid;
    +    boolean readPermission = false;
    +    boolean writePermission = false;
    +    boolean encryptedReadPermission = false;
    +    boolean encryptedWritePermission = false;
    +    boolean encryptedSignedReadPermission = false;
    +    boolean encryptedSignedWritePermission = false;
    +    ReadValueRequestCallback? readValueRequestCallback = null;
    +    SuccessCallback? readValueSendResponseSuccessCallback = null;
    +    ErrorCallback? readValueSendResponseErrorCallback = null;
    +    WriteValueRequestCallback? writeValueRequestCallback = null;
    +    SuccessCallback? writeValueSendResponseSuccessCallback = null;
    +    ErrorCallback? writeValueSendResponseErrorCallback = null;
    +  };
    +

    Since: + 6.0 +

    +
    +

    +This dictionary is used as a definition of a descriptor to be registered in a characteristic of the local GATT server.
    readValueRequestCallback and writeValueRequestCallback are callbacks called when a client reads or writes the value of the descriptor respectively. They can be set or replaced with another functions after registering the service containing the descriptor with BluetoothGATTServerDescriptor.setReadValueRequestCallback() and BluetoothGATTServerDescriptor.setWriteValueRequestCallback().
    readValueSendResponseSuccessCallback and writeValueSendResponseSuccessCallback are success callbacks called when a response sent from readValueRequestCallback or writeValueRequestCallback reaches client. They can be set or replaced with another functions, after registering the service containing the characteristic, with BluetoothGATTServerDescriptor.setReadValueRequestCallback() and BluetoothGATTServerDescriptor.setWriteValueRequestCallback().
    readValueSendResponseErrorCallback and writeValueSendResponseErrorCallback are error callbacks called when an attempt to send a response to a client from readValueRequestCallback or writeValueRequestCallback fails. They can be set or replaced with another functions, after registering the service containing the characteristic, with BluetoothGATTServerDescriptor.setReadValueRequestCallback() and BluetoothGATTServerDescriptor.setWriteValueRequestCallback(). +

    +
    +
    +

    Code example:

    /* readValueCallback, writeValueCallback are read/write request callbacks */
    +/* readValueSendResponseSuccessCallback and writeValueSendResponseSuccessCallback are success */
    +/* callbacks */
    +/* and writeValueSendResponseErrorCallback and readValueSendResponseErrorCallback are error */
    +/* callbacks */
    +var descriptorProperties =
    +{
    +  uuid: "0180",
    +  /* Descriptor's permissions */
    +  readPermission: true,
    +  writePermission: true,
    +  encryptedReadPermission: false,
    +  encryptedWritePermission: false,
    +  encryptedSignedReadPermission: false,
    +  encryptedSignedWritePermission: false,
    +  /* Read/write value callbacks */
    +  readValueRequestCallback: readValueCallback,
    +  readValueSendResponseSuccessCallback: readValueSendResponseSuccessCallback,
    +  readValueSendResponseErrorCallback: readValueSendResponseErrorCallback,
    +  writeValueRequestCallback: writeValueCallback,
    +  writeValueSendResponseSuccessCallback: writeValueSendResponseSuccessCallback,
    +  writeValueSendResponseErrorCallback: writeValueSendResponseErrorCallback
    +};
    +
    +
    +
    +
    +

    2.17. BluetoothGATTServerDescriptor

    +
    + A subclass representing GATT descriptors of characteristics registered in services of the local server. +It extends BluetoothGATTDescriptor with permissions and methods implementing interactions of the descriptor with remote clients. +
    +
      [NoInterfaceObject] interface BluetoothGATTServerDescriptor : BluetoothGATTDescriptor {
    +    readonly attribute boolean readPermission;
    +    readonly attribute boolean writePermission;
    +    readonly attribute boolean encryptedReadPermission;
    +    readonly attribute boolean encryptedWritePermission;
    +    readonly attribute boolean encryptedSignedReadPermission;
    +    readonly attribute boolean encryptedSignedWritePermission;
    +    void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback,
    +                                     optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                     optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException);
    +    void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback,
    +                                      optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                      optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException);
    +  };
    +

    Since: + 6.0 +

    + +
    +

    Attributes

    +
      +
    • + readonly +boolean readPermission
      + Indicates if clients have the permission to read the value of the descriptor. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean writePermission
      + Indicates if clients have the permission to write the value of the descriptor. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedReadPermission
      + Indicates if clients have the permission to read the value of the descriptor through encrypted connections. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedWritePermission
      + Indicates if clients have the permission to write the value of the descriptor through encrypted connections. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedSignedReadPermission
      + Indicates if clients have the permission to perform signed reads of the charactersitic's value. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedSignedWritePermission
      + Indicates if clients have the permission to perform signed writes of the charactersitic's value. +
      +

      Since: + 6.0 +

      +
    • +
    +
    +
    +

    Methods

    +
    +
    +setReadValueRequestCallback +
    +
    +
    + Registers the callback called when a client reads the value of the descriptor from the local GATT server. +
    +
    void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback,
    +                                 optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                 optional ErrorCallback? sendResponseErrorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The callback, registered with this function, is called when a remote client requests to read the value of the descriptor. +The server can respond to such requests by returning a GATTRequestReply object from the callback. +If ReadValueRequestCallback for the descriptor is not registered, or it does not return a GATTRequestReply, clients will not be able to get the value of this descriptor.

    +

    +A callback set with this function overwrites any previously set ReadValueRequestCallback. +

    +

    +The errorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +

    +The sendResponseErrorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + InvalidValuesError - If GATTRequestReply::statusCode or GATTRequestReply::data is invalid.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +readValueRequestCallback: + The callback called when a client reads the value of the descriptor. +
    • +
    • +successCallback [optional] [nullable]: + Callback function that is called when the readValueRequestCallback is registered successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure of readValueRequestCallback registration. +
    • +
    • +sendResponseSuccessCallback [optional] [nullable]: + Callback function that is called when responses returned from readValueRequestCallbacks are sent successfully. +
    • +
    • +sendResponseErrorCallback [optional] [nullable]: + Callback function that is called when responses returned from readValueRequestCallbacks are not sent due to an error. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server with at least one service which has at least one */
    +/* characteristic with at least one descriptor already exists */
    +var callback = function(clientAddress, offset)
    +{
    +  console.log(clientAddress + " requested to read characteristic's value with offset: " + offset);
    +  return new tizen.GATTRequestReply(0, "0x1234");
    +};
    +server.services[0].characteristics[0].descriptors[0].setReadValueRequestCallback(callback);
    +
    +
    +
    +
    +setWriteValueRequestCallback +
    +
    +
    + Registers the callback called when a remote client writes the value of the descriptor from the local GATT server. +
    +
    void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback,
    +                                  optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                  optional ErrorCallback? sendResponseErrorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The callback, registered with this function, is called when a remote client requests to write the value of the descriptor. +The server can respond to such requests by returning a GATTRequestReply object from the callback. +If WriteValueRequestCallback for the descriptor is not registered, or it does not return a GATTRequestReply, clients will not be able to get the value of this descriptor.

    +

    +A callback set with this function overwrites any previously set WriteValueRequestCallback. +

    +

    +The errorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +

    +The sendResponseErrorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + InvalidValuesError - If GATTRequestReply::statusCode or GATTRequestReply::data is invalid.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +writeValueRequestCallback: + The callback called when a client writes the value of the descriptor. +
    • +
    • +successCallback [optional] [nullable]: + Callback function that is called when the writeValueRequestCallback is registered successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure of writeValueRequestCallback registration. +
    • +
    • +sendResponseSuccessCallback [optional] [nullable]: + Callback function that is called when responses returned from writeValueRequestCallbacks are sent successfully. +
    • +
    • +sendResponseErrorCallback [optional] [nullable]: + Callback function that is called when responses returned from writeValueRequestCallbacks are not sent due to an error. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server with at least one service which has at least one */
    +/* characteristic with at least one descriptor already exists */
    +var callback = function(clientAddress, value, offset, replyRequired)
    +{
    +  console.log(clientAddress + " requested to write descriptor's value: " + value +
    +              " with offset: " + offset);
    +  return replyRequired ? new tizen.GATTRequestReply(0, "0x1234") : null;
    +};
    +server.services[0].characteristics[0].descriptors[0].setWriteValueRequestCallback(callback);
    +
    +
    +
    +
    +
    +
    +
    +

    2.18. BluetoothGATTServer

    +
    + The BluetoothGATTServer interface provides access to control the local GATT server: starting and stopping it, registering and unregistering local GATT services, and getting the ATT MTU (Attribute Protocol Maximum Transmission Unit) values. +
    +
      [NoInterfaceObject] interface BluetoothGATTServer {
    +    readonly attribute boolean isRunning;
    +    readonly attribute BluetoothGATTServerService[] services;
    +    void start(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +    void stop(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +    void registerService(BluetoothGATTServerServiceInit service, optional SuccessCallback? successCallback,
    +                         optional ErrorCallback? errorCallback) raises(WebAPIException);
    +    void unregisterAllServices(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +                               raises(WebAPIException);
    +    void getConnectionMtu(BluetoothAddress clientAddress, ConnectionMtuCallback callback, optional ErrorCallback? errorCallback)
    +                          raises(WebAPIException);
    +  };
    +

    Since: + 6.0 +

    +
    +

    Attributes

    +
      +
    • + readonly +boolean isRunning
      + The flag indicating if remote GATT clients can currently connect to the server, exposing services defined in BluetoothGATTServer::services. It is toggled on start() and stop() calls. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +BluetoothGATTServerService[] + services
      + The list of GATT services hosted on this server. +
      +

      Since: + 6.0 +

      +
    • +
    +
    +
    +

    Methods

    +
    +
    +start +
    +
    +
    + Starts the local GATT server. After it starts, it can conduct GATT server operations. Also, the remote clients can discover and use the services provided by the local Bluetooth GATT Server. +
    +
    void start(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The ErrorCallback will be launched in the following situations: +

    +
      +
    • + InvalidStateError - If the server is already running.
    • +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +successCallback [optional] [nullable]: + Called when the server is started. +
    • +
    • +errorCallback [optional] [nullable]: + The method to invoke when an error occurs. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type InvalidStateError, if the Bluetooth adapter is not enabled. +

      • +
      • + with error type TypeMismatchError, if any input attribute is not compatible with the expected type for this attribute. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      • + with error type AbortError, if any other error occurs. +

      • +
      +
    +
    +
    +

    Code example:

    var onSuccess = function()
    +{
    +  console.log("Server started successfully!");
    +};
    +
    +var onError = function(e)
    +{
    +  console.error("Server didn't start, error: " + e);
    +};
    +
    +var server = tizen.bluetooth.getGATTServer();
    +
    +server.start(onSuccess, onError);
    +
    +
    +
    +

    Output example:

    Server started successfully!
    +
    +
    +
    +
    +stop +
    +
    +
    + Stops GATT server operation. +
    +
    void stop(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +After the stop, remote clients will not be able to discover the local GATT server's services. +

    +

    +The ErrorCallback will be launched in the following situations: +

    +
      +
    • + InvalidStateError - If the server is not running.
    • +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    Parameters:

    • -successCallback: - Callback function that is called when the descriptor value is read successfully. +successCallback [optional] [nullable]: + Called when the server is stopped.
    • errorCallback [optional] [nullable]: - Callback function that is called in case of failure. + The method to invoke when an error occurs.
    @@ -3599,72 +5331,70 @@

    Methods

    Exceptions:

    • WebAPIException
      • - with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. + with error type InvalidStateError, if the Bluetooth adapter is not enabled.

      • - with error type InvalidStateError, if the local Bluetooth le adapter is currently not enabled. + with error type TypeMismatchError, if any input attribute is not compatible with the expected type for this attribute.

      • with error type SecurityError, if the application does not have the privilege to call this method.

      • +
      • + with error type AbortError, if any other error occurs. +

    -

    Code example:

    function onerror(e)
    +

    Code example:

    /* this example assumes that local gatt server already exists and it is started */
    +var onSuccess = function()
     {
    -  console.log("Failed to connect to device: " + e.message);
    -}
    +  console.log("Server stopped successfully!");
    +};
     
    -function proccessDevice(device)
    +var onError = function(e)
     {
    -  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)
    -      {
    -        console.log("Value read: " + val);
    -        device.disconnect();
    -      });
    -    }
    -  }
    -}
    +  console.error("Server didn't stop, error: " + e);
    +};
     
    -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);
    -  }
    -});
    +server.stop(onSuccess, onError);
    +
    +
    +
    +

    Output example:

    Server stopped successfully!
     
    -
    -writeValue +
    +registerService
    - Writes the descriptor value to the remote device. + Registers a primary service in the local GATT server.
    -
    void writeValue(Bytes value, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +
    void registerService(BluetoothGATTServerServiceInit service, optional SuccessCallback? successCallback,
    +                     optional ErrorCallback? errorCallback);

    Since: - 2.3.1 + 6.0 +

    +
    +

    +The service is available for clients after BluetoothGATTServer::start() call.

    +

    The ErrorCallback is launched with these error types:

    • -UnknownError - If any other error occurs
    • + InvalidStateError - If the service cannot be registered in the current state of the server. +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + InvalidValuesError - If any of the input parameters contains an invalid value
    • +
    • + AbortError - If any other error occurs.

    Privilege level: @@ -3673,20 +5403,23 @@

    Methods

    Privilege: http://tizen.org/privilege/bluetooth

    +

    Remark: + Services can only be registered before starting server. +

    Parameters:

    • -value: - The descriptor value to write. +service: + The definition of a service to be registered in the local GATT server.
    • successCallback [optional] [nullable]: - Callback function that is called when the descriptor value is written successfully. + Called when the local GATT server's services are successfully registered.
    • errorCallback [optional] [nullable]: - Callback function that is called in case of failure. + The method to invoke when an error occurs.
    @@ -3694,10 +5427,10 @@

    Methods

    Exceptions:

    • WebAPIException
      • - with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. + with error type InvalidStateError, if the Bluetooth adapter is not enabled.

      • - with error type InvalidStateError, if the local Bluetooth le adapter is currently not enabled. + with error type TypeMismatchError, if any input attribute is not compatible with the expected type for this attribute.

      • with error type SecurityError, if the application does not have the privilege to call this method. @@ -3706,45 +5439,185 @@

        Methods

    -

    Code example:

    function onerror(e)
    +

    Code example:

    var gattService = {serviceUuid: "0955", isPrimary: false, services: [], characteristics: []};
    +
    +var successCB = function()
     {
    -  console.log("Failed to connect to device: " + e.message);
    -}
    +  console.log("Service successfully registered!");
    +};
     
    -function proccessDevice(device)
    +var errorCB = function(e)
     {
    -  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()
    -          {
    -            console.log("Value written");
    -            device.disconnect();
    -          },
    -          function(e)
    -          {
    -            console.log("Failed to write: " + e.message);
    -          });
    -    }
    -  }
    -}
    +  console.log("Service not registered, error: " + e);
    +};
     
    -var adapter = tizen.bluetooth.getLEAdapter();
    -adapter.startScan(function onsuccess(device)
    +var server = tizen.bluetooth.getGATTServer();
    +
    +server.registerService(gattService, successCB, errorCB);
    +
    +
    +
    +

    Output example:

    Service successfully registered!
    +
    +
    + +
    +unregisterAllServices +
    +
    +
    + Unregisters all services from the local GATT server. +
    +
    void unregisterAllServices(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +This method unregisters all services and all their characteristics from the local GATT server. +

    +
    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • + InvalidStateError - If the service cannot be unregistered in the current state of the GATT server.
    • +
    • + AbortError - If any other error occurs
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +

    Remark: + Currently running local GATT server is stopped after calling this method. +

    +
    +

    Parameters:

    +
      +
    • +successCallback [optional] [nullable]: + Callback function that is called when services are successfully unregistered from the local GATT server. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server already exists */
    +var successCB = function()
     {
    -  if (device.address == "11:22:33:44:55:66")
    -  {
    -    console.log("Found device: " + device.name);
    -    proccessDevice(device);
    -  }
    -});
    +  console.log("Services successfully unregistered!");
    +};
    +
    +var errorCB = function(e)
    +{
    +  console.log("Services not unregistered, error: " + e);
    +};
    +
    +server.unregisterAllServices(successCB, errorCB);
    +
    +
    +
    +

    Output example:

    Services successfully unregistered!
    +
    +
    +
    +
    +getConnectionMtu +
    +
    +
    + Gets the ATT MTU for the connection with a client. +
    +
    void getConnectionMtu(BluetoothAddress clientAddress, ConnectionMtuCallback callback, optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • + InvalidStateError - If the server is not running.
    • +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +clientAddress: + MAC address of the client, for connection with whom the MTU is to be retrieved. +
    • +
    • +callback: + Callback functions that are called when the connection state changes. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called when getting MTU of a connection fails. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server already exists */
    +var successCB = function(mtu)
    +{
    +  console.log("ATT MTU value is: " + mtu);
    +};
    +
    +var errorCB = function(e)
    +{
    +  console.log("Cannot retrieve the ATT MTU, error: " + e);
    +};
    +
    +server.getConnectionMtu("12:34:56:78:90:ab", successCB, errorCB);
    +
    +
    +
    +

    Output example:

    ATT MTU value is: 123
     
    @@ -3752,7 +5625,7 @@

    Methods

    -

    2.12. BluetoothLEScanCallback

    +

    2.19. BluetoothLEScanCallback

    Bluetooth scanning process interface that defines the success callback for BluetoothLEAdapter.startScan()
      [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothLEScanCallback {
    @@ -3792,7 +5665,7 @@ 

    Methods

    -

    2.13. BluetoothLEAdvertiseCallback

    +

    2.20. BluetoothLEAdvertiseCallback

    Bluetooth advertising process interface that defines the success callback for BluetoothLEAdapter.startAdvertise()
      [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothLEAdvertiseCallback {
    @@ -3832,7 +5705,7 @@ 

    Methods

    -

    2.14. BluetoothLEConnectChangeCallback

    +

    2.21. BluetoothLEConnectChangeCallback

    Bluetooth LE connecting process interface that defines callbacks for getting notified about changes of connect to a specific LE based service on a remote Bluetooth LE device.
    @@ -3877,7 +5750,7 @@

    Methods

    -

    2.15. ReadValueSuccessCallback

    +

    2.22. ReadValueSuccessCallback

    The ReadValueSuccessCallback interface implements the callback for BluetoothGATTCharacteristic.readValue() and @@ -3919,8 +5792,307 @@

    Methods

    +
    +

    2.23. GATTRequestReply

    +
    + Representation of the local GATT server's response to request read/write to characteristic/descriptor. +
    +
      [Constructor(long statusCode = 0, optional Bytes data)]
    +  interface GATTRequestReply {
    +    attribute long statusCode;
    +    attribute Bytes? data;
    +  };
    +

    Since: + 6.0 +

    +
    +

    Constructors

    +
    +
    +Constructor (long, Bytes) +
    +
    GATTRequestReply(long statusCode = 0, optional Bytes data);
    +
    +
    +
    +

    Attributes

    + +
    +
    +
    +

    2.24. ReadValueRequestCallback

    +
    + The ReadValueRequestCallback interface implements the callback for +BluetoothGATTServerCharacteristicInit.readValueRequestCallback(), +BluetoothGATTServerCharacteristic.setReadValueRequestCallback(), +BluetoothGATTServerDescriptorInit.readValueRequestCallback() and +BluetoothGATTServerDescriptor.setReadValueRequestCallback(). +
    +
      [Callback=FunctionOnly, NoInterfaceObject] interface ReadValueRequestCallback {
    +    GATTRequestReply? onreadrequest(BluetoothAddress clientAddress, long offset);
    +  };
    +

    Since: + 6.0 +

    +

    Remark: + Example of using can be found at BluetoothGATTServerCharacteristic.setReadValueRequestCallback() and BluetoothGATTServerDescriptor.setReadValueRequestCallback() code examples. +

    +
    +

    Methods

    +
    +
    +onreadrequest +
    +
    +
    + Called when a client makes a read request for GATT characteristic to the connected local GATT server. +
    +
    GATTRequestReply? onreadrequest(BluetoothAddress clientAddress, long offset);
    +

    Since: + 6.0 +

    +
    +

    +The server should reply to requests by returning a GATTRequestReply object with requested data and a proper status code. +If the callback does not return a GATTRequestReply, the client will not receive a response. +

    +
    +
    +

    Parameters:

    +
      +
    • +clientAddress: + MAC address of the client that requested the value read of the GATT entity. +
    • +
    • +offset: + The offset given for the value of characteristic to read. +
    • +
    +
    +
    +

    Return value:

    +
      +GATTRequestReply [nullable]: + GATTRequestReply object with a status code and requested data. +
    +
    +
    +
    +
    +
    +
    +

    2.25. WriteValueRequestCallback

    +
    + The WriteValueRequestCallback interface implements the callback for +BluetoothGATTServerCharacteristicInit.writeValueRequestCallback(), +BluetoothGATTServerCharacteristic.setWriteValueRequestCallback(), +BluetoothGATTServerDescriptorInit.writeValueRequestCallback() and +BluetoothGATTServerDescriptor.setWriteValueRequestCallback(). +
    +
      [Callback=FunctionOnly, NoInterfaceObject] interface WriteValueRequestCallback {
    +    GATTRequestReply? onwriterequest(BluetoothAddress clientAddress, byte[] value, long offset, boolean replyRequired);
    +  };
    +

    Since: + 6.0 +

    +

    Remark: + Example of using can be found at BluetoothGATTServerCharacteristic.setWriteValueRequestCallback() and BluetoothGATTServerDescriptor.setWriteValueRequestCallback() code examples. +

    +
    +

    Methods

    +
    +
    +onwriterequest +
    +
    +
    + Called when a client connected to the local GATT server requests characteristic's value write. +
    +
    GATTRequestReply? onwriterequest(BluetoothAddress clientAddress, byte[] value, long offset, boolean replyRequired);
    +

    Since: + 6.0 +

    +
    +

    +The server should reply to requests by returning a GATTRequestReply object with a status code. +If the callback does not return a GATTRequestReply, the client will not receive a response. +

    +
    +
    +

    Parameters:

    +
      +
    • +clientAddress: + MAC address of the client that requested the value write of the GATT entity. +
    • +
    • +value: + Value to be written to the GATT entity. +
    • +
    • +offset: + Offset from which the value is to be written. +
    • +
    • +replyRequired: + Flag indicating whether the client requested an answer to the request. If it's false, the client preforms the write without response operation defined in Bluetooth Core Specification. +
    • +
    +
    +
    +
    +
    +
    +
    +

    2.26. NotificationCallback

    +
    + The NotificationCallback interface implements the success callback for BluetoothGATTServerCharacteristic.notifyAboutValueChange(). +
    +
      [Callback=FunctionOnly, NoInterfaceObject] interface NotificationCallback {
    +    void onnotificationsuccess(BluetoothAddress clientAddress);
    +    void onnotificationfail(BluetoothAddress clientAddress, WebAPIException error);
    +    void onnotificationfinish(BluetoothAddress clientAddress);
    +  };
    +

    Since: + 6.0 +

    +

    Remark: + Example of using can be found at BluetoothGATTServerCharacteristic.notifyAboutValueChange() code examples. +

    +
    +

    Methods

    +
    +
    +onnotificationsuccess +
    +
    +
    + Called when the local GATT server successfully notifies a client of a characteristic's value change. +
    +
    void onnotificationsuccess(BluetoothAddress clientAddress);
    +

    Since: + 6.0 +

    +
    +

    Parameters:

    +
      +
    • +clientAddress: + MAC address of the client that was notified. +
    • +
    +
    +
    +
    +onnotificationfail +
    +
    +
    + Called when the local GATT server fails to notify a client of a characteristic's value change. +
    +
    void onnotificationfail(BluetoothAddress clientAddress, WebAPIException error);
    +

    Since: + 6.0 +

    +
    +

    Parameters:

    +
      +
    • +clientAddress: + MAC address of the client that was notified. +
    • +
    • +error: + The error type and an error message from Tizen's Bluetooth LE stack. +
    • +
    +
    +
    +
    +onnotificationfinish +
    +
    +
    + Called when the last of all client notifications was sent. +
    +
    void onnotificationfinish(BluetoothAddress clientAddress);
    +

    Since: + 6.0 +

    +
    +

    Parameters:

    +
      +
    • +clientAddress: + MAC address of the last client that was notified. +
    • +
    +
    +
    +
    +
    +
    +
    +

    2.27. ConnectionMtuCallback

    +
    + The ConnectionMtuCallback interface implements the callback for BluetoothGATTServer.getConnectionMtU(). +
    +
      [Callback=FunctionOnly, NoInterfaceObject] interface ConnectionMtuCallback {
    +    void onsuccess(long mtu);
    +  };
    +

    Since: + 6.0 +

    +

    Remark: + Example of using can be found at BluetoothGATTServer.getConnectionMtu() code example. +

    +
    +

    Methods

    +
    +
    +onsuccess +
    +
    +
    + Called when the requested ATT MTU size for a connection is ready. +
    +
    void onsuccess(long mtu);
    +

    Since: + 6.0 +

    +
    +

    Parameters:

    +
      +
    • +mtu: + The requested ATT MTU value for the connection with another Bluetooth LE device. +
    • +
    +
    +
    +
    +
    +
    -

    2.16. BluetoothDevice

    +

    2.28. BluetoothDevice

    The BluetoothDevice interface represents a remote Bluetooth device.
    @@ -4283,7 +6455,7 @@

    Methods

    -

    2.17. BluetoothLEDevice

    +

    2.29. BluetoothLEDevice

    The BluetoothLEDevice interface represents a remote Bluetooth LE device.
    @@ -4296,13 +6468,18 @@

    Methods

    readonly attribute BluetoothLESolicitationUUID[]? solicitationuuids; readonly attribute BluetoothLEServiceData[]? serviceData; readonly attribute BluetoothLEManufacturerData? manufacturerData; - readonly attribute long rssi; + readonly attribute long? rssi; void connect(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void disconnect(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); + boolean isConnected() raises(WebAPIException); BluetoothGATTService getService(BluetoothUUID uuid) raises(WebAPIException); BluetoothUUID[] getServiceAllUuids() raises(WebAPIException); long addConnectStateChangeListener(BluetoothLEConnectChangeCallback listener) raises(WebAPIException); void removeConnectStateChangeListener(long watchID); + unsigned long getAttMtu() raises(WebAPIException); + void requestAttMtuChange(unsigned long newAttMtu) raises(WebAPIException); + long addAttMtuChangeListener(ConnectionMtuCallback callback) raises(WebAPIException); + void removeAttMtuChangeListener(long watchId) raises(WebAPIException); };

    Since: 2.3.1 @@ -4314,6 +6491,8 @@

    Methods

    @@ -4344,6 +6523,9 @@

    Attributes

    Since: 2.3.1

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4366,6 +6548,9 @@ 

    Attributes

    Since: 2.3.1

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4383,6 +6568,9 @@ 

    Attributes

    Since: 2.3.1

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4401,6 +6589,9 @@ 

    Attributes

    Since: 2.3.1

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4425,6 +6616,9 @@ 

    Attributes

    Since: 2.3.1

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4452,6 +6646,9 @@ 

    Attributes

    Remark: On devices prior to Tizen 6.0, service data is found only when its BluetoothLEServiceData::uuid is 16-bit. Finding service data with 128-bit BluetoothLEServiceData::uuid is supported since Tizen 6.0.

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4475,6 +6672,9 @@ 

    Attributes

    Since: 2.3.1

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     
    @@ -4513,7 +6713,7 @@ 

    Attributes

  • readonly -long rssi
    +long rssi [nullable]
    The received signal strength indicator in dBm (decibel-milliwatts) units.
    @@ -4524,6 +6724,9 @@

    Attributes

    Since: 3.0

    +

    Remark: + Since Tizen 6.0, this value can be a null, but only if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4694,15 +6897,76 @@ 

    Methods

    device.disconnect(ondisconnect, onerror); } - 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); + } +} + +var adapter = tizen.bluetooth.getLEAdapter(); +adapter.startScan(onDeviceFound, onerror); +
    +
    + +
    +isConnected +
    +
    +
    + Checks if Bluetooth Low Energy device is currently connected. +
    +
    boolean isConnected();
    +

    Since: + 6.0 +

    +
    +

    Return value:

    +
      +boolean: + true if the device is currently connected, false otherwise. +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
      • + with error type UnknownError, if any error occurs. +

      +
    +
    +
    +

    Code example:

    var dev;
    +
    +function onerror(e)
    +{
    +  console.log("Failed to connect to device: " + e.message);
    +}
    +
    +function onconnected()
    +{
    +  console.log("Connected to device: " + dev.isConnected());
     }
     
     var adapter = tizen.bluetooth.getLEAdapter();
    -adapter.startScan(onDeviceFound, onerror);
    +adapter.startScan(function onsuccess(device)
    +{
    +  if (device.address == "11:22:33:44:55:66")
    +  {
    +    adapter.stopScan();
    +    dev = device;
    +    var connected = dev.isConnected();
    +    console.log("Found device: " + device.name + ", connected: " + connected);
    +    if (!connected)
    +    {
    +      device.connect(onconnected, onerror);
    +    }
    +  }
    +});
    +
    +
    +
    +

    Output example:

    Found device: TestDevice, connected: false
    +Connected to device: true
     
    @@ -4887,7 +7151,7 @@

    Methods

    Exceptions:

    • WebAPIException
      • - with error type UnknownError, if any other error occurs. + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    @@ -4984,11 +7248,282 @@

    Methods

  • +
    +getAttMtu +
    +
    +
    + Gets the current value of Attribute Protocol(ATT) Maximum Transmission Unit(MTU) from the connected device. +
    +
    unsigned long getAttMtu();
    +

    Since: + 6.0 +

    +
    +

    Return value:

    +
      +unsigned long: + Current ATT MTU value. +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type InvalidStateError, if the remote device is not connected. +

      • +
      • + with error type UnknownError, if any other error occurs. +

      • +
      +
    +
    +
    +

    Code example:

    var dev;
    +
    +function onerror(e)
    +{
    +  console.log("Failed to connect to device: " + e.message);
    +}
    +
    +function onconnected()
    +{
    +  console.log("Connected to device, ATT MTU: " + dev.getAttMtu());
    +}
    +
    +var adapter = tizen.bluetooth.getLEAdapter();
    +adapter.startScan(function onsuccess(device)
    +{
    +  if (device.address == "11:22:33:44:55:66")
    +  {
    +    dev = device;
    +    console.log("Found device: " + device.name);
    +    device.connect(onconnected, onerror);
    +  }
    +});
    +
    +
    +
    +

    Output example:

    Found device: TestDevice
    +Connected to device, ATT MTU: 23
    +
    +
    +
    +
    +requestAttMtuChange +
    +
    +
    + Requests the GATT server to change the Attribute Protocol (ATT) Maximum Transmission Unit (MTU) value. +
    +
    void requestAttMtuChange(unsigned long newAttMtu);
    +

    Since: + 6.0 +

    +

    Remark: + ATT MTU value is determined between two connected devices and change will be successful only if both devices support the given value of ATT MTU. +

    +
    +

    Parameters:

    +
      +
    • +newAttMtu: + The new ATT MTU value, that will be sent to GATT server. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
      • + with error type UnknownError, if any error occurs. +

      +
    +
    +
    +

    Code example:

    function proccessDevice(device)
    +{
    +  function onConnected()
    +  {
    +    var attMtu = device.getAttMtu();
    +    console.log("Initial ATT MTU value: " + attMtu);
    +    watchID = device.addAttMtuChangeListener(function(value)
    +    {
    +      console.log("ATT MTU changed to: " + value);
    +      device.removeAttMtuChangeListener(watchID);
    +      device.disconnect();
    +    });
    +    device.requestAttMtuChange(64);
    +  }
    +  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);
    +  }
    +});
    +
    +
    +
    +

    Output example:

    Found device: TestDevice
    +Initial ATT MTU value: 31
    +ATT MTU changed to: 64
    +
    +
    +
    +
    +addAttMtuChangeListener +
    +
    +
    + Registers a listener to be called when ATT MTU value is changed. +
    +
    long addAttMtuChangeListener(ConnectionMtuCallback callback);
    +

    Since: + 6.0 +

    +

    Remark: + ATT MTU value is determined between two connected devices and change takes place after both devices agrees to new value, both connected devices can initiate the ATT MTU value change by sending the request. +

    +
    +

    Parameters:

    +
      +
    • +callback: + Listener function that is called when the connection's ATT MTU changes. +
    • +
    +
    +
    +

    Return value:

    +
      +long: + The watchID to be used to unregister the listener. +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if an input attribute is not compatible with the expected type for this attribute. +

      • +
      • + with error type UnknownError, if any other error occurs. +

      • +
      +
    +
    +
    +

    Code example:

    function proccessDevice(device)
    +{
    +  function onConnected()
    +  {
    +    var attMtu = device.getAttMtu();
    +    console.log("Initial ATT MTU value: " + attMtu);
    +    watchID = device.addAttMtuChangeListener(function(value)
    +    {
    +      console.log("ATT MTU changed to: " + value);
    +      device.removeAttMtuChangeListener(watchID);
    +      device.disconnect();
    +    });
    +    device.requestAttMtuChange(64);
    +  }
    +  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);
    +  }
    +});
    +
    +
    +
    +

    Output example:

    Found device: TestDevice
    +Initial ATT MTU value: 31
    +ATT MTU changed to: 64
    +
    +
    +
    +
    +removeAttMtuChangeListener +
    +
    +
    + Unregisters the ATT MTU value change listener. +
    +
    void removeAttMtuChangeListener(long watchId);
    +

    Since: + 6.0 +

    +
    +

    Parameters:

    +
      +
    • +watchId: + The watchID identifier returned by the addAttMtuChangeListener() method. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
      • + with error type UnknownError, if any error occurs. +

      +
    +
    +
    +

    Code example:

    function proccessDevice(device)
    +{
    +  function onConnected()
    +  {
    +    var attMtu = device.getAttMtu();
    +    console.log("Initial ATT MTU value: " + attMtu);
    +    watchID = device.addAttMtuChangeListener(function(value)
    +    {
    +      console.log("ATT MTU changed to: " + value);
    +      device.removeAttMtuChangeListener(watchID);
    +      device.disconnect();
    +    });
    +    device.requestAttMtuChange(64);
    +  }
    +  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);
    +  }
    +});
    +
    +
    +
    +

    Output example:

    Found device: TestDevice
    +Initial ATT MTU value: 31
    +ATT MTU changed to: 64
    +
    +
    +
    -

    2.18. BluetoothSocket

    +

    2.30. BluetoothSocket

    The BluetoothSocket interface represents the Bluetooth socket.
    @@ -5481,7 +8016,7 @@

    Methods

    -

    2.19. BluetoothClass

    +

    2.31. BluetoothClass

    The BluetoothClass interface represents Bluetooth Class of Device/Service(CoD).
    @@ -5658,7 +8193,7 @@

    Methods

    -

    2.20. BluetoothClassDeviceMajor

    +

    2.32. BluetoothClassDeviceMajor

    The BluetoothClassDeviceMajor interface holds the identifiers for major device classes of Bluetooth CoD.
    @@ -5680,7 +8215,7 @@

    Methods

    -

    2.21. BluetoothClassDeviceMinor

    +

    2.33. BluetoothClassDeviceMinor

    The BluetoothClassDeviceMinor interface holds the identifiers for minor device classes of Bluetooth CoD.
    @@ -5763,7 +8298,7 @@

    Methods

    -

    2.22. BluetoothClassDeviceService

    +

    2.34. BluetoothClassDeviceService

    The BluetoothClassDeviceService interface holds identifiers for the major service classes of Bluetooth CoD.
    @@ -5783,7 +8318,7 @@

    Methods

    -

    2.23. BluetoothServiceHandler

    +

    2.35. BluetoothServiceHandler

    The BluetoothServiceHandler interface provides methods to handle Bluetooth service.
    @@ -5995,7 +8530,7 @@

    Methods

    -

    2.24. BluetoothProfileHandler

    +

    2.36. BluetoothProfileHandler

    The BluetoothProfileHandler interface represents the Bluetooth profile handler.
    @@ -6041,7 +8576,7 @@

    Attributes

    -

    2.25. BluetoothHealthProfileHandler

    +

    2.37. BluetoothHealthProfileHandler

    This interface represents the handler of Bluetooth health device profile. The BluetoothHealthProfileHandler object is created by BluetoothAdapter.getBluetoothProfileHandler(). @@ -6260,7 +8795,7 @@

    Methods

    -

    2.26. BluetoothHealthApplication

    +

    2.38. BluetoothHealthApplication

    The BluetoothHealthApplication interface represents the Bluetooth health application.
    @@ -6479,7 +9014,7 @@

    Methods

    -

    2.27. BluetoothHealthChannel

    +

    2.39. BluetoothHealthChannel

    The BluetoothHealthChannel interface represents the Bluetooth health channel.
    @@ -6886,7 +9421,7 @@

    Methods

    -

    2.28. BluetoothAdapterChangeCallback

    +

    2.40. BluetoothAdapterChangeCallback

    The BluetoothAdapterChangeCallback interface specifies a set of methods to be invoked when the changes of Bluetooth adapter occur.
    @@ -6971,7 +9506,7 @@

    Methods

    -

    2.29. BluetoothDeviceSuccessCallback

    +

    2.41. BluetoothDeviceSuccessCallback

    The BluetoothDeviceSuccessCallback interface implements the success callback BluetoothAdapter.getDevice() and BluetoothAdapter.createBonding().
    @@ -7012,7 +9547,7 @@

    Methods

    -

    2.30. BluetoothDeviceArraySuccessCallback

    +

    2.42. BluetoothDeviceArraySuccessCallback

    The BluetoothDeviceArraySuccessCallback interface that defines the success callback for BluetoothAdapter.getKnownDevices().
    @@ -7054,7 +9589,7 @@

    Methods

    -

    2.31. BluetoothDiscoverDevicesSuccessCallback

    +

    2.43. BluetoothDiscoverDevicesSuccessCallback

    The BluetoothDiscoverDevicesSuccessCallback interface that defines the success callback for BluetoothAdapter.discoverDevices().
    @@ -7153,7 +9688,7 @@

    Methods

    -

    2.32. BluetoothSocketSuccessCallback

    +

    2.44. BluetoothSocketSuccessCallback

    The BluetoothSocketSuccessCallback interface that defines the success method for BluetoothDevice.connectToServiceByUUID().
    @@ -7194,7 +9729,7 @@

    Methods

    -

    2.33. BluetoothServiceSuccessCallback

    +

    2.45. BluetoothServiceSuccessCallback

    The BluetoothServiceSuccessCallback interface implements the success callback for BluetoothAdapter.registerRFCOMMServiceByUUID().
    @@ -7235,7 +9770,7 @@

    Methods

    -

    2.34. BluetoothHealthApplicationSuccessCallback

    +

    2.46. BluetoothHealthApplicationSuccessCallback

    The BluetoothHealthApplicationSuccessCallback interface that defines the success method for BluetoothHealthProfileHandler.registerSinkApplication().
    @@ -7282,7 +9817,7 @@

    Methods

    -

    2.35. BluetoothHealthChannelSuccessCallback

    +

    2.47. BluetoothHealthChannelSuccessCallback

    The BluetoothHealthChannelSuccessCallback interface that defines the success method for BluetoothHealthProfileHandler.connectToSource() and the event callback for BluetoothHealthApplication.onconnect().
    @@ -7329,7 +9864,7 @@

    Methods

    -

    2.36. BluetoothHealthChannelChangeCallback

    +

    2.48. BluetoothHealthChannelChangeCallback

    The BluetoothHealthChannelChangeCallback interface specifies a set of methods to be invoked when the changes of heath channel occur.
    @@ -7429,6 +9964,14 @@

    3. Related Feature

  • http://tizen.org/feature/network.bluetooth.le.gatt.client
  • +
    +

    +

    +To guarantee that the Bluetooth Low Energy application runs on a device with Bluetooth Low Energy GATT Server feature, declare the following feature requirements in the config file: +

    +

    +
  • http://tizen.org/feature/network.bluetooth.le.gatt.server
  • +

    For more information, see Application Filtering. @@ -7438,6 +9981,9 @@

    4. Full WebIDL

    typedef DOMString BluetoothUUID; typedef DOMString BluetoothLESolicitationUUID; typedef (byte[] or DOMString or Uint8Array) Bytes; + typedef (BluetoothGATTService or BluetoothGATTServerService) BluetoothGATTServiceVariant; + typedef (BluetoothGATTCharacteristic or BluetoothGATTServerCharacteristic) BluetoothGATTCharacteristicVariant; + typedef (BluetoothGATTDescriptor or BluetoothGATTServerDescriptor) BluetoothGATTDescriptorVariant; enum BluetoothSocketState { "CLOSED", "OPEN" }; enum BluetoothAdvertisePacketType { "ADVERTISE", "SCAN_RESPONSE" }; enum BluetoothAdvertisingState { "STARTED", "STOPPED" }; @@ -7448,9 +9994,54 @@

    4. Full WebIDL

    BluetoothLESolicitationUUID[]? solicitationuuids; unsigned long? appearance; boolean? includeTxPowerLevel; - BluetoothLEServiceData? serviceData; + BluetoothLEServiceData[]? servicesData; BluetoothLEManufacturerData? manufacturerData; }; + dictionary BluetoothGATTServerServiceInit { + BluetoothUUID serviceUuid; + boolean isPrimary = true; + BluetoothGATTServerServiceInit[]? includedServices = null; + BluetoothGATTServerCharacteristicInit[]? characteristics = null; + }; + dictionary BluetoothGATTServerCharacteristicInit { + BluetoothUUID uuid; + BluetoothGATTServerDescriptorInit[]? descriptors = null; + boolean isBroadcast = false; + boolean hasExtendedProperties = false; + boolean isNotify = false; + boolean isIndication = false; + boolean isReadable = false; + boolean isSignedWrite = false; + boolean isWritable = false; + boolean isWriteNoResponse = false; + boolean readPermission = false; + boolean writePermission = false; + boolean encryptedReadPermission = false; + boolean encryptedWritePermission = false; + boolean encryptedSignedReadPermission = false; + boolean encryptedSignedWritePermission = false; + ReadValueRequestCallback? readValueRequestCallback = null; + SuccessCallback? readValueSendResponseSuccessCallback = null; + ErrorCallback? readValueSendResponseErrorCallback = null; + WriteValueRequestCallback? writeValueRequestCallback = null; + SuccessCallback? writeValueSendResponseSuccessCallback = null; + ErrorCallback? writeValueSendResponseErrorCallback = null; + }; + dictionary BluetoothGATTServerDescriptorInit { + BluetoothUUID uuid; + boolean readPermission = false; + boolean writePermission = false; + boolean encryptedReadPermission = false; + boolean encryptedWritePermission = false; + boolean encryptedSignedReadPermission = false; + boolean encryptedSignedWritePermission = false; + ReadValueRequestCallback? readValueRequestCallback = null; + SuccessCallback? readValueSendResponseSuccessCallback = null; + ErrorCallback? readValueSendResponseErrorCallback = null; + WriteValueRequestCallback? writeValueRequestCallback = null; + SuccessCallback? writeValueSendResponseSuccessCallback = null; + ErrorCallback? writeValueSendResponseErrorCallback = null; + }; Tizen implements BluetoothManagerObject; [NoInterfaceObject] interface BluetoothManagerObject { readonly attribute BluetoothManager bluetooth; @@ -7472,7 +10063,7 @@

    4. Full WebIDL

    attribute BluetoothLESolicitationUUID[]? solicitationuuids; attribute unsigned long? appearance; attribute boolean? includeTxPowerLevel; - attribute BluetoothLEServiceData? serviceData; + attribute BluetoothLEServiceData[]? servicesData; attribute BluetoothLEManufacturerData? manufacturerData; }; [NoInterfaceObject] interface BluetoothManager { @@ -7482,6 +10073,7 @@

    4. Full WebIDL

    readonly attribute BluetoothClassDeviceService deviceService; BluetoothAdapter getDefaultAdapter() raises(WebAPIException); BluetoothLEAdapter getLEAdapter() raises(WebAPIException); + BluetoothGATTServer getGATTServer() raises(WebAPIException); byte[] toByteArray(Bytes data) raises(WebAPIException); DOMString toDOMString(Bytes data) raises(WebAPIException); Uint8Array toUint8Array(Bytes data) raises(WebAPIException); @@ -7515,18 +10107,25 @@

    4. Full WebIDL

    [NoInterfaceObject] interface BluetoothLEAdapter { void startScan(BluetoothLEScanCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void stopScan() raises(WebAPIException); + boolean isScanning() raises(WebAPIException); void startAdvertise(BluetoothLEAdvertiseData advertiseData, BluetoothAdvertisePacketType packetType, BluetoothLEAdvertiseCallback successCallback, optional ErrorCallback? errorCallback, optional BluetoothAdvertisingMode? mode, optional boolean? connectable) raises(WebAPIException); void stopAdvertise() raises(WebAPIException); + long addConnectStateChangeListener(BluetoothLEConnectChangeCallback listener) raises(WebAPIException); + void removeConnectStateChangeListener(long watchID); }; [NoInterfaceObject] interface BluetoothGATTService { readonly attribute BluetoothUUID? serviceUuid; - readonly attribute BluetoothGATTService[] services; - readonly attribute BluetoothGATTCharacteristic[] characteristics; + readonly attribute BluetoothGATTServiceVariant[] services; + readonly attribute BluetoothGATTCharacteristicVariant[] characteristics; + }; + [NoInterfaceObject] interface BluetoothGATTServerService : BluetoothGATTService { + readonly attribute boolean isPrimary; + void unregister(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); }; [NoInterfaceObject] interface BluetoothGATTCharacteristic { - readonly attribute BluetoothGATTDescriptor[] descriptors; + readonly attribute BluetoothGATTDescriptorVariant[] descriptors; readonly attribute boolean isBroadcast; readonly attribute boolean hasExtendedProperties; readonly attribute boolean isNotify; @@ -7542,12 +10141,54 @@

    4. Full WebIDL

    long addValueChangeListener(ReadValueSuccessCallback callback) raises(WebAPIException); void removeValueChangeListener(long watchID); }; + [NoInterfaceObject] interface BluetoothGATTServerCharacteristic : BluetoothGATTCharacteristic { + readonly attribute boolean readPermission; + readonly attribute boolean writePermission; + readonly attribute boolean encryptedReadPermission; + readonly attribute boolean encryptedWritePermission; + readonly attribute boolean encryptedSignedReadPermission; + readonly attribute boolean encryptedSignedWritePermission; + void notifyAboutValueChange(Bytes value, BluetoothAddress? clientAddress, optional NotificationCallback? notificationCallback, + optional ErrorCallback? errorCallback) raises(WebAPIException); + void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback, + optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, + optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException); + void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback, + optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, + optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException); + }; [NoInterfaceObject] interface BluetoothGATTDescriptor { readonly attribute BluetoothUUID? uuid; void readValue(ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void writeValue(Bytes value, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); }; + [NoInterfaceObject] interface BluetoothGATTServerDescriptor : BluetoothGATTDescriptor { + readonly attribute boolean readPermission; + readonly attribute boolean writePermission; + readonly attribute boolean encryptedReadPermission; + readonly attribute boolean encryptedWritePermission; + readonly attribute boolean encryptedSignedReadPermission; + readonly attribute boolean encryptedSignedWritePermission; + void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback, + optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, + optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException); + void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback, + optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, + optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException); + }; + [NoInterfaceObject] interface BluetoothGATTServer { + readonly attribute boolean isRunning; + readonly attribute BluetoothGATTServerService[] services; + void start(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); + void stop(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); + void registerService(BluetoothGATTServerServiceInit service, optional SuccessCallback? successCallback, + optional ErrorCallback? errorCallback) raises(WebAPIException); + void unregisterAllServices(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) + raises(WebAPIException); + void getConnectionMtu(BluetoothAddress clientAddress, ConnectionMtuCallback callback, optional ErrorCallback? errorCallback) + raises(WebAPIException); + }; [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothLEScanCallback { void onsuccess(BluetoothLEDevice device); }; @@ -7561,6 +10202,25 @@

    4. Full WebIDL

    [Callback=FunctionOnly, NoInterfaceObject] interface ReadValueSuccessCallback { void onread(byte[] value); }; + [Constructor(long statusCode = 0, optional Bytes data)] + interface GATTRequestReply { + attribute long statusCode; + attribute Bytes? data; + }; + [Callback=FunctionOnly, NoInterfaceObject] interface ReadValueRequestCallback { + GATTRequestReply? onreadrequest(BluetoothAddress clientAddress, long offset); + }; + [Callback=FunctionOnly, NoInterfaceObject] interface WriteValueRequestCallback { + GATTRequestReply? onwriterequest(BluetoothAddress clientAddress, byte[] value, long offset, boolean replyRequired); + }; + [Callback=FunctionOnly, NoInterfaceObject] interface NotificationCallback { + void onnotificationsuccess(BluetoothAddress clientAddress); + void onnotificationfail(BluetoothAddress clientAddress, WebAPIException error); + void onnotificationfinish(BluetoothAddress clientAddress); + }; + [Callback=FunctionOnly, NoInterfaceObject] interface ConnectionMtuCallback { + void onsuccess(long mtu); + }; [NoInterfaceObject] interface BluetoothDevice { readonly attribute DOMString name; readonly attribute BluetoothAddress address; @@ -7581,13 +10241,18 @@

    4. Full WebIDL

    readonly attribute BluetoothLESolicitationUUID[]? solicitationuuids; readonly attribute BluetoothLEServiceData[]? serviceData; readonly attribute BluetoothLEManufacturerData? manufacturerData; - readonly attribute long rssi; + readonly attribute long? rssi; void connect(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void disconnect(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); + boolean isConnected() raises(WebAPIException); BluetoothGATTService getService(BluetoothUUID uuid) raises(WebAPIException); BluetoothUUID[] getServiceAllUuids() raises(WebAPIException); long addConnectStateChangeListener(BluetoothLEConnectChangeCallback listener) raises(WebAPIException); void removeConnectStateChangeListener(long watchID); + unsigned long getAttMtu() raises(WebAPIException); + void requestAttMtuChange(unsigned long newAttMtu) raises(WebAPIException); + long addAttMtuChangeListener(ConnectionMtuCallback callback) raises(WebAPIException); + void removeAttMtuChangeListener(long watchId) raises(WebAPIException); }; [NoInterfaceObject] interface BluetoothSocket { readonly attribute BluetoothUUID uuid; diff --git a/docs/application/web/api/6.0/device_api/tv/tizen/bluetooth.html b/docs/application/web/api/6.0/device_api/tv/tizen/bluetooth.html index 05ed335c50..d1bacb7df0 100644 --- a/docs/application/web/api/6.0/device_api/tv/tizen/bluetooth.html +++ b/docs/application/web/api/6.0/device_api/tv/tizen/bluetooth.html @@ -32,6 +32,8 @@ Advertise for remote devices (including Bluetooth LE devices)
  • Act as a GATT client (Generic Attribute Profile client)
  • +
  • +Configure the local GATT server (Generic Attribute Profile)
  • For more information on the Bluetooth features, see Bluetooth Guide. @@ -67,6 +69,15 @@

    Table of Contents

  • 1.8. Bytes
  • +
  • + 1.9. BluetoothGATTServiceVariant +
  • +
  • + 1.10. BluetoothGATTCharacteristicVariant +
  • +
  • + 1.11. BluetoothGATTDescriptorVariant +
  • 2. Interfaces
  • @@ -170,6 +205,8 @@

    Summary of Interfaces and Methods

    BluetoothAdapter getDefaultAdapter ()
    BluetoothLEAdapter getLEAdapter ()
    +
    +BluetoothGATTServer getGATTServer ()
    byte[] toByteArray (Bytes data)
    DOMString toDOMString (Bytes data)
    @@ -201,8 +238,11 @@

    Summary of Interfaces and Methods

    void startScan (BluetoothLEScanCallback successCallback, optional ErrorCallback? errorCallback)
    void stopScan ()
    +
    boolean isScanning ()
    void startAdvertise (BluetoothLEAdvertiseData advertiseData, BluetoothAdvertisePacketType packetType, BluetoothLEAdvertiseCallback successCallback, optional ErrorCallback? errorCallback, optional BluetoothAdvertisingMode? mode, optional boolean? connectable)
    void stopAdvertise ()
    +
    long addConnectStateChangeListener (BluetoothLEConnectChangeCallback listener)
    +
    void removeConnectStateChangeListener (long watchID)
    @@ -210,6 +250,14 @@

    Summary of Interfaces and Methods

    +BluetoothGATTServerServiceInit + + + +BluetoothGATTServerService +
    void unregister (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    + + BluetoothGATTCharacteristic
    void readValue (ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback)
    @@ -219,6 +267,18 @@

    Summary of Interfaces and Methods

    +BluetoothGATTServerCharacteristicInit + + + +BluetoothGATTServerCharacteristic + +
    void notifyAboutValueChange (Bytes value, BluetoothAddress? clientAddress, optional NotificationCallback? notificationCallback, optional ErrorCallback? errorCallback)
    +
    void setReadValueRequestCallback (ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, optional ErrorCallback? sendResponseErrorCallback)
    +
    void setWriteValueRequestCallback (WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, optional ErrorCallback? sendResponseErrorCallback)
    + + + BluetoothGATTDescriptor
    void readValue (ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback)
    @@ -226,6 +286,27 @@

    Summary of Interfaces and Methods

    +BluetoothGATTServerDescriptorInit + + + +BluetoothGATTServerDescriptor + +
    void setReadValueRequestCallback (ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, optional ErrorCallback? sendResponseErrorCallback)
    +
    void setWriteValueRequestCallback (WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, optional ErrorCallback? sendResponseErrorCallback)
    + + + +BluetoothGATTServer + +
    void start (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +
    void stop (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +
    void registerService (BluetoothGATTServerServiceInit service, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +
    void unregisterAllServices (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +
    void getConnectionMtu (BluetoothAddress clientAddress, ConnectionMtuCallback callback, optional ErrorCallback? errorCallback)
    + + + BluetoothLEScanCallback
    void onsuccess (BluetoothLEDevice device)
    @@ -245,6 +326,32 @@

    Summary of Interfaces and Methods

    void onread (byte[] value)
    +GATTRequestReply + + + +ReadValueRequestCallback +
    +GATTRequestReply? onreadrequest (BluetoothAddress clientAddress, long offset)
    + + +WriteValueRequestCallback +
    +GATTRequestReply? onwriterequest (BluetoothAddress clientAddress, byte[] value, long offset, boolean replyRequired)
    + + +NotificationCallback + +
    void onnotificationsuccess (BluetoothAddress clientAddress)
    +
    void onnotificationfail (BluetoothAddress clientAddress, WebAPIException error)
    +
    void onnotificationfinish (BluetoothAddress clientAddress)
    + + + +ConnectionMtuCallback +
    void onsuccess (long mtu)
    + + BluetoothDevice
    void connectToServiceByUUID (BluetoothUUID uuid, BluetoothSocketSuccessCallback successCallback, optional ErrorCallback? errorCallback)
    @@ -253,12 +360,17 @@

    Summary of Interfaces and Methods

    void connect (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    void disconnect (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +
    boolean isConnected ()
    BluetoothGATTService getService (BluetoothUUID uuid)
    BluetoothUUID[] getServiceAllUuids ()
    long addConnectStateChangeListener (BluetoothLEConnectChangeCallback listener)
    void removeConnectStateChangeListener (long watchID)
    +
    unsigned long getAttMtu ()
    +
    void requestAttMtuChange (unsigned long newAttMtu)
    +
    long addAttMtuChangeListener (ConnectionMtuCallback callback)
    +
    void removeAttMtuChangeListener (long watchId)
    @@ -464,6 +576,36 @@

    1. Type Definitions

    6.0

    +
    +

    1.9. BluetoothGATTServiceVariant

    +
    + The type of objects which are either BluetoothGATTService or BluetoothGATTServerService, depending on the context in which they appear. +
    +
      typedef (BluetoothGATTService or BluetoothGATTServerService) BluetoothGATTServiceVariant;
    +

    Since: + 6.0 +

    +
    +
    +

    1.10. BluetoothGATTCharacteristicVariant

    +
    + The type of objects which are either BluetoothGATTCharacteristic or BluetoothGATTServerCharacteristic, depending on the context in which they appear. +
    +
      typedef (BluetoothGATTCharacteristic or BluetoothGATTServerCharacteristic) BluetoothGATTCharacteristicVariant;
    +

    Since: + 6.0 +

    +
    +
    +

    1.11. BluetoothGATTDescriptorVariant

    +
    + The type of objects which are either BluetoothGATTDescriptor or BluetoothGATTServerDescriptor, depending on the context in which they appear. +
    +
      typedef (BluetoothGATTDescriptor or BluetoothGATTServerDescriptor) BluetoothGATTDescriptorVariant;
    +

    Since: + 6.0 +

    +

    2. Interfaces

    @@ -645,7 +787,7 @@

    Attributes

    BluetoothLESolicitationUUID[]? solicitationuuids; unsigned long? appearance; boolean? includeTxPowerLevel; - BluetoothLEServiceData? serviceData; + BluetoothLEServiceData[]? servicesData; BluetoothLEManufacturerData? manufacturerData; };

    Since: @@ -680,7 +822,7 @@

    Attributes

    attribute BluetoothLESolicitationUUID[]? solicitationuuids; attribute unsigned long? appearance; attribute boolean? includeTxPowerLevel; - attribute BluetoothLEServiceData? serviceData; + attribute BluetoothLEServiceData[]? servicesData; attribute BluetoothLEManufacturerData? manufacturerData; };

    Since: @@ -816,20 +958,26 @@

    Attributes

    -
  • -BluetoothLEServiceData serviceData [nullable]
    - The service data for advertise or scan response data. +
  • +BluetoothLEServiceData[] + servicesData [nullable]
    + The array of objects representing service data for advertise.

    Since: 6.0

    Remark: - Only 16-bit BluetoothLEServiceData::uuid values can be advertised. + Only 16-bit BluetoothLEServiceData::uuid values can be advertised. Duplicated uuid values in servicesData are not allowed for advertising. +

    +

    Remark: + If this attribute is in neither null nor undefined, the value of deprecated BluetoothLEAdvertiseData::serviceData attribute is ignored.

    Code example:

    var advertise = new tizen.BluetoothLEAdvertiseData();
    -var service = new tizen.BluetoothLEServiceData("11e5", "0x1811");
    -advertise.serviceData = service;
    +
    +var firstService = new tizen.BluetoothLEServiceData("11e5", "0x1811");
    +var secondService = new tizen.BluetoothLEServiceData("a5e8", "0x1815");
    +advertise.servicesData = [firstService, secondService];
     
  • @@ -862,6 +1010,7 @@

    Attributes

    readonly attribute BluetoothClassDeviceService deviceService; BluetoothAdapter getDefaultAdapter() raises(WebAPIException); BluetoothLEAdapter getLEAdapter() raises(WebAPIException); + BluetoothGATTServer getGATTServer() raises(WebAPIException); byte[] toByteArray(Bytes data) raises(WebAPIException); DOMString toDOMString(Bytes data) raises(WebAPIException); Uint8Array toUint8Array(Bytes data) raises(WebAPIException); @@ -1033,6 +1182,50 @@

    Methods

    +
    +getGATTServer +
    +
    +
    + Gets the BluetoothGATTServer object, which allows starting, stopping the local GATT server, and configuring its services. +
    +
    BluetoothGATTServer getGATTServer();
    +

    Since: + 6.0 +

    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Return value:

    + +
    +
    +

    Exceptions:

    + +
    +
    +

    Code example:

    var server = tizen.bluetooth.getGATTServer();
    +
    +
    +
    toByteArray
    @@ -1083,15 +1276,20 @@

    Methods

    Code example:

    var dataInt8Array = new Int8Array([-21, 31]);
     var dataUint8Array = new Uint8Array([240, 129]);
     var dataString = "0x18b1";
    -console.log("converted from Int8Array: " + tizen.bluetooth.toByteArray(dataInt8Array));
    -console.log("converted from Uint8Array: " + tizen.bluetooth.toByteArray(dataUint8Array));
    -console.log("converted from DOMString: " + tizen.bluetooth.toByteArray(dataString));
    +
    +var fromInt8Array = tizen.bluetooth.toByteArray(dataInt8Array);
    +var fromUint8Array = tizen.bluetooth.toByteArray(dataUint8Array);
    +var fromString = tizen.bluetooth.toByteArray(dataString);
    +
    +console.log("converted from Int8Array: " + JSON.stringify(fromInt8Array));
    +console.log("converted from Uint8Array: " + JSON.stringify(fromUint8Array));
    +console.log("converted from DOMString: " + JSON.stringify(fromString));
     
    -

    Output example:

    converted from Int8Array: Int8Array(2) [-21, 31]
    -converted from Uint8Array: Int8Array(2) [-16, -127]
    -converted from DOMString: Int8Array(2) [24, -79]
    +

    Output example:

    converted from Int8Array: [235, 31]
    +converted from Uint8Array: [240, 129]
    +converted from DOMString: [244, 177]
     
    @@ -1195,15 +1393,20 @@

    Methods

    Code example:

    var dataInt8Array = new Int8Array([-21, 31]);
     var dataUint8Array = new Uint8Array([240, 129]);
     var dataString = "0x18b1";
    -console.log("converted from Int8Array: " + tizen.bluetooth.toUint8Array(dataInt8Array));
    -console.log("converted from Uint8Array: " + tizen.bluetooth.toUint8Array(dataUint8Array));
    -console.log("converted from DOMString: " + tizen.bluetooth.toUint8Array(dataString));
    +
    +var fromInt8Array = tizen.bluetooth.toUint8Array(dataInt8Array);
    +var fromUint8Array = tizen.bluetooth.toUint8Array(dataUint8Array);
    +var fromString = tizen.bluetooth.toUint8Array(dataString);
    +
    +console.log("converted from Int8Array: " + JSON.stringify(fromInt8Array));
    +console.log("converted from Uint8Array: " + JSON.stringify(fromUint8Array));
    +console.log("converted from DOMString: " + JSON.stringify(fromString));
     
    -

    Output example:

    converted from Int8Array: Uint8Array(2) [235, 31]
    -converted from Uint8Array: Uint8Array(2) [240, 129]
    -converted from DOMString: Uint8Array(2) [24, 177]
    +

    Output example:

    converted from Int8Array: {"0":235, "1":31}
    +converted from Uint8Array: {"0":240, "1":129}
    +converted from DOMString: {"0":24, "1":177}
     
    @@ -1242,9 +1445,13 @@

    Methods

    -

    Code example:

    tizen.bluetooth.uuidTo128bit("1234");
    -tizen.bluetooth.uuidTo128bit("ab5690ef");
    -tizen.bluetooth.uuidTo128bit("abcdef01-2345-6789-abcd-ef0123456789");
    +

    Code example:

    var uuidFrom16bits = tizen.bluetooth.uuidTo128bit("1234");
    +var uuidFrom32bits = tizen.bluetooth.uuidTo128bit("ab5690ef");
    +var uuidFrom128bits = tizen.bluetooth.uuidTo128bit("abcdef01-2345-6789-abcd-ef0123456789");
    +
    +console.log(uuidFrom16bits);
    +console.log(uuidFrom32bits);
    +console.log(uuidFrom128bits);
     
    @@ -2547,10 +2754,13 @@

    Methods

      [NoInterfaceObject] interface BluetoothLEAdapter {
         void startScan(BluetoothLEScanCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
         void stopScan() raises(WebAPIException);
    +    boolean isScanning() raises(WebAPIException);
         void startAdvertise(BluetoothLEAdvertiseData advertiseData, BluetoothAdvertisePacketType packetType,
                             BluetoothLEAdvertiseCallback successCallback, optional ErrorCallback? errorCallback,
                             optional BluetoothAdvertisingMode? mode, optional boolean? connectable) raises(WebAPIException);
         void stopAdvertise() raises(WebAPIException);
    +    long addConnectStateChangeListener(BluetoothLEConnectChangeCallback listener) raises(WebAPIException);
    +    void removeConnectStateChangeListener(long watchID);
       };

    Since: 6.0 @@ -2677,6 +2887,56 @@

    Methods

    +
    +isScanning +
    +
    +
    + Checks if scanning for Bluetooth Low Energy devices is currently in progress. +
    +
    boolean isScanning();
    +

    Since: + 6.0 +

    +
    +

    Return value:

    + +
    +
    +

    Exceptions:

    + +
    +
    +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
    +var scanningStarted = adapter.isScanning();
    +console.log("Scanning status: " + scanningStarted);
    +if (!scanningStarted)
    +{
    +  adapter.startScan(function onsuccess(device)
    +  {
    +    console.log("Scanning status: " + adapter.isScanning());
    +    adapter.stopScan();
    +  });
    +}
    +
    +
    +
    +

    Output example:

    Scanning status: false
    +Scanning status: true
    +
    +
    +
    startAdvertise
    @@ -2756,6 +3016,9 @@

    Methods

  • with error type QuotaExceededError, if any input attribute is not compatible with the maximum data size for this attribute.

  • +
  • + with error type InvalidValuesError, if advertising services data contains duplicated UUIDs. +

  • with error type InvalidStateError, if device is currently in progress of advertising, if the local Bluetooth le adapter is currently not enabled.

  • @@ -2856,18 +3119,148 @@

    Methods

    +
    +addConnectStateChangeListener +
    +
    +
    + Registers a listener that is called whenever a GATT connection with another device is established or terminated. +
    +
    long addConnectStateChangeListener(BluetoothLEConnectChangeCallback listener);
    +

    Since: + 6.0 +

    +
    +

    +The BluetoothLEConnectChangeCallback, registered with this function, is called in the following cases: +

    + +
    +
    +

    Parameters:

    + +
    +
    +

    Return value:

    + +
    +
    +

    Exceptions:

    + +
    +
    +

    Code example:

    /* This application is running the local GATT Server and does not connect to remote GATT servers. */
    +/* To be able to notify connected clients about characteristic values' changes, it saves their data. */
    +var connectedClients = [];
    +
    +function onConnected(device)
    +{
    +  console.log("A client connected: " + device.address);
    +  connectedClients.push(device);
    +}
    +
    +function onDisconnected(device)
    +{
    +  console.log("A client disconnected: " + device.address);
    +  connectedClients = connectedClients.filter(function(connectedClient)
    +  {
    +    return connectedClient.address !== device.address;
    +  });
    +}
    +
    +tizen.bluetooth.getLEAdapter().addConnectStateChangeListener(
    +    {onconnected: onConnected, ondisconnected: onDisconnected});
    +
    +
    +
    +

    Output example:

    A client connected: 6A:33:B1:17:D4:81
    +A client connected: 4B:1F:DD:35:41:19
    +A client connected: CC:D4:11:E5:72:4B
    +A client disconnected: 6A:33:B1:17:D4:81
    +
    +
    +
    +
    +removeConnectStateChangeListener +
    +
    +
    + Unregisters a listener called whenever a GATT connection with another device is established or terminated. +
    +
    void removeConnectStateChangeListener(long watchID);
    +

    Since: + 6.0 +

    +
    +

    +This function unregisters a BluetoothLEConnectChangeCallback registered with BluetoothLEAdapter.addConnectStateChangeListener() method. +

    +
    +
    +

    Parameters:

    + +
    +
    +

    Code example:

    /* This application is running the local GATT Server and does not connect to remote GATT servers. */
    +function onConnected(device)
    +{
    +  console.log("A client connected: " + device.address);
    +}
    +
    +function onDisconnected(device)
    +{
    +  console.log("A client disconnected: " + device.address);
    +}
    +
    +/* Save watchId to be able to remove the listener later */
    +var watchId = tizen.bluetooth.getLEAdapter().addConnectStateChangeListener(
    +    {onconnected: onConnected, ondisconnected: onDisconnected});
    +
    +/* A little later, the listener is no longer needed, and can be removed with */
    +/* removeConnectStateChangeListener(watchId) method */
    +
    +
    +
    +

    Output example:

    A client connected: 6A:33:B1:17:D4:81
    +A client connected: 4B:1F:DD:35:41:19
    +A client connected: CC:D4:11:E5:72:4B
    +A client disconnected: 6A:33:B1:17:D4:81
    +
    +
    +

    2.9. BluetoothGATTService

    - Bluetooth Low Energy Service. The service can be retrieved with BluetoothLEDevice.getService(). + Bluetooth Low Energy service. The service can be retrieved with BluetoothLEDevice::getService().
      [NoInterfaceObject] interface BluetoothGATTService {
         readonly attribute BluetoothUUID? serviceUuid;
    -    readonly attribute BluetoothGATTService[] services;
    -    readonly attribute BluetoothGATTCharacteristic[] characteristics;
    +    readonly attribute BluetoothGATTServiceVariant[] services;
    +    readonly attribute BluetoothGATTCharacteristicVariant[] characteristics;
       };

    Since: 6.0 @@ -2917,13 +3310,16 @@

    Attributes

  • readonly -BluetoothGATTService[] +BluetoothGATTServiceVariant[] services
    A list of services included in this service.

    Since: 6.0

    +

    Remark: + It can be either type BluetoothGATTService for services retrieved from remote GATT servers or type BluetoothGATTServerService for services retrieved from the local GATT server. +

    Code example:

    var service = device.getService(device.uuids[0]);
     for (var i = 0; i < service.services.length; ++i)
    @@ -2935,13 +3331,16 @@ 

    Attributes

  • readonly -BluetoothGATTCharacteristic[] +BluetoothGATTCharacteristicVariant[] characteristics
    A list of characteristics in this service.

    Since: 6.0

    +

    Remark: + It can be either type BluetoothGATTCha racteristic for characteristics retrieved from services of remote GATT servers or type BluetoothGATTServerCharacteristic for characteristics retrieved from services of local GATT server. +

    Code example:

    var service = device.getService(device.uuids[0]);
     for (var i = 0; i < service.characteristics.length; ++i)
    @@ -2954,14 +3353,155 @@ 

    Attributes

  • -
    -

    2.10. BluetoothGATTCharacteristic

    +
    +

    2.10. BluetoothGATTServerServiceInit

    - A characteristic provided by Bluetooth Low Energy service. + A dictionary for specifying GATT service parameters.
    -
      [NoInterfaceObject] interface BluetoothGATTCharacteristic {
    -    readonly attribute BluetoothGATTDescriptor[] descriptors;
    -    readonly attribute boolean isBroadcast;
    +
      dictionary BluetoothGATTServerServiceInit {
    +    BluetoothUUID serviceUuid;
    +    boolean isPrimary = true;
    +    BluetoothGATTServerServiceInit[]? includedServices = null;
    +    BluetoothGATTServerCharacteristicInit[]? characteristics = null;
    +  };
    +

    Since: + 6.0 +

    +
    +

    +This dictionary defines the GATT services to be registered to the local GATT server. +

    +
    +
    +

    Code example:

    /* serviceA and serviceB are objects of type BluetoothGATTServerServiceInit. */
    +/* hrmCharacteristic is a BluetoothGATTServerCharacteristicInit object. */
    +var serviceParameters =
    +{
    +  serviceUuid: "4b102e75",
    +  isPrimary: true,
    +  includedServices: [serviceA, serviceB],
    +  characteristics: [hrmCharacteristic]
    +};
    +
    +
    +
    +
    +

    2.11. BluetoothGATTServerService

    +
    + The class representing a Bluetooth GATT service provided by the local GATT server. +
    +
      [NoInterfaceObject] interface BluetoothGATTServerService : BluetoothGATTService {
    +    readonly attribute boolean isPrimary;
    +    void unregister(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +  };
    +

    Since: + 6.0 +

    + +
    +

    Attributes

    +
    • + readonly +boolean isPrimary
      + Flag indicating whether the service is primary or secondary. +
      +

      Since: + 6.0 +

      +
    +
    +
    +

    Methods

    +
    +
    +unregister +
    +
    +
    + Unregisters the service and all its characteristics from the local GATT server. +
    +
    void unregister(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • + InvalidStateError - If the service cannot be unregistered in the current state of the GATT server.
    • +
    • + AbortError - If any other error occurs
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +

    Remark: + GATT services included in other GATT services cannot be unregistered. +

    +

    Remark: + If this method is called for the only GATT service, currently registered in the local running GATT server, the server stops running. +

    +
    +

    Parameters:

    +
      +
    • +successCallback [optional] [nullable]: + Callback function that is called when the service is successfully unregistered from the local GATT server. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      • + with error type AbortError, if any other error occurs. +

      • +
      +
    +
    +
    +

    Code example:

    /* The service has been registered in the GATT server for a while. Now it is no longer needed. */
    +function onsuccess()
    +{
    +  console.log("Service unregistered");
    +}
    +
    +function onerror(error)
    +{
    +  console.log("Failed to unregister service: " + error.message);
    +}
    +
    +tizen.bluetooth.getGATTServer().services[0].unregister(onsuccess, onerror);
    +
    +
    +
    +
    +
    +
    +
    +

    2.12. BluetoothGATTCharacteristic

    +
    + A characteristic provided by Bluetooth Low Energy service. +
    +
      [NoInterfaceObject] interface BluetoothGATTCharacteristic {
    +    readonly attribute BluetoothGATTDescriptorVariant[] descriptors;
    +    readonly attribute boolean isBroadcast;
         readonly attribute boolean hasExtendedProperties;
         readonly attribute boolean isNotify;
         readonly attribute boolean isIndication;
    @@ -2984,13 +3524,16 @@ 

    Attributes

    • readonly -BluetoothGATTDescriptor[] +BluetoothGATTDescriptorVariant[] descriptors
      A list of descriptors in this characteristic.

      Since: 6.0

      +

      Remark: + The type of this field is BluetoothGATTDescriptor for descriptors of characteristics retrieved from services of remote GATT servers and BluetoothGATTServerDescriptor for descriptors of characteristics retrieved from the services of local GATT server. +

    • readonly @@ -3107,6 +3650,9 @@

      Methods

      Privilege: http://tizen.org/privilege/bluetooth

      +

      Remark: + BluetothGATTServerCharacteristic objects do not support this function. An attempt to call it for such an object will result in an exception. +

      Parameters:

        @@ -3132,6 +3678,9 @@

        Methods

      • with error type SecurityError, if the application does not have the privilege to call this method.

      • +
      • + with error type NotSupportedError, if the method is called for BluetoothGATTServerCharacteristic. +

    @@ -3197,6 +3746,9 @@

    Methods

    Privilege: http://tizen.org/privilege/bluetooth

    +

    Remark: + BluetothGATTServerCharacteristic objects do not support this function. An attempt to call it for such an object will result in an exception. +

    Parameters:

    @@ -3288,6 +3843,9 @@

    Methods

    Privilege: http://tizen.org/privilege/bluetooth

    +

    Remark: + BluetothGATTServerCharacteristic objects do not support this function. An attempt to call it for such an object will result in an exception. +

    Parameters:

    Exceptions:

    -
    @@ -3365,6 +3928,9 @@

    Methods

    Remark: Example of using can be find at addValueChangeListener code example.

    +

    Remark: + Value change listeners cannot be registered and thus unregistered for BluetothGATTServerCharacteristic objects. An attempt to remove value change listener for such an object will result in no operation. +

    Parameters:

      @@ -3378,56 +3944,200 @@

      Methods

    -
    -

    2.11. BluetoothGATTDescriptor

    +
    +

    2.13. BluetoothGATTServerCharacteristicInit

    - Bluetooth Low Energy Descriptor. + A dictionary for specifying GATT characteristic parameters.
    -
      [NoInterfaceObject] interface BluetoothGATTDescriptor {
    -    readonly attribute BluetoothUUID? uuid;
    -    void readValue(ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    -    void writeValue(Bytes value, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    -                    raises(WebAPIException);
    +
      dictionary BluetoothGATTServerCharacteristicInit {
    +    BluetoothUUID uuid;
    +    BluetoothGATTServerDescriptorInit[]? descriptors = null;
    +    boolean isBroadcast = false;
    +    boolean hasExtendedProperties = false;
    +    boolean isNotify = false;
    +    boolean isIndication = false;
    +    boolean isReadable = false;
    +    boolean isSignedWrite = false;
    +    boolean isWritable = false;
    +    boolean isWriteNoResponse = false;
    +    boolean readPermission = false;
    +    boolean writePermission = false;
    +    boolean encryptedReadPermission = false;
    +    boolean encryptedWritePermission = false;
    +    boolean encryptedSignedReadPermission = false;
    +    boolean encryptedSignedWritePermission = false;
    +    ReadValueRequestCallback? readValueRequestCallback = null;
    +    SuccessCallback? readValueSendResponseSuccessCallback = null;
    +    ErrorCallback? readValueSendResponseErrorCallback = null;
    +    WriteValueRequestCallback? writeValueRequestCallback = null;
    +    SuccessCallback? writeValueSendResponseSuccessCallback = null;
    +    ErrorCallback? writeValueSendResponseErrorCallback = null;
       };

    Since: 6.0

    -
    +
    +

    +This dictionary is used as a definition of a characteristic to be registered in a service of the local GATT server.
    readValueRequestCallback and writeValueRequestCallback are callbacks called when a client reads or writes the value of the characteristic respectively. They can be set or replaced with another functions, after registering the service containing the characteristic, with BluetoothGATTServerCharacteristic.setReadValueRequestCallback() and BluetoothGATTServerCharacteristic.setWriteValueRequestCallback().
    readValueSendResponseSuccessCallback and writeValueSendResponseSuccessCallback are success callbacks called when a response sent from readValueRequestCallback or writeValueRequestCallback reaches client. They can be set or replaced with another functions, after registering the service containing the characteristic, with BluetoothGATTServerCharacteristic.setReadValueRequestCallback() and BluetoothGATTServerCharacteristic.setWriteValueRequestCallback().
    readValueSendResponseErrorCallback and writeValueSendResponseErrorCallback are error callbacks called when an attempt to send a response to a client from readValueRequestCallback or writeValueRequestCallback fails. They can be set or replaced with another functions, after registering the service containing the characteristic, with BluetoothGATTServerCharacteristic.setReadValueRequestCallback() and BluetoothGATTServerCharacteristic.setWriteValueRequestCallback(). +

    +
    +
    +

    Code example:

    /* nameDescriptor, placeDescriptor are BluetoothGATTServerDescriptorInit objects */
    +/* readValueCallback, writeValueCallback are read/write request callbacks */
    +/* readValueSendResponseSuccessCallback and writeValueSendResponseSuccessCallback */
    +/* are success callbacks */
    +/* and writeValueSendResponseErrorCallback and readValueSendResponseErrorCallback */
    +/* are error callbacks */
    +var characteristicParameters =
    +{
    +  uuid: "0180",
    +  descriptors: [nameDescriptor, placeDescriptor],
    +  /* Characteristic's properties */
    +  isBroadcast: false,
    +  hasExtendedProperties: false,
    +  isNotify: false,
    +  isIndication: false,
    +  isReadable: true,
    +  isSignedWrite: false,
    +  isWritable: true,
    +  isWriteNoResponse: false,
    +  /* Characteristic's permissions */
    +  readPermission: true,
    +  writePermission: true,
    +  encryptedReadPermission: false,
    +  encryptedWritePermission: false,
    +  encryptedSignedReadPermission: false,
    +  encryptedSignedWritePermission: false,
    +  readValueRequestCallback: readValueCallback,
    +  readValueSendResponseSuccessCallback: readValueSendResponseSuccessCallback,
    +  readValueSendResponseErrorCallback: readValueSendResponseErrorCallback,
    +  writeValueRequestCallback: writeValueCallback,
    +  writeValueSendResponseSuccessCallback: writeValueSendResponseSuccessCallback,
    +  writeValueSendResponseErrorCallback: writeValueSendResponseErrorCallback
    +};
    +
    +
    +
    +
    +

    2.14. BluetoothGATTServerCharacteristic

    +
    + A subclass representing GATT characteristic used to construct a service of the local Bluetooth GATT server. +It extends BluetoothGATTCharacteristic with permissions and methods implementing interactions of the characteristic with remote clients. +
    +
      [NoInterfaceObject] interface BluetoothGATTServerCharacteristic : BluetoothGATTCharacteristic {
    +    readonly attribute boolean readPermission;
    +    readonly attribute boolean writePermission;
    +    readonly attribute boolean encryptedReadPermission;
    +    readonly attribute boolean encryptedWritePermission;
    +    readonly attribute boolean encryptedSignedReadPermission;
    +    readonly attribute boolean encryptedSignedWritePermission;
    +    void notifyAboutValueChange(Bytes value, BluetoothAddress? clientAddress, optional NotificationCallback? notificationCallback,
    +                                optional ErrorCallback? errorCallback) raises(WebAPIException);
    +    void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback,
    +                                     optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                     optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException);
    +    void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback,
    +                                      optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                      optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException);
    +  };
    +

    Since: + 6.0 +

    + +

    Attributes

    -
    • +
        +
      • readonly -BluetoothUUID uuid [nullable]
        - UUID of the descriptor. +boolean readPermission
        + Indicates if clients have the permission to read the value of the characteristic.

        Since: 6.0

        -

        Remark: - uuid is set to null, if the value cannot be retrieved. +

      • +
      • + readonly +boolean writePermission
        + Indicates if clients have the permission to write the value of the characteristic. +
        +

        Since: + 6.0

        -
      +
    • +
    • + readonly +boolean encryptedReadPermission
      + Indicates if clients have the permission to read the value of the characteristic through encrypted connections. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedWritePermission
      + Indicates if clients have the permission to write the value of the characteristic through encrypted connections. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedSignedReadPermission
      + Indicates if clients have the permission to perform signed reads of the characteristic's value. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedSignedWritePermission
      + Indicates if clients have the permission to perform signed writes of the characteristic's value. +
      +

      Since: + 6.0 +

      +
    • +

    Methods

    -
    -readValue +
    +notifyAboutValueChange
    - Reads descriptor value from remote device. Updates descriptor value attribute. + Notifies the clients of the local GATT server of the changes in the characteristic.
    -
    void readValue(ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback);
    +
    void notifyAboutValueChange(Bytes value, BluetoothAddress? clientAddress, optional NotificationCallback? notificationCallback,
    +                            optional ErrorCallback? errorCallback);

    Since: 6.0

    +This function sends a BLE notification or indication about a change of characteristic's value to clients that registered for it. If a particular client is specified, only he gets the update. +Otherwise it is sent to all clients connected to the local GATT server, who registered for the updates.

    +

    +Clients can only register for characteristic's notifications or indications, if the characteristic defines a Client Characteristic Configuration Descriptor (CCCD), as described in the Bluetooth standard. +CCCD has to be defined as any other descriptor, using BluetoothGATTServerDescriptorInit. +

    +
    +
    +

    The ErrorCallback is launched with these error types:

    • -UnknownError - If any other error occurs
    • + InvalidValuesError - If any of the parameters is invalid. +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.

    Privilege level: @@ -3436,16 +4146,27 @@

    Methods

    Privilege: http://tizen.org/privilege/bluetooth

    +

    Remark: + To notify the clients the service with current characteristic must be registered (see BluetoothGATTServer::registerService()) and available for clients (see BluetoothGATTServer::start()). +

    Parameters:

    • -successCallback: - Callback function that is called when the descriptor value is read successfully. +value: + The new value of the characteristic. +
    • +
    • +clientAddress [nullable]: + The address of the client to be notified about the value change. If a null is passed, all clients will be notified. +
    • +
    • +notificationCallback [optional] [nullable]: + The callback called for each attempt of a client notification.
    • errorCallback [optional] [nullable]: - Callback function that is called in case of failure. + Callback function that is called in case of failure of sending notification.
    @@ -3455,9 +4176,6 @@

    Methods

  • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

  • -
  • - with error type InvalidStateError, if the local Bluetooth le adapter is currently not enabled. -

  • with error type SecurityError, if the application does not have the privilege to call this method.

  • @@ -3465,179 +4183,1613 @@

    Methods

    -

    Code example:

    function onerror(e)
    -{
    -  console.log("Failed to connect to device: " + e.message);
    -}
    -
    -function proccessDevice(device)
    +

    Code example:

    /* this example assumes that the local gatt server with at least one service which has at least one */
    +/* characteristic already exists */
    +var callback =
     {
    -  device.connect(onConnected, onerror);
    -  function onConnected()
    +  onnotificationsuccess: function(clientAddress)
       {
    -    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)
    -      {
    -        console.log("Value read: " + val);
    -        device.disconnect();
    -      });
    -    }
    +    console.log(clientAddress + " notified about change.");
    +  },
    +  onnotificationfail: function(clientAddress, error)
    +  {
    +    console.error("Couldn't notify " + clientAddress + " about change:" + error.name);
    +  },
    +  onnotificationfinish: function(clientAddress)
    +  {
    +    console.log("Finished notifying about change.");
       }
    -}
    +};
     
    -var adapter = tizen.bluetooth.getLEAdapter();
    -adapter.startScan(function onsuccess(device)
    +function errorCallback(error)
     {
    -  if (device.address == "11:22:33:44:55:66")
    -  {
    -    console.log("Found device: " + device.name);
    -    proccessDevice(device);
    -  }
    -});
    +  console.error("Failed to notify about value change: " + error.name + ": " + error.message);
    +}
    +
    +server.services[0].characteristics[0].notifyAboutValueChange("1234", null, callback, errorCallback);
     
    - -
    -writeValue + +
    +setReadValueRequestCallback +
    +
    +
    + Registers the callback called when a client reads the value of the characteristic from the local GATT server. +
    +
    void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback,
    +                                 optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                 optional ErrorCallback? sendResponseErrorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The callback, registered with this function, is called when a remote client requests to read the value of the characteristic. +The server can respond to such requests by returning a GATTRequestReply object from the callback. +If ReadValueRequestCallback for the characteristic is not registered, or it does not return a GATTRequestReply, clients will not be able to get the value of this characteristic.

    +

    +A callback set with this function overwrites any previously set ReadValueRequestCallback. +

    +

    +The errorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +

    +The sendResponseErrorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + InvalidValuesError - If GATTRequestReply::statusCode or GATTRequestReply::data is invalid.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +readValueRequestCallback: + The callback called when a client reads the value of the characteristic. +
    • +
    • +successCallback [optional] [nullable]: + Callback function that is called when the readValueRequestCallback is registered successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure of readValueRequestCallback registration. +
    • +
    • +sendResponseSuccessCallback [optional] [nullable]: + Callback function that is called when responses returned from readValueRequestCallbacks are sent successfully. +
    • +
    • +sendResponseErrorCallback [optional] [nullable]: + Callback function that is called when responses returned from readValueRequestCallbacks are not sent due to an error. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server with at least one service which has at least one */
    +/* characteristic already exists */
    +var callback = function(clientAddress, offset)
    +{
    +  console.log(clientAddress + " requested to read characteristic's value with offset: " + offset);
    +  return new tizen.GATTRequestReply(0, "0x1234");
    +};
    +
    +server.services[0].characteristics[0].setReadValueRequestCallback(callback);
    +
    +
    +
    +
    +setWriteValueRequestCallback +
    +
    +
    + Registers the callback called when a client writes the value of the characteristic of the local GATT server. +
    +
    void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback,
    +                                  optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                  optional ErrorCallback? sendResponseErrorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The callback, registered with this function, is called when a remote client requests to write the value of the characteristic. +The server can respond to such requests by returning a GATTRequestReply object from the callback. +If WriteValueRequestCallback for the characteristic is not registered, or it does not return a GATTRequestReply, clients will not be able to get the value of this characteristic.

    +

    +A callback set with this function overwrites any previously set WriteValueRequestCallback. +

    +

    +The errorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +

    +The sendResponseErrorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + InvalidValuesError - If GATTRequestReply::statusCode or GATTRequestReply::data is invalid.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +writeValueRequestCallback: + The callback called when a client writes the value of the characteristic. +
    • +
    • +successCallback [optional] [nullable]: + Callback function that is called when the writeValueRequestCallback is registered successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure of writeValueRequestCallback registration. +
    • +
    • +sendResponseSuccessCallback [optional] [nullable]: + Callback function that is called when responses returned from writeValueRequestCallbacks are sent successfully. +
    • +
    • +sendResponseErrorCallback [optional] [nullable]: + Callback function that is called when responses returned from writeValueRequestCallbacks are not sent due to an error. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server with at least one service which has at least one */
    +/* characteristic already exists */
    +var callback = function(clientAddress, value, offset, replyRequired)
    +{
    +  console.log(clientAddress + " requested to write characteristic's value: " + value +
    +              " with offset: " + offset);
    +  return replyRequired ? new tizen.GATTRequestReply(0, "0x1234") : null;
    +};
    +
    +server.services[0].characteristics[0].setWriteValueRequestCallback(callback);
    +
    +
    +
    + +
    +
    +
    +

    2.15. BluetoothGATTDescriptor

    +
    + Bluetooth Low Energy descriptor. +
    +
      [NoInterfaceObject] interface BluetoothGATTDescriptor {
    +    readonly attribute BluetoothUUID? uuid;
    +    void readValue(ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +    void writeValue(Bytes value, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +                    raises(WebAPIException);
    +  };
    +

    Since: + 6.0 +

    +
    +

    Attributes

    +
    • + readonly +BluetoothUUID uuid [nullable]
      + UUID of the descriptor. +
      +

      Since: + 6.0 +

      +

      Remark: + uuid is set to null, if the value cannot be retrieved. +

      +
    +
    +
    +

    Methods

    +
    +
    +readValue +
    +
    +
    + Reads descriptor value from remote device. Updates descriptor value attribute. +
    +
    void readValue(ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • + UnknownError - If any other error occurs
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +

    Remark: + BluetothGATTServerDescriptor objects do not support this function. An attempt to call it for such an object will result in an exception. +

    +
    +

    Parameters:

    +
      +
    • +successCallback: + Callback function that is called when the descriptor value is read successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type InvalidStateError, if the local Bluetooth le adapter is currently not enabled. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      • + with error type NotSupportedError, if the method is called for BluetoothGATTServerDescriptor. +

      • +
      +
    +
    +
    +

    Code example:

    function onerror(e)
    +{
    +  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)
    +    {
    +      var characteristic = service.characteristics[0];
    +      var descriptor = characteristic.descriptors[0];
    +      descriptor.readValue(function(val)
    +      {
    +        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);
    +  }
    +});
    +
    +
    +
    +
    +writeValue +
    +
    +
    + Writes the descriptor value to the remote device. +
    +
    void writeValue(Bytes value, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • +UnknownError - If any other error occurs
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +

    Remark: + BluetothGATTServerDescriptor objects do not support this function. An attempt to call it for such an object will result in an exception. +

    +
    +

    Parameters:

    +
      +
    • +value: + The descriptor value to write. +
    • +
    • +successCallback [optional] [nullable]: + Callback function that is called when the descriptor value is written successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type InvalidStateError, if the local Bluetooth le adapter is currently not enabled. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      • + with error type NotSupportedError, if the method is called for BluetoothGATTServerDescriptor. +

      • +
      +
    +
    +
    +

    Code example:

    function onerror(e)
    +{
    +  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)
    +    {
    +      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);
    +          });
    +    }
    +  }
    +}
    +
    +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);
    +  }
    +});
    +
    +
    +
    +
    +
    +
    +
    +

    2.16. BluetoothGATTServerDescriptorInit

    +
    + A dictionary for specifying GATT descriptor parameters. +
    +
      dictionary BluetoothGATTServerDescriptorInit {
    +    BluetoothUUID uuid;
    +    boolean readPermission = false;
    +    boolean writePermission = false;
    +    boolean encryptedReadPermission = false;
    +    boolean encryptedWritePermission = false;
    +    boolean encryptedSignedReadPermission = false;
    +    boolean encryptedSignedWritePermission = false;
    +    ReadValueRequestCallback? readValueRequestCallback = null;
    +    SuccessCallback? readValueSendResponseSuccessCallback = null;
    +    ErrorCallback? readValueSendResponseErrorCallback = null;
    +    WriteValueRequestCallback? writeValueRequestCallback = null;
    +    SuccessCallback? writeValueSendResponseSuccessCallback = null;
    +    ErrorCallback? writeValueSendResponseErrorCallback = null;
    +  };
    +

    Since: + 6.0 +

    +
    +

    +This dictionary is used as a definition of a descriptor to be registered in a characteristic of the local GATT server.
    readValueRequestCallback and writeValueRequestCallback are callbacks called when a client reads or writes the value of the descriptor respectively. They can be set or replaced with another functions after registering the service containing the descriptor with BluetoothGATTServerDescriptor.setReadValueRequestCallback() and BluetoothGATTServerDescriptor.setWriteValueRequestCallback().
    readValueSendResponseSuccessCallback and writeValueSendResponseSuccessCallback are success callbacks called when a response sent from readValueRequestCallback or writeValueRequestCallback reaches client. They can be set or replaced with another functions, after registering the service containing the characteristic, with BluetoothGATTServerDescriptor.setReadValueRequestCallback() and BluetoothGATTServerDescriptor.setWriteValueRequestCallback().
    readValueSendResponseErrorCallback and writeValueSendResponseErrorCallback are error callbacks called when an attempt to send a response to a client from readValueRequestCallback or writeValueRequestCallback fails. They can be set or replaced with another functions, after registering the service containing the characteristic, with BluetoothGATTServerDescriptor.setReadValueRequestCallback() and BluetoothGATTServerDescriptor.setWriteValueRequestCallback(). +

    +
    +
    +

    Code example:

    /* readValueCallback, writeValueCallback are read/write request callbacks */
    +/* readValueSendResponseSuccessCallback and writeValueSendResponseSuccessCallback are success */
    +/* callbacks */
    +/* and writeValueSendResponseErrorCallback and readValueSendResponseErrorCallback are error */
    +/* callbacks */
    +var descriptorProperties =
    +{
    +  uuid: "0180",
    +  /* Descriptor's permissions */
    +  readPermission: true,
    +  writePermission: true,
    +  encryptedReadPermission: false,
    +  encryptedWritePermission: false,
    +  encryptedSignedReadPermission: false,
    +  encryptedSignedWritePermission: false,
    +  /* Read/write value callbacks */
    +  readValueRequestCallback: readValueCallback,
    +  readValueSendResponseSuccessCallback: readValueSendResponseSuccessCallback,
    +  readValueSendResponseErrorCallback: readValueSendResponseErrorCallback,
    +  writeValueRequestCallback: writeValueCallback,
    +  writeValueSendResponseSuccessCallback: writeValueSendResponseSuccessCallback,
    +  writeValueSendResponseErrorCallback: writeValueSendResponseErrorCallback
    +};
    +
    +
    +
    +
    +

    2.17. BluetoothGATTServerDescriptor

    +
    + A subclass representing GATT descriptors of characteristics registered in services of the local server. +It extends BluetoothGATTDescriptor with permissions and methods implementing interactions of the descriptor with remote clients. +
    +
      [NoInterfaceObject] interface BluetoothGATTServerDescriptor : BluetoothGATTDescriptor {
    +    readonly attribute boolean readPermission;
    +    readonly attribute boolean writePermission;
    +    readonly attribute boolean encryptedReadPermission;
    +    readonly attribute boolean encryptedWritePermission;
    +    readonly attribute boolean encryptedSignedReadPermission;
    +    readonly attribute boolean encryptedSignedWritePermission;
    +    void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback,
    +                                     optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                     optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException);
    +    void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback,
    +                                      optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                      optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException);
    +  };
    +

    Since: + 6.0 +

    + +
    +

    Attributes

    +
      +
    • + readonly +boolean readPermission
      + Indicates if clients have the permission to read the value of the descriptor. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean writePermission
      + Indicates if clients have the permission to write the value of the descriptor. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedReadPermission
      + Indicates if clients have the permission to read the value of the descriptor through encrypted connections. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedWritePermission
      + Indicates if clients have the permission to write the value of the descriptor through encrypted connections. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedSignedReadPermission
      + Indicates if clients have the permission to perform signed reads of the charactersitic's value. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedSignedWritePermission
      + Indicates if clients have the permission to perform signed writes of the charactersitic's value. +
      +

      Since: + 6.0 +

      +
    • +
    +
    +
    +

    Methods

    +
    +
    +setReadValueRequestCallback +
    +
    +
    + Registers the callback called when a client reads the value of the descriptor from the local GATT server. +
    +
    void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback,
    +                                 optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                 optional ErrorCallback? sendResponseErrorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The callback, registered with this function, is called when a remote client requests to read the value of the descriptor. +The server can respond to such requests by returning a GATTRequestReply object from the callback. +If ReadValueRequestCallback for the descriptor is not registered, or it does not return a GATTRequestReply, clients will not be able to get the value of this descriptor.

    +

    +A callback set with this function overwrites any previously set ReadValueRequestCallback. +

    +

    +The errorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +

    +The sendResponseErrorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + InvalidValuesError - If GATTRequestReply::statusCode or GATTRequestReply::data is invalid.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +readValueRequestCallback: + The callback called when a client reads the value of the descriptor. +
    • +
    • +successCallback [optional] [nullable]: + Callback function that is called when the readValueRequestCallback is registered successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure of readValueRequestCallback registration. +
    • +
    • +sendResponseSuccessCallback [optional] [nullable]: + Callback function that is called when responses returned from readValueRequestCallbacks are sent successfully. +
    • +
    • +sendResponseErrorCallback [optional] [nullable]: + Callback function that is called when responses returned from readValueRequestCallbacks are not sent due to an error. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server with at least one service which has at least one */
    +/* characteristic with at least one descriptor already exists */
    +var callback = function(clientAddress, offset)
    +{
    +  console.log(clientAddress + " requested to read characteristic's value with offset: " + offset);
    +  return new tizen.GATTRequestReply(0, "0x1234");
    +};
    +server.services[0].characteristics[0].descriptors[0].setReadValueRequestCallback(callback);
    +
    +
    +
    +
    +setWriteValueRequestCallback +
    +
    +
    + Registers the callback called when a remote client writes the value of the descriptor from the local GATT server. +
    +
    void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback,
    +                                  optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                  optional ErrorCallback? sendResponseErrorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The callback, registered with this function, is called when a remote client requests to write the value of the descriptor. +The server can respond to such requests by returning a GATTRequestReply object from the callback. +If WriteValueRequestCallback for the descriptor is not registered, or it does not return a GATTRequestReply, clients will not be able to get the value of this descriptor.

    +

    +A callback set with this function overwrites any previously set WriteValueRequestCallback. +

    +

    +The errorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +

    +The sendResponseErrorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + InvalidValuesError - If GATTRequestReply::statusCode or GATTRequestReply::data is invalid.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +writeValueRequestCallback: + The callback called when a client writes the value of the descriptor. +
    • +
    • +successCallback [optional] [nullable]: + Callback function that is called when the writeValueRequestCallback is registered successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure of writeValueRequestCallback registration. +
    • +
    • +sendResponseSuccessCallback [optional] [nullable]: + Callback function that is called when responses returned from writeValueRequestCallbacks are sent successfully. +
    • +
    • +sendResponseErrorCallback [optional] [nullable]: + Callback function that is called when responses returned from writeValueRequestCallbacks are not sent due to an error. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server with at least one service which has at least one */
    +/* characteristic with at least one descriptor already exists */
    +var callback = function(clientAddress, value, offset, replyRequired)
    +{
    +  console.log(clientAddress + " requested to write descriptor's value: " + value +
    +              " with offset: " + offset);
    +  return replyRequired ? new tizen.GATTRequestReply(0, "0x1234") : null;
    +};
    +server.services[0].characteristics[0].descriptors[0].setWriteValueRequestCallback(callback);
    +
    +
    +
    +
    +
    +
    +
    +

    2.18. BluetoothGATTServer

    +
    + The BluetoothGATTServer interface provides access to control the local GATT server: starting and stopping it, registering and unregistering local GATT services, and getting the ATT MTU (Attribute Protocol Maximum Transmission Unit) values. +
    +
      [NoInterfaceObject] interface BluetoothGATTServer {
    +    readonly attribute boolean isRunning;
    +    readonly attribute BluetoothGATTServerService[] services;
    +    void start(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +    void stop(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +    void registerService(BluetoothGATTServerServiceInit service, optional SuccessCallback? successCallback,
    +                         optional ErrorCallback? errorCallback) raises(WebAPIException);
    +    void unregisterAllServices(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +                               raises(WebAPIException);
    +    void getConnectionMtu(BluetoothAddress clientAddress, ConnectionMtuCallback callback, optional ErrorCallback? errorCallback)
    +                          raises(WebAPIException);
    +  };
    +

    Since: + 6.0 +

    +
    +

    Attributes

    +
      +
    • + readonly +boolean isRunning
      + The flag indicating if remote GATT clients can currently connect to the server, exposing services defined in BluetoothGATTServer::services. It is toggled on start() and stop() calls. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +BluetoothGATTServerService[] + services
      + The list of GATT services hosted on this server. +
      +

      Since: + 6.0 +

      +
    • +
    +
    +
    +

    Methods

    +
    +
    +start +
    +
    +
    + Starts the local GATT server. After it starts, it can conduct GATT server operations. Also, the remote clients can discover and use the services provided by the local Bluetooth GATT Server. +
    +
    void start(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The ErrorCallback will be launched in the following situations: +

    +
      +
    • + InvalidStateError - If the server is already running.
    • +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +successCallback [optional] [nullable]: + Called when the server is started. +
    • +
    • +errorCallback [optional] [nullable]: + The method to invoke when an error occurs. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type InvalidStateError, if the Bluetooth adapter is not enabled. +

      • +
      • + with error type TypeMismatchError, if any input attribute is not compatible with the expected type for this attribute. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      • + with error type AbortError, if any other error occurs. +

      • +
      +
    +
    +
    +

    Code example:

    var onSuccess = function()
    +{
    +  console.log("Server started successfully!");
    +};
    +
    +var onError = function(e)
    +{
    +  console.error("Server didn't start, error: " + e);
    +};
    +
    +var server = tizen.bluetooth.getGATTServer();
    +
    +server.start(onSuccess, onError);
    +
    +
    +
    +

    Output example:

    Server started successfully!
    +
    +
    +
    +
    +stop +
    +
    +
    + Stops GATT server operation. +
    +
    void stop(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +After the stop, remote clients will not be able to discover the local GATT server's services. +

    +

    +The ErrorCallback will be launched in the following situations: +

    +
      +
    • + InvalidStateError - If the server is not running.
    • +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +successCallback [optional] [nullable]: + Called when the server is stopped. +
    • +
    • +errorCallback [optional] [nullable]: + The method to invoke when an error occurs. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type InvalidStateError, if the Bluetooth adapter is not enabled. +

      • +
      • + with error type TypeMismatchError, if any input attribute is not compatible with the expected type for this attribute. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      • + with error type AbortError, if any other error occurs. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that local gatt server already exists and it is started */
    +var onSuccess = function()
    +{
    +  console.log("Server stopped successfully!");
    +};
    +
    +var onError = function(e)
    +{
    +  console.error("Server didn't stop, error: " + e);
    +};
    +
    +server.stop(onSuccess, onError);
    +
    +
    +
    +

    Output example:

    Server stopped successfully!
    +
    +
    +
    +
    +registerService +
    +
    +
    + Registers a primary service in the local GATT server. +
    +
    void registerService(BluetoothGATTServerServiceInit service, optional SuccessCallback? successCallback,
    +                     optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The service is available for clients after BluetoothGATTServer::start() call. +

    +
    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • + InvalidStateError - If the service cannot be registered in the current state of the server.
    • +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + InvalidValuesError - If any of the input parameters contains an invalid value
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +

    Remark: + Services can only be registered before starting server. +

    +
    +

    Parameters:

    +
      +
    • +service: + The definition of a service to be registered in the local GATT server. +
    • +
    • +successCallback [optional] [nullable]: + Called when the local GATT server's services are successfully registered. +
    • +
    • +errorCallback [optional] [nullable]: + The method to invoke when an error occurs. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type InvalidStateError, if the Bluetooth adapter is not enabled. +

      • +
      • + with error type TypeMismatchError, if any input attribute is not compatible with the expected type for this attribute. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    var gattService = {serviceUuid: "0955", isPrimary: false, services: [], characteristics: []};
    +
    +var successCB = function()
    +{
    +  console.log("Service successfully registered!");
    +};
    +
    +var errorCB = function(e)
    +{
    +  console.log("Service not registered, error: " + e);
    +};
    +
    +var server = tizen.bluetooth.getGATTServer();
    +
    +server.registerService(gattService, successCB, errorCB);
    +
    +
    +
    +

    Output example:

    Service successfully registered!
    +
    +
    +
    +
    +unregisterAllServices +
    +
    +
    + Unregisters all services from the local GATT server. +
    +
    void unregisterAllServices(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +This method unregisters all services and all their characteristics from the local GATT server. +

    +
    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • + InvalidStateError - If the service cannot be unregistered in the current state of the GATT server.
    • +
    • + AbortError - If any other error occurs
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +

    Remark: + Currently running local GATT server is stopped after calling this method. +

    +
    +

    Parameters:

    +
      +
    • +successCallback [optional] [nullable]: + Callback function that is called when services are successfully unregistered from the local GATT server. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server already exists */
    +var successCB = function()
    +{
    +  console.log("Services successfully unregistered!");
    +};
    +
    +var errorCB = function(e)
    +{
    +  console.log("Services not unregistered, error: " + e);
    +};
    +
    +server.unregisterAllServices(successCB, errorCB);
    +
    +
    +
    +

    Output example:

    Services successfully unregistered!
    +
    +
    +
    +
    +getConnectionMtu +
    +
    +
    + Gets the ATT MTU for the connection with a client. +
    +
    void getConnectionMtu(BluetoothAddress clientAddress, ConnectionMtuCallback callback, optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • + InvalidStateError - If the server is not running.
    • +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +clientAddress: + MAC address of the client, for connection with whom the MTU is to be retrieved. +
    • +
    • +callback: + Callback functions that are called when the connection state changes. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called when getting MTU of a connection fails. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server already exists */
    +var successCB = function(mtu)
    +{
    +  console.log("ATT MTU value is: " + mtu);
    +};
    +
    +var errorCB = function(e)
    +{
    +  console.log("Cannot retrieve the ATT MTU, error: " + e);
    +};
    +
    +server.getConnectionMtu("12:34:56:78:90:ab", successCB, errorCB);
    +
    +
    +
    +

    Output example:

    ATT MTU value is: 123
    +
    +
    +
    +
    +
    +
    +
    +

    2.19. BluetoothLEScanCallback

    +
    + Bluetooth scanning process interface that defines the success callback for BluetoothLEAdapter.startScan()
    +
      [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothLEScanCallback {
    +    void onsuccess(BluetoothLEDevice device);
    +  };
    +

    Since: + 6.0 +

    +

    Remark: + Example of using can be find at startScan code example. +

    +
    +

    Methods

    +
    +
    +onsuccess +
    +
    +
    + Called when a new device is successfully discovered in the process of scanning. +
    +
    void onsuccess(BluetoothLEDevice device);
    +

    Since: + 6.0 +

    +
    +

    Parameters:

    +
      +
    • +device: + Device that is found. +
    • +
    +
    +
    +
    +
    +
    +
    +

    2.20. BluetoothLEAdvertiseCallback

    +
    + Bluetooth advertising process interface that defines the success callback for BluetoothLEAdapter.startAdvertise()
    +
      [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothLEAdvertiseCallback {
    +    void onstate(BluetoothAdvertisingState state);
    +  };
    +

    Since: + 6.0 +

    +

    Remark: + Example of using can be find at startAdvertise code example. +

    +
    +

    Methods

    +
    +
    +onstate +
    +
    +
    + Called when the advertising state is changed. +
    +
    void onstate(BluetoothAdvertisingState state);
    +

    Since: + 6.0 +

    +
    +

    Parameters:

    +
      +
    • +state: + State that is Advertising process. +
    • +
    +
    +
    +
    +
    +
    +
    +

    2.21. BluetoothLEConnectChangeCallback

    +
    + Bluetooth LE connecting process interface that defines callbacks for getting notified about changes of connect to a specific LE based service on a remote Bluetooth LE device. +
    +
      [Callback, NoInterfaceObject] interface BluetoothLEConnectChangeCallback {
    +    void onconnected(BluetoothLEDevice device);
    +    void ondisconnected(BluetoothLEDevice device);
    +  };
    +

    Since: + 6.0 +

    +

    Remark: + Example of using can be find at addConnectStateChangeListener code example. +

    +
    +

    Methods

    +
    +
    +onconnected +
    +
    +
    + Called at the beginning of connect to a specific LE based service on a remote Bluetooth LE device. +
    +
    void onconnected(BluetoothLEDevice device);
    +

    Since: + 6.0 +

    +
    +
    +ondisconnected +
    +
    +
    + Called at the beginning of disconnect to a specific LE based service on a remote Bluetooth LE device. +
    +
    void ondisconnected(BluetoothLEDevice device);
    +

    Since: + 6.0 +

    +
    +
    +
    +
    +
    +

    2.22. ReadValueSuccessCallback

    +
    + The ReadValueSuccessCallback interface implements the callback for +BluetoothGATTCharacteristic.readValue() and +BluetoothGATTDescriptor.readValue() methods. +
    +
      [Callback=FunctionOnly, NoInterfaceObject] interface ReadValueSuccessCallback {
    +    void onread(byte[] value);
    +  };
    +

    Since: + 6.0 +

    +

    Remark: + Example of using can be find at BluetoothGATTCharacteristic.readValue() and BluetoothGATTDescriptor.readValue() code examples. +

    +
    +

    Methods

    +
    +
    +onread +
    +
    +
    + Called when a characteristic value has been read. +
    +
    void onread(byte[] value);
    +

    Since: + 6.0 +

    +
    +

    Parameters:

    +
      +
    • +value: + Read characteristic value. +
    • +
    +
    +
    +
    +
    +
    +
    +

    2.23. GATTRequestReply

    +
    + Representation of the local GATT server's response to request read/write to characteristic/descriptor. +
    +
      [Constructor(long statusCode = 0, optional Bytes data)]
    +  interface GATTRequestReply {
    +    attribute long statusCode;
    +    attribute Bytes? data;
    +  };
    +

    Since: + 6.0 +

    +
    +

    Constructors

    +
    +
    +Constructor (long, Bytes) +
    +
    GATTRequestReply(long statusCode = 0, optional Bytes data);
    +
    +
    +
    +

    Attributes

    +
      +
    • +long statusCode
      + Reply status code. +
      +

      Since: + 6.0 +

      +
    • +
    • +Bytes data [nullable]
      + Response data. It is only relevant for read value requests. It will be ignored in replies to write requests and thus can be uninitialized in such replies. +
      +

      Since: + 6.0 +

      +
    • +
    +
    +
    +
    +

    2.24. ReadValueRequestCallback

    +
    + The ReadValueRequestCallback interface implements the callback for +BluetoothGATTServerCharacteristicInit.readValueRequestCallback(), +BluetoothGATTServerCharacteristic.setReadValueRequestCallback(), +BluetoothGATTServerDescriptorInit.readValueRequestCallback() and +BluetoothGATTServerDescriptor.setReadValueRequestCallback(). +
    +
      [Callback=FunctionOnly, NoInterfaceObject] interface ReadValueRequestCallback {
    +    GATTRequestReply? onreadrequest(BluetoothAddress clientAddress, long offset);
    +  };
    +

    Since: + 6.0 +

    +

    Remark: + Example of using can be found at BluetoothGATTServerCharacteristic.setReadValueRequestCallback() and BluetoothGATTServerDescriptor.setReadValueRequestCallback() code examples. +

    +
    +

    Methods

    +
    +
    +onreadrequest
    - Writes the descriptor value to the remote device. + Called when a client makes a read request for GATT characteristic to the connected local GATT server.
    -
    void writeValue(Bytes value, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +
    GATTRequestReply? onreadrequest(BluetoothAddress clientAddress, long offset);

    Since: 6.0

    -The ErrorCallback is launched with these error types: +The server should reply to requests by returning a GATTRequestReply object with requested data and a proper status code. +If the callback does not return a GATTRequestReply, the client will not receive a response.

    -
      -
    • -UnknownError - If any other error occurs
    • -
    -

    Privilege level: - public -

    -

    Privilege: - http://tizen.org/privilege/bluetooth -

    Parameters:

    • -value: - The descriptor value to write. -
    • -
    • -successCallback [optional] [nullable]: - Callback function that is called when the descriptor value is written successfully. +clientAddress: + MAC address of the client that requested the value read of the GATT entity.
    • -errorCallback [optional] [nullable]: - Callback function that is called in case of failure. +offset: + The offset given for the value of characteristic to read.
    -
    -

    Exceptions:

    -
    • WebAPIException
        -
      • - with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. -

      • -
      • - with error type InvalidStateError, if the local Bluetooth le adapter is currently not enabled. -

      • -
      • - with error type SecurityError, if the application does not have the privilege to call this method. -

      • -
      -
    -
    -
    -

    Code example:

    function onerror(e)
    -{
    -  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)
    -    {
    -      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);
    -          });
    -    }
    -  }
    -}
    -
    -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);
    -  }
    -});
    -
    +
    +

    Return value:

    +
      +GATTRequestReply [nullable]: + GATTRequestReply object with a status code and requested data. +
    -
    -

    2.12. BluetoothLEScanCallback

    +
    +

    2.25. WriteValueRequestCallback

    - Bluetooth scanning process interface that defines the success callback for BluetoothLEAdapter.startScan()
    -
      [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothLEScanCallback {
    -    void onsuccess(BluetoothLEDevice device);
    + The WriteValueRequestCallback interface implements the callback for
    +BluetoothGATTServerCharacteristicInit.writeValueRequestCallback(),
    +BluetoothGATTServerCharacteristic.setWriteValueRequestCallback(),
    +BluetoothGATTServerDescriptorInit.writeValueRequestCallback() and
    +BluetoothGATTServerDescriptor.setWriteValueRequestCallback().
    +          
    +
      [Callback=FunctionOnly, NoInterfaceObject] interface WriteValueRequestCallback {
    +    GATTRequestReply? onwriterequest(BluetoothAddress clientAddress, byte[] value, long offset, boolean replyRequired);
       };

    Since: 6.0

    Remark: - Example of using can be find at startScan code example. + Example of using can be found at BluetoothGATTServerCharacteristic.setWriteValueRequestCallback() and BluetoothGATTServerDescriptor.setWriteValueRequestCallback() code examples.

    Methods

    -
    -onsuccess +
    +onwriterequest
    - Called when a new device is successfully discovered in the process of scanning. + Called when a client connected to the local GATT server requests characteristic's value write.
    -
    void onsuccess(BluetoothLEDevice device);
    +
    GATTRequestReply? onwriterequest(BluetoothAddress clientAddress, byte[] value, long offset, boolean replyRequired);

    Since: 6.0

    +
    +

    +The server should reply to requests by returning a GATTRequestReply object with a status code. +If the callback does not return a GATTRequestReply, the client will not receive a response. +

    +

    Parameters:

    • -device: - Device that is found. +clientAddress: + MAC address of the client that requested the value write of the GATT entity. +
    • +
    • +value: + Value to be written to the GATT entity. +
    • +
    • +offset: + Offset from which the value is to be written. +
    • +
    • +replyRequired: + Flag indicating whether the client requested an answer to the request. If it's false, the client preforms the write without response operation defined in Bluetooth Core Specification.
    @@ -3645,30 +5797,33 @@

    Methods

    -
    -

    2.13. BluetoothLEAdvertiseCallback

    +
    +

    2.26. NotificationCallback

    - Bluetooth advertising process interface that defines the success callback for BluetoothLEAdapter.startAdvertise()
    -
      [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothLEAdvertiseCallback {
    -    void onstate(BluetoothAdvertisingState state);
    + The NotificationCallback interface implements the success callback for BluetoothGATTServerCharacteristic.notifyAboutValueChange().
    +          
    +
      [Callback=FunctionOnly, NoInterfaceObject] interface NotificationCallback {
    +    void onnotificationsuccess(BluetoothAddress clientAddress);
    +    void onnotificationfail(BluetoothAddress clientAddress, WebAPIException error);
    +    void onnotificationfinish(BluetoothAddress clientAddress);
       };

    Since: 6.0

    Remark: - Example of using can be find at startAdvertise code example. + Example of using can be found at BluetoothGATTServerCharacteristic.notifyAboutValueChange() code examples.

    Methods

    -
    -onstate +
    +onnotificationsuccess
    - Called when the advertising state is changed. + Called when the local GATT server successfully notifies a client of a characteristic's value change.
    -
    void onstate(BluetoothAdvertisingState state);
    +
    void onnotificationsuccess(BluetoothAddress clientAddress);

    Since: 6.0

    @@ -3676,87 +5831,86 @@

    Methods

    Parameters:

    • -state: - State that is Advertising process. +clientAddress: + MAC address of the client that was notified.
    - -
    -
    -
    -

    2.14. BluetoothLEConnectChangeCallback

    -
    - Bluetooth LE connecting process interface that defines callbacks for getting notified about changes of connect to a specific LE based service on a remote Bluetooth LE device. -
    -
      [Callback, NoInterfaceObject] interface BluetoothLEConnectChangeCallback {
    -    void onconnected(BluetoothLEDevice device);
    -    void ondisconnected(BluetoothLEDevice device);
    -  };
    -

    Since: - 6.0 -

    -

    Remark: - Example of using can be find at addConnectStateChangeListener code example. -

    -
    -

    Methods

    -
    -
    -onconnected +
    +onnotificationfail
    - Called at the beginning of connect to a specific LE based service on a remote Bluetooth LE device. + Called when the local GATT server fails to notify a client of a characteristic's value change.
    -
    void onconnected(BluetoothLEDevice device);
    +
    void onnotificationfail(BluetoothAddress clientAddress, WebAPIException error);

    Since: 6.0

    +
    +

    Parameters:

    +
      +
    • +clientAddress: + MAC address of the client that was notified. +
    • +
    • +error: + The error type and an error message from Tizen's Bluetooth LE stack. +
    • +
    +
    -
    -ondisconnected +
    +onnotificationfinish
    - Called at the beginning of disconnect to a specific LE based service on a remote Bluetooth LE device. + Called when the last of all client notifications was sent.
    -
    void ondisconnected(BluetoothLEDevice device);
    +
    void onnotificationfinish(BluetoothAddress clientAddress);

    Since: 6.0

    +
    +

    Parameters:

    +
      +
    • +clientAddress: + MAC address of the last client that was notified. +
    • +
    +
    -
    -

    2.15. ReadValueSuccessCallback

    +
    +

    2.27. ConnectionMtuCallback

    - The ReadValueSuccessCallback interface implements the callback for -BluetoothGATTCharacteristic.readValue() and -BluetoothGATTDescriptor.readValue() methods. + The ConnectionMtuCallback interface implements the callback for BluetoothGATTServer.getConnectionMtU().
    -
      [Callback=FunctionOnly, NoInterfaceObject] interface ReadValueSuccessCallback {
    -    void onread(byte[] value);
    +
      [Callback=FunctionOnly, NoInterfaceObject] interface ConnectionMtuCallback {
    +    void onsuccess(long mtu);
       };

    Since: 6.0

    Remark: - Example of using can be find at BluetoothGATTCharacteristic.readValue() and BluetoothGATTDescriptor.readValue() code examples. + Example of using can be found at BluetoothGATTServer.getConnectionMtu() code example.

    Methods

    -
    -onread +
    +onsuccess
    - Called when a characteristic value has been read. + Called when the requested ATT MTU size for a connection is ready.
    -
    void onread(byte[] value);
    +
    void onsuccess(long mtu);

    Since: 6.0

    @@ -3764,8 +5918,8 @@

    Methods

    Parameters:

    • -value: - Read characteristic value. +mtu: + The requested ATT MTU value for the connection with another Bluetooth LE device.
    @@ -3774,7 +5928,7 @@

    Methods

    -

    2.16. BluetoothDevice

    +

    2.28. BluetoothDevice

    The BluetoothDevice interface represents a remote Bluetooth device.
    @@ -4137,7 +6291,7 @@

    Methods

    -

    2.17. BluetoothLEDevice

    +

    2.29. BluetoothLEDevice

    The BluetoothLEDevice interface represents a remote Bluetooth LE device.
    @@ -4150,13 +6304,18 @@

    Methods

    readonly attribute BluetoothLESolicitationUUID[]? solicitationuuids; readonly attribute BluetoothLEServiceData[]? serviceData; readonly attribute BluetoothLEManufacturerData? manufacturerData; - readonly attribute long rssi; + readonly attribute long? rssi; void connect(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void disconnect(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); + boolean isConnected() raises(WebAPIException); BluetoothGATTService getService(BluetoothUUID uuid) raises(WebAPIException); BluetoothUUID[] getServiceAllUuids() raises(WebAPIException); long addConnectStateChangeListener(BluetoothLEConnectChangeCallback listener) raises(WebAPIException); void removeConnectStateChangeListener(long watchID); + unsigned long getAttMtu() raises(WebAPIException); + void requestAttMtuChange(unsigned long newAttMtu) raises(WebAPIException); + long addAttMtuChangeListener(ConnectionMtuCallback callback) raises(WebAPIException); + void removeAttMtuChangeListener(long watchId) raises(WebAPIException); };

    Since: 6.0 @@ -4168,6 +6327,8 @@

    Methods

    @@ -4198,6 +6359,9 @@

    Attributes

    Since: 6.0

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4220,6 +6384,9 @@ 

    Attributes

    Since: 6.0

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4237,6 +6404,9 @@ 

    Attributes

    Since: 6.0

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4255,6 +6425,9 @@ 

    Attributes

    Since: 6.0

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4279,6 +6452,9 @@ 

    Attributes

    Since: 6.0

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4306,6 +6482,9 @@ 

    Attributes

    Remark: On devices prior to Tizen 6.0, service data is found only when its BluetoothLEServiceData::uuid is 16-bit. Finding service data with 128-bit BluetoothLEServiceData::uuid is supported since Tizen 6.0.

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4329,6 +6508,9 @@ 

    Attributes

    Since: 6.0

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     
    @@ -4367,7 +6549,7 @@ 

    Attributes

  • readonly -long rssi
    +long rssi [nullable]
    The received signal strength indicator in dBm (decibel-milliwatts) units.
    @@ -4378,6 +6560,9 @@

    Attributes

    Since: 6.0

    +

    Remark: + Since Tizen 6.0, this value can be a null, but only if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4542,21 +6727,82 @@ 

    Methods

    console.log("Disconnected"); } - function onconnected() - { - console.log("Connected to device"); - device.disconnect(ondisconnect, onerror); - } + 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(); +adapter.startScan(onDeviceFound, onerror); +
    +
    + +
    +isConnected +
    +
    +
    + Checks if Bluetooth Low Energy device is currently connected. +
    +
    boolean isConnected();
    +

    Since: + 6.0 +

    +
    +

    Return value:

    +
      +boolean: + true if the device is currently connected, false otherwise. +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
      • + with error type UnknownError, if any error occurs. +

      +
    +
    +
    +

    Code example:

    var dev;
    +
    +function onerror(e)
    +{
    +  console.log("Failed to connect to device: " + e.message);
    +}
    +
    +function onconnected()
    +{
    +  console.log("Connected to device: " + dev.isConnected());
    +}
     
    +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);
    +    adapter.stopScan();
    +    dev = device;
    +    var connected = dev.isConnected();
    +    console.log("Found device: " + device.name + ", connected: " + connected);
    +    if (!connected)
    +    {
    +      device.connect(onconnected, onerror);
    +    }
       }
    -}
    -
    -var adapter = tizen.bluetooth.getLEAdapter();
    -adapter.startScan(onDeviceFound, onerror);
    +});
    +
    +
    +
    +

    Output example:

    Found device: TestDevice, connected: false
    +Connected to device: true
     
    @@ -4741,7 +6987,7 @@

    Methods

    Exceptions:

    • WebAPIException
      • - with error type UnknownError, if any other error occurs. + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    @@ -4838,11 +7084,282 @@

    Methods

  • +
    +getAttMtu +
    +
    +
    + Gets the current value of Attribute Protocol(ATT) Maximum Transmission Unit(MTU) from the connected device. +
    +
    unsigned long getAttMtu();
    +

    Since: + 6.0 +

    +
    +

    Return value:

    +
      +unsigned long: + Current ATT MTU value. +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type InvalidStateError, if the remote device is not connected. +

      • +
      • + with error type UnknownError, if any other error occurs. +

      • +
      +
    +
    +
    +

    Code example:

    var dev;
    +
    +function onerror(e)
    +{
    +  console.log("Failed to connect to device: " + e.message);
    +}
    +
    +function onconnected()
    +{
    +  console.log("Connected to device, ATT MTU: " + dev.getAttMtu());
    +}
    +
    +var adapter = tizen.bluetooth.getLEAdapter();
    +adapter.startScan(function onsuccess(device)
    +{
    +  if (device.address == "11:22:33:44:55:66")
    +  {
    +    dev = device;
    +    console.log("Found device: " + device.name);
    +    device.connect(onconnected, onerror);
    +  }
    +});
    +
    +
    +
    +

    Output example:

    Found device: TestDevice
    +Connected to device, ATT MTU: 23
    +
    +
    +
    +
    +requestAttMtuChange +
    +
    +
    + Requests the GATT server to change the Attribute Protocol (ATT) Maximum Transmission Unit (MTU) value. +
    +
    void requestAttMtuChange(unsigned long newAttMtu);
    +

    Since: + 6.0 +

    +

    Remark: + ATT MTU value is determined between two connected devices and change will be successful only if both devices support the given value of ATT MTU. +

    +
    +

    Parameters:

    +
      +
    • +newAttMtu: + The new ATT MTU value, that will be sent to GATT server. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
      • + with error type UnknownError, if any error occurs. +

      +
    +
    +
    +

    Code example:

    function proccessDevice(device)
    +{
    +  function onConnected()
    +  {
    +    var attMtu = device.getAttMtu();
    +    console.log("Initial ATT MTU value: " + attMtu);
    +    watchID = device.addAttMtuChangeListener(function(value)
    +    {
    +      console.log("ATT MTU changed to: " + value);
    +      device.removeAttMtuChangeListener(watchID);
    +      device.disconnect();
    +    });
    +    device.requestAttMtuChange(64);
    +  }
    +  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);
    +  }
    +});
    +
    +
    +
    +

    Output example:

    Found device: TestDevice
    +Initial ATT MTU value: 31
    +ATT MTU changed to: 64
    +
    +
    +
    +
    +addAttMtuChangeListener +
    +
    +
    + Registers a listener to be called when ATT MTU value is changed. +
    +
    long addAttMtuChangeListener(ConnectionMtuCallback callback);
    +

    Since: + 6.0 +

    +

    Remark: + ATT MTU value is determined between two connected devices and change takes place after both devices agrees to new value, both connected devices can initiate the ATT MTU value change by sending the request. +

    +
    +

    Parameters:

    +
      +
    • +callback: + Listener function that is called when the connection's ATT MTU changes. +
    • +
    +
    +
    +

    Return value:

    +
      +long: + The watchID to be used to unregister the listener. +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if an input attribute is not compatible with the expected type for this attribute. +

      • +
      • + with error type UnknownError, if any other error occurs. +

      • +
      +
    +
    +
    +

    Code example:

    function proccessDevice(device)
    +{
    +  function onConnected()
    +  {
    +    var attMtu = device.getAttMtu();
    +    console.log("Initial ATT MTU value: " + attMtu);
    +    watchID = device.addAttMtuChangeListener(function(value)
    +    {
    +      console.log("ATT MTU changed to: " + value);
    +      device.removeAttMtuChangeListener(watchID);
    +      device.disconnect();
    +    });
    +    device.requestAttMtuChange(64);
    +  }
    +  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);
    +  }
    +});
    +
    +
    +
    +

    Output example:

    Found device: TestDevice
    +Initial ATT MTU value: 31
    +ATT MTU changed to: 64
    +
    +
    +
    +
    +removeAttMtuChangeListener +
    +
    +
    + Unregisters the ATT MTU value change listener. +
    +
    void removeAttMtuChangeListener(long watchId);
    +

    Since: + 6.0 +

    +
    +

    Parameters:

    +
      +
    • +watchId: + The watchID identifier returned by the addAttMtuChangeListener() method. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
      • + with error type UnknownError, if any error occurs. +

      +
    +
    +
    +

    Code example:

    function proccessDevice(device)
    +{
    +  function onConnected()
    +  {
    +    var attMtu = device.getAttMtu();
    +    console.log("Initial ATT MTU value: " + attMtu);
    +    watchID = device.addAttMtuChangeListener(function(value)
    +    {
    +      console.log("ATT MTU changed to: " + value);
    +      device.removeAttMtuChangeListener(watchID);
    +      device.disconnect();
    +    });
    +    device.requestAttMtuChange(64);
    +  }
    +  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);
    +  }
    +});
    +
    +
    +
    +

    Output example:

    Found device: TestDevice
    +Initial ATT MTU value: 31
    +ATT MTU changed to: 64
    +
    +
    +
    -

    2.18. BluetoothSocket

    +

    2.30. BluetoothSocket

    The BluetoothSocket interface represents the Bluetooth socket.
    @@ -5335,7 +7852,7 @@

    Methods

    -

    2.19. BluetoothClass

    +

    2.31. BluetoothClass

    The BluetoothClass interface represents Bluetooth Class of Device/Service(CoD).
    @@ -5512,7 +8029,7 @@

    Methods

    -

    2.20. BluetoothClassDeviceMajor

    +

    2.32. BluetoothClassDeviceMajor

    The BluetoothClassDeviceMajor interface holds the identifiers for major device classes of Bluetooth CoD.
    @@ -5534,7 +8051,7 @@

    Methods

    -

    2.21. BluetoothClassDeviceMinor

    +

    2.33. BluetoothClassDeviceMinor

    The BluetoothClassDeviceMinor interface holds the identifiers for minor device classes of Bluetooth CoD.
    @@ -5617,7 +8134,7 @@

    Methods

    -

    2.22. BluetoothClassDeviceService

    +

    2.34. BluetoothClassDeviceService

    The BluetoothClassDeviceService interface holds identifiers for the major service classes of Bluetooth CoD.
    @@ -5637,7 +8154,7 @@

    Methods

    -

    2.23. BluetoothServiceHandler

    +

    2.35. BluetoothServiceHandler

    The BluetoothServiceHandler interface provides methods to handle Bluetooth service.
    @@ -5849,7 +8366,7 @@

    Methods

    -

    2.24. BluetoothAdapterChangeCallback

    +

    2.36. BluetoothAdapterChangeCallback

    The BluetoothAdapterChangeCallback interface specifies a set of methods to be invoked when the changes of Bluetooth adapter occur.
    @@ -5934,7 +8451,7 @@

    Methods

    -

    2.25. BluetoothDeviceSuccessCallback

    +

    2.37. BluetoothDeviceSuccessCallback

    The BluetoothDeviceSuccessCallback interface implements the success callback BluetoothAdapter.getDevice() and BluetoothAdapter.createBonding().
    @@ -5975,7 +8492,7 @@

    Methods

    -

    2.26. BluetoothDeviceArraySuccessCallback

    +

    2.38. BluetoothDeviceArraySuccessCallback

    The BluetoothDeviceArraySuccessCallback interface that defines the success callback for BluetoothAdapter.getKnownDevices().
    @@ -6017,7 +8534,7 @@

    Methods

    -

    2.27. BluetoothDiscoverDevicesSuccessCallback

    +

    2.39. BluetoothDiscoverDevicesSuccessCallback

    The BluetoothDiscoverDevicesSuccessCallback interface that defines the success callback for BluetoothAdapter.discoverDevices().
    @@ -6116,7 +8633,7 @@

    Methods

    -

    2.28. BluetoothSocketSuccessCallback

    +

    2.40. BluetoothSocketSuccessCallback

    The BluetoothSocketSuccessCallback interface that defines the success method for BluetoothDevice.connectToServiceByUUID().
    @@ -6157,7 +8674,7 @@

    Methods

    -

    2.29. BluetoothServiceSuccessCallback

    +

    2.41. BluetoothServiceSuccessCallback

    The BluetoothServiceSuccessCallback interface implements the success callback for BluetoothAdapter.registerRFCOMMServiceByUUID().
    @@ -6227,6 +8744,14 @@

    3. Related Feature

  • http://tizen.org/feature/network.bluetooth.le.gatt.client
  • +
    +

    +

    +To guarantee that the Bluetooth Low Energy application runs on a device with Bluetooth Low Energy GATT Server feature, declare the following feature requirements in the config file: +

    +

    +
  • http://tizen.org/feature/network.bluetooth.le.gatt.server
  • +

    For more information, see Application Filtering. @@ -6236,6 +8761,9 @@

    4. Full WebIDL

    typedef DOMString BluetoothUUID; typedef DOMString BluetoothLESolicitationUUID; typedef (byte[] or DOMString or Uint8Array) Bytes; + typedef (BluetoothGATTService or BluetoothGATTServerService) BluetoothGATTServiceVariant; + typedef (BluetoothGATTCharacteristic or BluetoothGATTServerCharacteristic) BluetoothGATTCharacteristicVariant; + typedef (BluetoothGATTDescriptor or BluetoothGATTServerDescriptor) BluetoothGATTDescriptorVariant; enum BluetoothSocketState { "CLOSED", "OPEN" }; enum BluetoothAdvertisePacketType { "ADVERTISE", "SCAN_RESPONSE" }; enum BluetoothAdvertisingState { "STARTED", "STOPPED" }; @@ -6246,9 +8774,54 @@

    4. Full WebIDL

    BluetoothLESolicitationUUID[]? solicitationuuids; unsigned long? appearance; boolean? includeTxPowerLevel; - BluetoothLEServiceData? serviceData; + BluetoothLEServiceData[]? servicesData; BluetoothLEManufacturerData? manufacturerData; }; + dictionary BluetoothGATTServerServiceInit { + BluetoothUUID serviceUuid; + boolean isPrimary = true; + BluetoothGATTServerServiceInit[]? includedServices = null; + BluetoothGATTServerCharacteristicInit[]? characteristics = null; + }; + dictionary BluetoothGATTServerCharacteristicInit { + BluetoothUUID uuid; + BluetoothGATTServerDescriptorInit[]? descriptors = null; + boolean isBroadcast = false; + boolean hasExtendedProperties = false; + boolean isNotify = false; + boolean isIndication = false; + boolean isReadable = false; + boolean isSignedWrite = false; + boolean isWritable = false; + boolean isWriteNoResponse = false; + boolean readPermission = false; + boolean writePermission = false; + boolean encryptedReadPermission = false; + boolean encryptedWritePermission = false; + boolean encryptedSignedReadPermission = false; + boolean encryptedSignedWritePermission = false; + ReadValueRequestCallback? readValueRequestCallback = null; + SuccessCallback? readValueSendResponseSuccessCallback = null; + ErrorCallback? readValueSendResponseErrorCallback = null; + WriteValueRequestCallback? writeValueRequestCallback = null; + SuccessCallback? writeValueSendResponseSuccessCallback = null; + ErrorCallback? writeValueSendResponseErrorCallback = null; + }; + dictionary BluetoothGATTServerDescriptorInit { + BluetoothUUID uuid; + boolean readPermission = false; + boolean writePermission = false; + boolean encryptedReadPermission = false; + boolean encryptedWritePermission = false; + boolean encryptedSignedReadPermission = false; + boolean encryptedSignedWritePermission = false; + ReadValueRequestCallback? readValueRequestCallback = null; + SuccessCallback? readValueSendResponseSuccessCallback = null; + ErrorCallback? readValueSendResponseErrorCallback = null; + WriteValueRequestCallback? writeValueRequestCallback = null; + SuccessCallback? writeValueSendResponseSuccessCallback = null; + ErrorCallback? writeValueSendResponseErrorCallback = null; + }; Tizen implements BluetoothManagerObject; [NoInterfaceObject] interface BluetoothManagerObject { readonly attribute BluetoothManager bluetooth; @@ -6270,7 +8843,7 @@

    4. Full WebIDL

    attribute BluetoothLESolicitationUUID[]? solicitationuuids; attribute unsigned long? appearance; attribute boolean? includeTxPowerLevel; - attribute BluetoothLEServiceData? serviceData; + attribute BluetoothLEServiceData[]? servicesData; attribute BluetoothLEManufacturerData? manufacturerData; }; [NoInterfaceObject] interface BluetoothManager { @@ -6280,6 +8853,7 @@

    4. Full WebIDL

    readonly attribute BluetoothClassDeviceService deviceService; BluetoothAdapter getDefaultAdapter() raises(WebAPIException); BluetoothLEAdapter getLEAdapter() raises(WebAPIException); + BluetoothGATTServer getGATTServer() raises(WebAPIException); byte[] toByteArray(Bytes data) raises(WebAPIException); DOMString toDOMString(Bytes data) raises(WebAPIException); Uint8Array toUint8Array(Bytes data) raises(WebAPIException); @@ -6313,18 +8887,25 @@

    4. Full WebIDL

    [NoInterfaceObject] interface BluetoothLEAdapter { void startScan(BluetoothLEScanCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void stopScan() raises(WebAPIException); + boolean isScanning() raises(WebAPIException); void startAdvertise(BluetoothLEAdvertiseData advertiseData, BluetoothAdvertisePacketType packetType, BluetoothLEAdvertiseCallback successCallback, optional ErrorCallback? errorCallback, optional BluetoothAdvertisingMode? mode, optional boolean? connectable) raises(WebAPIException); void stopAdvertise() raises(WebAPIException); + long addConnectStateChangeListener(BluetoothLEConnectChangeCallback listener) raises(WebAPIException); + void removeConnectStateChangeListener(long watchID); }; [NoInterfaceObject] interface BluetoothGATTService { readonly attribute BluetoothUUID? serviceUuid; - readonly attribute BluetoothGATTService[] services; - readonly attribute BluetoothGATTCharacteristic[] characteristics; + readonly attribute BluetoothGATTServiceVariant[] services; + readonly attribute BluetoothGATTCharacteristicVariant[] characteristics; + }; + [NoInterfaceObject] interface BluetoothGATTServerService : BluetoothGATTService { + readonly attribute boolean isPrimary; + void unregister(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); }; [NoInterfaceObject] interface BluetoothGATTCharacteristic { - readonly attribute BluetoothGATTDescriptor[] descriptors; + readonly attribute BluetoothGATTDescriptorVariant[] descriptors; readonly attribute boolean isBroadcast; readonly attribute boolean hasExtendedProperties; readonly attribute boolean isNotify; @@ -6340,12 +8921,54 @@

    4. Full WebIDL

    long addValueChangeListener(ReadValueSuccessCallback callback) raises(WebAPIException); void removeValueChangeListener(long watchID); }; + [NoInterfaceObject] interface BluetoothGATTServerCharacteristic : BluetoothGATTCharacteristic { + readonly attribute boolean readPermission; + readonly attribute boolean writePermission; + readonly attribute boolean encryptedReadPermission; + readonly attribute boolean encryptedWritePermission; + readonly attribute boolean encryptedSignedReadPermission; + readonly attribute boolean encryptedSignedWritePermission; + void notifyAboutValueChange(Bytes value, BluetoothAddress? clientAddress, optional NotificationCallback? notificationCallback, + optional ErrorCallback? errorCallback) raises(WebAPIException); + void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback, + optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, + optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException); + void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback, + optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, + optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException); + }; [NoInterfaceObject] interface BluetoothGATTDescriptor { readonly attribute BluetoothUUID? uuid; void readValue(ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void writeValue(Bytes value, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); }; + [NoInterfaceObject] interface BluetoothGATTServerDescriptor : BluetoothGATTDescriptor { + readonly attribute boolean readPermission; + readonly attribute boolean writePermission; + readonly attribute boolean encryptedReadPermission; + readonly attribute boolean encryptedWritePermission; + readonly attribute boolean encryptedSignedReadPermission; + readonly attribute boolean encryptedSignedWritePermission; + void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback, + optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, + optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException); + void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback, + optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, + optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException); + }; + [NoInterfaceObject] interface BluetoothGATTServer { + readonly attribute boolean isRunning; + readonly attribute BluetoothGATTServerService[] services; + void start(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); + void stop(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); + void registerService(BluetoothGATTServerServiceInit service, optional SuccessCallback? successCallback, + optional ErrorCallback? errorCallback) raises(WebAPIException); + void unregisterAllServices(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) + raises(WebAPIException); + void getConnectionMtu(BluetoothAddress clientAddress, ConnectionMtuCallback callback, optional ErrorCallback? errorCallback) + raises(WebAPIException); + }; [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothLEScanCallback { void onsuccess(BluetoothLEDevice device); }; @@ -6359,6 +8982,25 @@

    4. Full WebIDL

    [Callback=FunctionOnly, NoInterfaceObject] interface ReadValueSuccessCallback { void onread(byte[] value); }; + [Constructor(long statusCode = 0, optional Bytes data)] + interface GATTRequestReply { + attribute long statusCode; + attribute Bytes? data; + }; + [Callback=FunctionOnly, NoInterfaceObject] interface ReadValueRequestCallback { + GATTRequestReply? onreadrequest(BluetoothAddress clientAddress, long offset); + }; + [Callback=FunctionOnly, NoInterfaceObject] interface WriteValueRequestCallback { + GATTRequestReply? onwriterequest(BluetoothAddress clientAddress, byte[] value, long offset, boolean replyRequired); + }; + [Callback=FunctionOnly, NoInterfaceObject] interface NotificationCallback { + void onnotificationsuccess(BluetoothAddress clientAddress); + void onnotificationfail(BluetoothAddress clientAddress, WebAPIException error); + void onnotificationfinish(BluetoothAddress clientAddress); + }; + [Callback=FunctionOnly, NoInterfaceObject] interface ConnectionMtuCallback { + void onsuccess(long mtu); + }; [NoInterfaceObject] interface BluetoothDevice { readonly attribute DOMString name; readonly attribute BluetoothAddress address; @@ -6379,13 +9021,18 @@

    4. Full WebIDL

    readonly attribute BluetoothLESolicitationUUID[]? solicitationuuids; readonly attribute BluetoothLEServiceData[]? serviceData; readonly attribute BluetoothLEManufacturerData? manufacturerData; - readonly attribute long rssi; + readonly attribute long? rssi; void connect(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void disconnect(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); + boolean isConnected() raises(WebAPIException); BluetoothGATTService getService(BluetoothUUID uuid) raises(WebAPIException); BluetoothUUID[] getServiceAllUuids() raises(WebAPIException); long addConnectStateChangeListener(BluetoothLEConnectChangeCallback listener) raises(WebAPIException); void removeConnectStateChangeListener(long watchID); + unsigned long getAttMtu() raises(WebAPIException); + void requestAttMtuChange(unsigned long newAttMtu) raises(WebAPIException); + long addAttMtuChangeListener(ConnectionMtuCallback callback) raises(WebAPIException); + void removeAttMtuChangeListener(long watchId) raises(WebAPIException); }; [NoInterfaceObject] interface BluetoothSocket { readonly attribute BluetoothUUID uuid; diff --git a/docs/application/web/api/6.0/device_api/wearable/tizen/bluetooth.html b/docs/application/web/api/6.0/device_api/wearable/tizen/bluetooth.html index 530cb77577..c6cee0975a 100755 --- a/docs/application/web/api/6.0/device_api/wearable/tizen/bluetooth.html +++ b/docs/application/web/api/6.0/device_api/wearable/tizen/bluetooth.html @@ -32,6 +32,8 @@ Advertise for remote devices (including Bluetooth LE devices)
  • Act as a GATT client (Generic Attribute Profile client)
  • +
  • +Configure the local GATT server (Generic Attribute Profile)
  • For more information on the Bluetooth features, see Bluetooth Guide. @@ -73,6 +75,15 @@

    Table of Contents

  • 1.10. Bytes
  • +
  • + 1.11. BluetoothGATTServiceVariant +
  • +
  • + 1.12. BluetoothGATTCharacteristicVariant +
  • +
  • + 1.13. BluetoothGATTDescriptorVariant +
  • 2. Interfaces
  • @@ -190,6 +225,8 @@

    Summary of Interfaces and Methods

    BluetoothAdapter getDefaultAdapter ()
    BluetoothLEAdapter getLEAdapter ()
    +
    +BluetoothGATTServer getGATTServer ()
    byte[] toByteArray (Bytes data)
    DOMString toDOMString (Bytes data)
    @@ -221,8 +258,11 @@

    Summary of Interfaces and Methods

    void startScan (BluetoothLEScanCallback successCallback, optional ErrorCallback? errorCallback)
    void stopScan ()
    +
    boolean isScanning ()
    void startAdvertise (BluetoothLEAdvertiseData advertiseData, BluetoothAdvertisePacketType packetType, BluetoothLEAdvertiseCallback successCallback, optional ErrorCallback? errorCallback, optional BluetoothAdvertisingMode? mode, optional boolean? connectable)
    void stopAdvertise ()
    +
    long addConnectStateChangeListener (BluetoothLEConnectChangeCallback listener)
    +
    void removeConnectStateChangeListener (long watchID)
    @@ -230,6 +270,14 @@

    Summary of Interfaces and Methods

    +BluetoothGATTServerServiceInit + + + +BluetoothGATTServerService +
    void unregister (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    + + BluetoothGATTCharacteristic
    void readValue (ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback)
    @@ -239,6 +287,18 @@

    Summary of Interfaces and Methods

    +BluetoothGATTServerCharacteristicInit + + + +BluetoothGATTServerCharacteristic + +
    void notifyAboutValueChange (Bytes value, BluetoothAddress? clientAddress, optional NotificationCallback? notificationCallback, optional ErrorCallback? errorCallback)
    +
    void setReadValueRequestCallback (ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, optional ErrorCallback? sendResponseErrorCallback)
    +
    void setWriteValueRequestCallback (WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, optional ErrorCallback? sendResponseErrorCallback)
    + + + BluetoothGATTDescriptor
    void readValue (ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback)
    @@ -246,6 +306,27 @@

    Summary of Interfaces and Methods

    +BluetoothGATTServerDescriptorInit + + + +BluetoothGATTServerDescriptor + +
    void setReadValueRequestCallback (ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, optional ErrorCallback? sendResponseErrorCallback)
    +
    void setWriteValueRequestCallback (WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, optional ErrorCallback? sendResponseErrorCallback)
    + + + +BluetoothGATTServer + +
    void start (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +
    void stop (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +
    void registerService (BluetoothGATTServerServiceInit service, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +
    void unregisterAllServices (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +
    void getConnectionMtu (BluetoothAddress clientAddress, ConnectionMtuCallback callback, optional ErrorCallback? errorCallback)
    + + + BluetoothLEScanCallback
    void onsuccess (BluetoothLEDevice device)
    @@ -265,6 +346,32 @@

    Summary of Interfaces and Methods

    void onread (byte[] value)
    +GATTRequestReply + + + +ReadValueRequestCallback +
    +GATTRequestReply? onreadrequest (BluetoothAddress clientAddress, long offset)
    + + +WriteValueRequestCallback +
    +GATTRequestReply? onwriterequest (BluetoothAddress clientAddress, byte[] value, long offset, boolean replyRequired)
    + + +NotificationCallback + +
    void onnotificationsuccess (BluetoothAddress clientAddress)
    +
    void onnotificationfail (BluetoothAddress clientAddress, WebAPIException error)
    +
    void onnotificationfinish (BluetoothAddress clientAddress)
    + + + +ConnectionMtuCallback +
    void onsuccess (long mtu)
    + + BluetoothDevice
    void connectToServiceByUUID (BluetoothUUID uuid, BluetoothSocketSuccessCallback successCallback, optional ErrorCallback? errorCallback)
    @@ -273,12 +380,17 @@

    Summary of Interfaces and Methods

    void connect (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    void disconnect (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +
    boolean isConnected ()
    BluetoothGATTService getService (BluetoothUUID uuid)
    BluetoothUUID[] getServiceAllUuids ()
    long addConnectStateChangeListener (BluetoothLEConnectChangeCallback listener)
    void removeConnectStateChangeListener (long watchID)
    +
    unsigned long getAttMtu ()
    +
    void requestAttMtuChange (unsigned long newAttMtu)
    +
    long addAttMtuChangeListener (ConnectionMtuCallback callback)
    +
    void removeAttMtuChangeListener (long watchId)
    @@ -524,6 +636,36 @@

    1. Type Definitions

    2.3.1

    +
    +

    1.11. BluetoothGATTServiceVariant

    +
    + The type of objects which are either BluetoothGATTService or BluetoothGATTServerService, depending on the context in which they appear. +
    +
      typedef (BluetoothGATTService or BluetoothGATTServerService) BluetoothGATTServiceVariant;
    +

    Since: + 6.0 +

    +
    +
    +

    1.12. BluetoothGATTCharacteristicVariant

    +
    + The type of objects which are either BluetoothGATTCharacteristic or BluetoothGATTServerCharacteristic, depending on the context in which they appear. +
    +
      typedef (BluetoothGATTCharacteristic or BluetoothGATTServerCharacteristic) BluetoothGATTCharacteristicVariant;
    +

    Since: + 6.0 +

    +
    +
    +

    1.13. BluetoothGATTDescriptorVariant

    +
    + The type of objects which are either BluetoothGATTDescriptor or BluetoothGATTServerDescriptor, depending on the context in which they appear. +
    +
      typedef (BluetoothGATTDescriptor or BluetoothGATTServerDescriptor) BluetoothGATTDescriptorVariant;
    +

    Since: + 6.0 +

    +

    2. Interfaces

    @@ -705,7 +847,7 @@

    Attributes

    BluetoothLESolicitationUUID[]? solicitationuuids; unsigned long? appearance; boolean? includeTxPowerLevel; - BluetoothLEServiceData? serviceData; + BluetoothLEServiceData[]? servicesData; BluetoothLEManufacturerData? manufacturerData; };

    Since: @@ -740,8 +882,9 @@

    Attributes

    attribute BluetoothLESolicitationUUID[]? solicitationuuids; attribute unsigned long? appearance; attribute boolean? includeTxPowerLevel; - attribute BluetoothLEServiceData? serviceData; - attribute BluetoothLEManufacturerData? manufacturerData; + attribute BluetoothLEServiceData[]? servicesData; + attribute BluetoothLEServiceData? serviceData; + attribute BluetoothLEManufacturerData? manufacturerData; };

    Since: 2.3.1 @@ -876,16 +1019,39 @@

    Attributes

    -
  • +
  • +BluetoothLEServiceData[] + servicesData [nullable]
    + The array of objects representing service data for advertise. +
    +

    Since: + 6.0 +

    +

    Remark: + Only 16-bit BluetoothLEServiceData::uuid values can be advertised. Duplicated uuid values in servicesData are not allowed for advertising. +

    +

    Remark: + If this attribute is in neither null nor undefined, the value of deprecated BluetoothLEAdvertiseData::serviceData attribute is ignored. +

    +
    +

    Code example:

    var advertise = new tizen.BluetoothLEAdvertiseData();
    +
    +var firstService = new tizen.BluetoothLEServiceData("11e5", "0x1811");
    +var secondService = new tizen.BluetoothLEServiceData("a5e8", "0x1815");
    +advertise.servicesData = [firstService, secondService];
    +
    +
    +
  • +
  • BluetoothLEServiceData serviceData [nullable]
    The service data for advertise or scan response data.
    +

    Deprecated. + Deprecated since 6.0. Instead, use BluetoothLEAdvertiseData::servicesData. +

    Since: 2.3.1

    -

    Remark: - Only 16-bit BluetoothLEServiceData::uuid values can be advertised. -

    Code example:

    var advertise = new tizen.BluetoothLEAdvertiseData();
     var service = new tizen.BluetoothLEServiceData("11e5", "0x1811");
    @@ -922,6 +1088,7 @@ 

    Attributes

    readonly attribute BluetoothClassDeviceService deviceService; BluetoothAdapter getDefaultAdapter() raises(WebAPIException); BluetoothLEAdapter getLEAdapter() raises(WebAPIException); + BluetoothGATTServer getGATTServer() raises(WebAPIException); byte[] toByteArray(Bytes data) raises(WebAPIException); DOMString toDOMString(Bytes data) raises(WebAPIException); Uint8Array toUint8Array(Bytes data) raises(WebAPIException); @@ -1093,6 +1260,50 @@

    Methods

    +
    +getGATTServer +
    +
    +
    + Gets the BluetoothGATTServer object, which allows starting, stopping the local GATT server, and configuring its services. +
    +
    BluetoothGATTServer getGATTServer();
    +

    Since: + 6.0 +

    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Return value:

    + +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      • + with error type NotSupportedError, if the feature is not supported. +

      • +
      • + with error type AbortError, if any other error occurs. +

      • +
      +
    +
    +
    +

    Code example:

    var server = tizen.bluetooth.getGATTServer();
    +
    +
    +
    toByteArray
    @@ -1143,15 +1354,20 @@

    Methods

    Code example:

    var dataInt8Array = new Int8Array([-21, 31]);
     var dataUint8Array = new Uint8Array([240, 129]);
     var dataString = "0x18b1";
    -console.log("converted from Int8Array: " + tizen.bluetooth.toByteArray(dataInt8Array));
    -console.log("converted from Uint8Array: " + tizen.bluetooth.toByteArray(dataUint8Array));
    -console.log("converted from DOMString: " + tizen.bluetooth.toByteArray(dataString));
    +
    +var fromInt8Array = tizen.bluetooth.toByteArray(dataInt8Array);
    +var fromUint8Array = tizen.bluetooth.toByteArray(dataUint8Array);
    +var fromString = tizen.bluetooth.toByteArray(dataString);
    +
    +console.log("converted from Int8Array: " + JSON.stringify(fromInt8Array));
    +console.log("converted from Uint8Array: " + JSON.stringify(fromUint8Array));
    +console.log("converted from DOMString: " + JSON.stringify(fromString));
     
    -

    Output example:

    converted from Int8Array: Int8Array(2) [-21, 31]
    -converted from Uint8Array: Int8Array(2) [-16, -127]
    -converted from DOMString: Int8Array(2) [24, -79]
    +

    Output example:

    converted from Int8Array: [235, 31]
    +converted from Uint8Array: [240, 129]
    +converted from DOMString: [244, 177]
     
    @@ -1255,15 +1471,20 @@

    Methods

    Code example:

    var dataInt8Array = new Int8Array([-21, 31]);
     var dataUint8Array = new Uint8Array([240, 129]);
     var dataString = "0x18b1";
    -console.log("converted from Int8Array: " + tizen.bluetooth.toUint8Array(dataInt8Array));
    -console.log("converted from Uint8Array: " + tizen.bluetooth.toUint8Array(dataUint8Array));
    -console.log("converted from DOMString: " + tizen.bluetooth.toUint8Array(dataString));
    +
    +var fromInt8Array = tizen.bluetooth.toUint8Array(dataInt8Array);
    +var fromUint8Array = tizen.bluetooth.toUint8Array(dataUint8Array);
    +var fromString = tizen.bluetooth.toUint8Array(dataString);
    +
    +console.log("converted from Int8Array: " + JSON.stringify(fromInt8Array));
    +console.log("converted from Uint8Array: " + JSON.stringify(fromUint8Array));
    +console.log("converted from DOMString: " + JSON.stringify(fromString));
     
    -

    Output example:

    converted from Int8Array: Uint8Array(2) [235, 31]
    -converted from Uint8Array: Uint8Array(2) [240, 129]
    -converted from DOMString: Uint8Array(2) [24, 177]
    +

    Output example:

    converted from Int8Array: {"0":235, "1":31}
    +converted from Uint8Array: {"0":240, "1":129}
    +converted from DOMString: {"0":24, "1":177}
     
    @@ -1302,9 +1523,13 @@

    Methods

  • -

    Code example:

    tizen.bluetooth.uuidTo128bit("1234");
    -tizen.bluetooth.uuidTo128bit("ab5690ef");
    -tizen.bluetooth.uuidTo128bit("abcdef01-2345-6789-abcd-ef0123456789");
    +

    Code example:

    var uuidFrom16bits = tizen.bluetooth.uuidTo128bit("1234");
    +var uuidFrom32bits = tizen.bluetooth.uuidTo128bit("ab5690ef");
    +var uuidFrom128bits = tizen.bluetooth.uuidTo128bit("abcdef01-2345-6789-abcd-ef0123456789");
    +
    +console.log(uuidFrom16bits);
    +console.log(uuidFrom32bits);
    +console.log(uuidFrom128bits);
     
    @@ -2672,10 +2897,13 @@

    Methods

      [NoInterfaceObject] interface BluetoothLEAdapter {
         void startScan(BluetoothLEScanCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
         void stopScan() raises(WebAPIException);
    +    boolean isScanning() raises(WebAPIException);
         void startAdvertise(BluetoothLEAdvertiseData advertiseData, BluetoothAdvertisePacketType packetType,
                             BluetoothLEAdvertiseCallback successCallback, optional ErrorCallback? errorCallback,
                             optional BluetoothAdvertisingMode? mode, optional boolean? connectable) raises(WebAPIException);
         void stopAdvertise() raises(WebAPIException);
    +    long addConnectStateChangeListener(BluetoothLEConnectChangeCallback listener) raises(WebAPIException);
    +    void removeConnectStateChangeListener(long watchID);
       };

    Since: 2.3.1 @@ -2802,6 +3030,56 @@

    Methods

    +
    +isScanning +
    +
    +
    + Checks if scanning for Bluetooth Low Energy devices is currently in progress. +
    +
    boolean isScanning();
    +

    Since: + 6.0 +

    +
    +

    Return value:

    + +
    +
    +

    Exceptions:

    + +
    +
    +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
    +var scanningStarted = adapter.isScanning();
    +console.log("Scanning status: " + scanningStarted);
    +if (!scanningStarted)
    +{
    +  adapter.startScan(function onsuccess(device)
    +  {
    +    console.log("Scanning status: " + adapter.isScanning());
    +    adapter.stopScan();
    +  });
    +}
    +
    +
    +
    +

    Output example:

    Scanning status: false
    +Scanning status: true
    +
    +
    +
    startAdvertise
    @@ -2881,6 +3159,9 @@

    Methods

  • with error type QuotaExceededError, if any input attribute is not compatible with the maximum data size for this attribute.

  • +
  • + with error type InvalidValuesError, if advertising services data contains duplicated UUIDs. +

  • with error type InvalidStateError, if device is currently in progress of advertising, if the local Bluetooth le adapter is currently not enabled.

  • @@ -2981,52 +3262,182 @@

    Methods

    - - - -
    -

    2.9. BluetoothGATTService

    +
    +addConnectStateChangeListener +
    +
    - Bluetooth Low Energy Service. The service can be retrieved with BluetoothLEDevice.getService(). -
    -
      [NoInterfaceObject] interface BluetoothGATTService {
    -    readonly attribute BluetoothUUID uuid;
    -    readonly attribute BluetoothUUID? serviceUuid;
    -    readonly attribute BluetoothGATTService[] services;
    -    readonly attribute BluetoothGATTCharacteristic[] characteristics;
    -  };
    + Registers a listener that is called whenever a GATT connection with another device is established or terminated. +
    +
    long addConnectStateChangeListener(BluetoothLEConnectChangeCallback listener);

    Since: - 2.3.1 -

    + 6.0 +

    +
    +

    +The BluetoothLEConnectChangeCallback, registered with this function, is called in the following cases: +

    + +
    +
    +

    Parameters:

    + +
    +
    +

    Return value:

    + +
    +
    +

    Exceptions:

    + +
    -

    Code example:

    function onconnected(device)
    +

    Code example:

    /* This application is running the local GATT Server and does not connect to remote GATT servers. */
    +/* To be able to notify connected clients about characteristic values' changes, it saves their data. */
    +var connectedClients = [];
    +
    +function onConnected(device)
     {
    -  console.log("Connected to device");
    -  var service = device.getService(device.uuids[0]);
    -  console.log("Service got");
    +  console.log("A client connected: " + device.address);
    +  connectedClients.push(device);
     }
     
    -var adapter = tizen.bluetooth.getLEAdapter();
    -adapter.startScan(function onsuccess(device)
    +function onDisconnected(device)
     {
    -  console.log("[Found device] address: " + device.address);
    -  device.connect(onconnected.bind(null, device), onerror);
    -});
    +  console.log("A client disconnected: " + device.address);
    +  connectedClients = connectedClients.filter(function(connectedClient)
    +  {
    +    return connectedClient.address !== device.address;
    +  });
    +}
    +
    +tizen.bluetooth.getLEAdapter().addConnectStateChangeListener(
    +    {onconnected: onConnected, ondisconnected: onDisconnected});
     
    -
    -

    Attributes

    -
    +
    +

    2.9. BluetoothGATTService

    +
    + Bluetooth Low Energy service. The service can be retrieved with BluetoothLEDevice::getService(). +
    +
      [NoInterfaceObject] interface BluetoothGATTService {
    +    readonly attribute BluetoothUUID uuid;
    +    readonly attribute BluetoothUUID? serviceUuid;
    +    readonly attribute BluetoothGATTServiceVariant[] services;
    +    readonly attribute BluetoothGATTCharacteristicVariant[] characteristics;
    +  };
    +

    Since: + 2.3.1 +

    +
    +

    Code example:

    function onconnected(device)
    +{
    +  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);
    +});
    +
    +
    +
    +

    Attributes

    +
    +
    +

    2.10. BluetoothGATTServerServiceInit

    +
    + A dictionary for specifying GATT service parameters. +
    +
      dictionary BluetoothGATTServerServiceInit {
    +    BluetoothUUID serviceUuid;
    +    boolean isPrimary = true;
    +    BluetoothGATTServerServiceInit[]? includedServices = null;
    +    BluetoothGATTServerCharacteristicInit[]? characteristics = null;
    +  };
    +

    Since: + 6.0 +

    +
    +

    +This dictionary defines the GATT services to be registered to the local GATT server. +

    +
    +
    +

    Code example:

    /* serviceA and serviceB are objects of type BluetoothGATTServerServiceInit. */
    +/* hrmCharacteristic is a BluetoothGATTServerCharacteristicInit object. */
    +var serviceParameters =
    +{
    +  serviceUuid: "4b102e75",
    +  isPrimary: true,
    +  includedServices: [serviceA, serviceB],
    +  characteristics: [hrmCharacteristic]
    +};
    +
    +
    +
    +
    +

    2.11. BluetoothGATTServerService

    +
    + The class representing a Bluetooth GATT service provided by the local GATT server. +
    +
      [NoInterfaceObject] interface BluetoothGATTServerService : BluetoothGATTService {
    +    readonly attribute boolean isPrimary;
    +    void unregister(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +  };
    +

    Since: + 6.0 +

    + +
    +

    Attributes

    + +
    +
    +

    Methods

    +
    +
    +unregister +
    +
    +
    + Unregisters the service and all its characteristics from the local GATT server. +
    +
    void unregister(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • + InvalidStateError - If the service cannot be unregistered in the current state of the GATT server.
    • +
    • + AbortError - If any other error occurs
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +

    Remark: + GATT services included in other GATT services cannot be unregistered. +

    +

    Remark: + If this method is called for the only GATT service, currently registered in the local running GATT server, the server stops running. +

    +
    +

    Parameters:

    +
      +
    • +successCallback [optional] [nullable]: + Callback function that is called when the service is successfully unregistered from the local GATT server. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      • + with error type AbortError, if any other error occurs. +

      • +
      +
    +
    +
    +

    Code example:

    /* The service has been registered in the GATT server for a while. Now it is no longer needed. */
    +function onsuccess()
    +{
    +  console.log("Service unregistered");
    +}
    +
    +function onerror(error)
    +{
    +  console.log("Failed to unregister service: " + error.message);
    +}
    +
    +tizen.bluetooth.getGATTServer().services[0].unregister(onsuccess, onerror);
    +
    +
    +
    +
    +
    +
    -

    2.10. BluetoothGATTCharacteristic

    +

    2.12. BluetoothGATTCharacteristic

    A characteristic provided by Bluetooth Low Energy service.
      [NoInterfaceObject] interface BluetoothGATTCharacteristic {
    -    readonly attribute BluetoothGATTDescriptor[] descriptors;
    +    readonly attribute BluetoothGATTDescriptorVariant[] descriptors;
         readonly attribute boolean isBroadcast;
         readonly attribute boolean hasExtendedProperties;
         readonly attribute boolean isNotify;
    @@ -3130,13 +3688,16 @@ 

    Attributes

    @@ -3343,6 +3910,9 @@

    Methods

    Privilege: http://tizen.org/privilege/bluetooth

    +

    Remark: + BluetothGATTServerCharacteristic objects do not support this function. An attempt to call it for such an object will result in an exception. +

    Parameters:

    @@ -3434,6 +4007,9 @@

    Methods

    Privilege: http://tizen.org/privilege/bluetooth

    +

    Remark: + BluetothGATTServerCharacteristic objects do not support this function. An attempt to call it for such an object will result in an exception. +

    Parameters:

    Exceptions:

    -
    @@ -3511,6 +4092,9 @@

    Methods

    Remark: Example of using can be find at addValueChangeListener code example.

    +

    Remark: + Value change listeners cannot be registered and thus unregistered for BluetothGATTServerCharacteristic objects. An attempt to remove value change listener for such an object will result in no operation. +

    Parameters:

    -
    -

    2.11. BluetoothGATTDescriptor

    +
    +

    2.13. BluetoothGATTServerCharacteristicInit

    - Bluetooth Low Energy Descriptor. + A dictionary for specifying GATT characteristic parameters.
    -
      [NoInterfaceObject] interface BluetoothGATTDescriptor {
    -    readonly attribute BluetoothUUID? uuid;
    -    void readValue(ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    -    void writeValue(Bytes value, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    -                    raises(WebAPIException);
    +
      dictionary BluetoothGATTServerCharacteristicInit {
    +    BluetoothUUID uuid;
    +    BluetoothGATTServerDescriptorInit[]? descriptors = null;
    +    boolean isBroadcast = false;
    +    boolean hasExtendedProperties = false;
    +    boolean isNotify = false;
    +    boolean isIndication = false;
    +    boolean isReadable = false;
    +    boolean isSignedWrite = false;
    +    boolean isWritable = false;
    +    boolean isWriteNoResponse = false;
    +    boolean readPermission = false;
    +    boolean writePermission = false;
    +    boolean encryptedReadPermission = false;
    +    boolean encryptedWritePermission = false;
    +    boolean encryptedSignedReadPermission = false;
    +    boolean encryptedSignedWritePermission = false;
    +    ReadValueRequestCallback? readValueRequestCallback = null;
    +    SuccessCallback? readValueSendResponseSuccessCallback = null;
    +    ErrorCallback? readValueSendResponseErrorCallback = null;
    +    WriteValueRequestCallback? writeValueRequestCallback = null;
    +    SuccessCallback? writeValueSendResponseSuccessCallback = null;
    +    ErrorCallback? writeValueSendResponseErrorCallback = null;
       };

    Since: - 2.3.1 + 6.0

    -
    +
    +

    +This dictionary is used as a definition of a characteristic to be registered in a service of the local GATT server.
    readValueRequestCallback and writeValueRequestCallback are callbacks called when a client reads or writes the value of the characteristic respectively. They can be set or replaced with another functions, after registering the service containing the characteristic, with BluetoothGATTServerCharacteristic.setReadValueRequestCallback() and BluetoothGATTServerCharacteristic.setWriteValueRequestCallback().
    readValueSendResponseSuccessCallback and writeValueSendResponseSuccessCallback are success callbacks called when a response sent from readValueRequestCallback or writeValueRequestCallback reaches client. They can be set or replaced with another functions, after registering the service containing the characteristic, with BluetoothGATTServerCharacteristic.setReadValueRequestCallback() and BluetoothGATTServerCharacteristic.setWriteValueRequestCallback().
    readValueSendResponseErrorCallback and writeValueSendResponseErrorCallback are error callbacks called when an attempt to send a response to a client from readValueRequestCallback or writeValueRequestCallback fails. They can be set or replaced with another functions, after registering the service containing the characteristic, with BluetoothGATTServerCharacteristic.setReadValueRequestCallback() and BluetoothGATTServerCharacteristic.setWriteValueRequestCallback(). +

    +
    +
    +

    Code example:

    /* nameDescriptor, placeDescriptor are BluetoothGATTServerDescriptorInit objects */
    +/* readValueCallback, writeValueCallback are read/write request callbacks */
    +/* readValueSendResponseSuccessCallback and writeValueSendResponseSuccessCallback */
    +/* are success callbacks */
    +/* and writeValueSendResponseErrorCallback and readValueSendResponseErrorCallback */
    +/* are error callbacks */
    +var characteristicParameters =
    +{
    +  uuid: "0180",
    +  descriptors: [nameDescriptor, placeDescriptor],
    +  /* Characteristic's properties */
    +  isBroadcast: false,
    +  hasExtendedProperties: false,
    +  isNotify: false,
    +  isIndication: false,
    +  isReadable: true,
    +  isSignedWrite: false,
    +  isWritable: true,
    +  isWriteNoResponse: false,
    +  /* Characteristic's permissions */
    +  readPermission: true,
    +  writePermission: true,
    +  encryptedReadPermission: false,
    +  encryptedWritePermission: false,
    +  encryptedSignedReadPermission: false,
    +  encryptedSignedWritePermission: false,
    +  readValueRequestCallback: readValueCallback,
    +  readValueSendResponseSuccessCallback: readValueSendResponseSuccessCallback,
    +  readValueSendResponseErrorCallback: readValueSendResponseErrorCallback,
    +  writeValueRequestCallback: writeValueCallback,
    +  writeValueSendResponseSuccessCallback: writeValueSendResponseSuccessCallback,
    +  writeValueSendResponseErrorCallback: writeValueSendResponseErrorCallback
    +};
    +
    +
    +
    +
    +

    2.14. BluetoothGATTServerCharacteristic

    +
    + A subclass representing GATT characteristic used to construct a service of the local Bluetooth GATT server. +It extends BluetoothGATTCharacteristic with permissions and methods implementing interactions of the characteristic with remote clients. +
    +
      [NoInterfaceObject] interface BluetoothGATTServerCharacteristic : BluetoothGATTCharacteristic {
    +    readonly attribute boolean readPermission;
    +    readonly attribute boolean writePermission;
    +    readonly attribute boolean encryptedReadPermission;
    +    readonly attribute boolean encryptedWritePermission;
    +    readonly attribute boolean encryptedSignedReadPermission;
    +    readonly attribute boolean encryptedSignedWritePermission;
    +    void notifyAboutValueChange(Bytes value, BluetoothAddress? clientAddress, optional NotificationCallback? notificationCallback,
    +                                optional ErrorCallback? errorCallback) raises(WebAPIException);
    +    void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback,
    +                                     optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                     optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException);
    +    void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback,
    +                                      optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                      optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException);
    +  };
    +

    Since: + 6.0 +

    + +

    Attributes

    -
    • +
        +
      • readonly -BluetoothUUID uuid [nullable]
        - UUID of the descriptor. +boolean readPermission
        + Indicates if clients have the permission to read the value of the characteristic.

        Since: 6.0

        -

        Remark: - uuid is set to null, if the value cannot be retrieved. -

        -
      -
    -
    -

    Methods

    -
    -
    -readValue -
    -
    -
    - Reads descriptor value from remote device. Updates descriptor value attribute. + +
  • + readonly +boolean writePermission
    + Indicates if clients have the permission to write the value of the characteristic.
    -
    void readValue(ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback);

    Since: - 2.3.1 + 6.0

    -
    -

    -The ErrorCallback is launched with these error types: +

  • +
  • + readonly +boolean encryptedReadPermission
    + Indicates if clients have the permission to read the value of the characteristic through encrypted connections. +
    +

    Since: + 6.0

    -
      -
    • +
    • +
    • + readonly +boolean encryptedWritePermission
      + Indicates if clients have the permission to write the value of the characteristic through encrypted connections. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedSignedReadPermission
      + Indicates if clients have the permission to perform signed reads of the characteristic's value. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedSignedWritePermission
      + Indicates if clients have the permission to perform signed writes of the characteristic's value. +
      +

      Since: + 6.0 +

      +
    • +
    +
  • +
    +

    Methods

    +
    +
    +notifyAboutValueChange +
    +
    +
    + Notifies the clients of the local GATT server of the changes in the characteristic. +
    +
    void notifyAboutValueChange(Bytes value, BluetoothAddress? clientAddress, optional NotificationCallback? notificationCallback,
    +                            optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +This function sends a BLE notification or indication about a change of characteristic's value to clients that registered for it. If a particular client is specified, only he gets the update. +Otherwise it is sent to all clients connected to the local GATT server, who registered for the updates.

    +

    +Clients can only register for characteristic's notifications or indications, if the characteristic defines a Client Characteristic Configuration Descriptor (CCCD), as described in the Bluetooth standard. +CCCD has to be defined as any other descriptor, using BluetoothGATTServerDescriptorInit. +

    +
    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • + InvalidValuesError - If any of the parameters is invalid.
    • +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +

    Remark: + To notify the clients the service with current characteristic must be registered (see BluetoothGATTServer::registerService()) and available for clients (see BluetoothGATTServer::start()). +

    +
    +

    Parameters:

    +
      +
    • +value: + The new value of the characteristic. +
    • +
    • +clientAddress [nullable]: + The address of the client to be notified about the value change. If a null is passed, all clients will be notified. +
    • +
    • +notificationCallback [optional] [nullable]: + The callback called for each attempt of a client notification. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure of sending notification. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server with at least one service which has at least one */
    +/* characteristic already exists */
    +var callback =
    +{
    +  onnotificationsuccess: function(clientAddress)
    +  {
    +    console.log(clientAddress + " notified about change.");
    +  },
    +  onnotificationfail: function(clientAddress, error)
    +  {
    +    console.error("Couldn't notify " + clientAddress + " about change:" + error.name);
    +  },
    +  onnotificationfinish: function(clientAddress)
    +  {
    +    console.log("Finished notifying about change.");
    +  }
    +};
    +
    +function errorCallback(error)
    +{
    +  console.error("Failed to notify about value change: " + error.name + ": " + error.message);
    +}
    +
    +server.services[0].characteristics[0].notifyAboutValueChange("1234", null, callback, errorCallback);
    +
    +
    +
    +
    +setReadValueRequestCallback +
    +
    +
    + Registers the callback called when a client reads the value of the characteristic from the local GATT server. +
    +
    void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback,
    +                                 optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                 optional ErrorCallback? sendResponseErrorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The callback, registered with this function, is called when a remote client requests to read the value of the characteristic. +The server can respond to such requests by returning a GATTRequestReply object from the callback. +If ReadValueRequestCallback for the characteristic is not registered, or it does not return a GATTRequestReply, clients will not be able to get the value of this characteristic.

    +

    +A callback set with this function overwrites any previously set ReadValueRequestCallback. +

    +

    +The errorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +

    +The sendResponseErrorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + InvalidValuesError - If GATTRequestReply::statusCode or GATTRequestReply::data is invalid.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +readValueRequestCallback: + The callback called when a client reads the value of the characteristic. +
    • +
    • +successCallback [optional] [nullable]: + Callback function that is called when the readValueRequestCallback is registered successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure of readValueRequestCallback registration. +
    • +
    • +sendResponseSuccessCallback [optional] [nullable]: + Callback function that is called when responses returned from readValueRequestCallbacks are sent successfully. +
    • +
    • +sendResponseErrorCallback [optional] [nullable]: + Callback function that is called when responses returned from readValueRequestCallbacks are not sent due to an error. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server with at least one service which has at least one */
    +/* characteristic already exists */
    +var callback = function(clientAddress, offset)
    +{
    +  console.log(clientAddress + " requested to read characteristic's value with offset: " + offset);
    +  return new tizen.GATTRequestReply(0, "0x1234");
    +};
    +
    +server.services[0].characteristics[0].setReadValueRequestCallback(callback);
    +
    +
    +
    +
    +setWriteValueRequestCallback +
    +
    +
    + Registers the callback called when a client writes the value of the characteristic of the local GATT server. +
    +
    void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback,
    +                                  optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                  optional ErrorCallback? sendResponseErrorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The callback, registered with this function, is called when a remote client requests to write the value of the characteristic. +The server can respond to such requests by returning a GATTRequestReply object from the callback. +If WriteValueRequestCallback for the characteristic is not registered, or it does not return a GATTRequestReply, clients will not be able to get the value of this characteristic.

    +

    +A callback set with this function overwrites any previously set WriteValueRequestCallback. +

    +

    +The errorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +

    +The sendResponseErrorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + InvalidValuesError - If GATTRequestReply::statusCode or GATTRequestReply::data is invalid.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +writeValueRequestCallback: + The callback called when a client writes the value of the characteristic. +
    • +
    • +successCallback [optional] [nullable]: + Callback function that is called when the writeValueRequestCallback is registered successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure of writeValueRequestCallback registration. +
    • +
    • +sendResponseSuccessCallback [optional] [nullable]: + Callback function that is called when responses returned from writeValueRequestCallbacks are sent successfully. +
    • +
    • +sendResponseErrorCallback [optional] [nullable]: + Callback function that is called when responses returned from writeValueRequestCallbacks are not sent due to an error. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server with at least one service which has at least one */
    +/* characteristic already exists */
    +var callback = function(clientAddress, value, offset, replyRequired)
    +{
    +  console.log(clientAddress + " requested to write characteristic's value: " + value +
    +              " with offset: " + offset);
    +  return replyRequired ? new tizen.GATTRequestReply(0, "0x1234") : null;
    +};
    +
    +server.services[0].characteristics[0].setWriteValueRequestCallback(callback);
    +
    +
    +
    +
    +
    +
    +
    +

    2.15. BluetoothGATTDescriptor

    +
    + Bluetooth Low Energy descriptor. +
    +
      [NoInterfaceObject] interface BluetoothGATTDescriptor {
    +    readonly attribute BluetoothUUID? uuid;
    +    void readValue(ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +    void writeValue(Bytes value, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +                    raises(WebAPIException);
    +  };
    +

    Since: + 2.3.1 +

    +
    +

    Attributes

    +
    • + readonly +BluetoothUUID uuid [nullable]
      + UUID of the descriptor. +
      +

      Since: + 6.0 +

      +

      Remark: + uuid is set to null, if the value cannot be retrieved. +

      +
    +
    +
    +

    Methods

    +
    +
    +readValue +
    +
    +
    + Reads descriptor value from remote device. Updates descriptor value attribute. +
    +
    void readValue(ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 2.3.1 +

    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • + UnknownError - If any other error occurs
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +

    Remark: + BluetothGATTServerDescriptor objects do not support this function. An attempt to call it for such an object will result in an exception. +

    +
    +

    Parameters:

    +
      +
    • +successCallback: + Callback function that is called when the descriptor value is read successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type InvalidStateError, if the local Bluetooth le adapter is currently not enabled. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      • + with error type NotSupportedError, if the method is called for BluetoothGATTServerDescriptor. +

      • +
      +
    +
    +
    +

    Code example:

    function onerror(e)
    +{
    +  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)
    +    {
    +      var characteristic = service.characteristics[0];
    +      var descriptor = characteristic.descriptors[0];
    +      descriptor.readValue(function(val)
    +      {
    +        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);
    +  }
    +});
    +
    +
    +
    +
    +writeValue +
    +
    +
    + Writes the descriptor value to the remote device. +
    +
    void writeValue(Bytes value, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 2.3.1 +

    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • UnknownError - If any other error occurs
    @@ -3582,16 +4729,601 @@

    Methods

    Privilege: http://tizen.org/privilege/bluetooth

    +

    Remark: + BluetothGATTServerDescriptor objects do not support this function. An attempt to call it for such an object will result in an exception. +

    +
    +

    Parameters:

    +
      +
    • +value: + The descriptor value to write. +
    • +
    • +successCallback [optional] [nullable]: + Callback function that is called when the descriptor value is written successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type InvalidStateError, if the local Bluetooth le adapter is currently not enabled. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      • + with error type NotSupportedError, if the method is called for BluetoothGATTServerDescriptor. +

      • +
      +
    +
    +
    +

    Code example:

    function onerror(e)
    +{
    +  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)
    +    {
    +      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);
    +          });
    +    }
    +  }
    +}
    +
    +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);
    +  }
    +});
    +
    +
    +
    +
    +
    +
    +
    +

    2.16. BluetoothGATTServerDescriptorInit

    +
    + A dictionary for specifying GATT descriptor parameters. +
    +
      dictionary BluetoothGATTServerDescriptorInit {
    +    BluetoothUUID uuid;
    +    boolean readPermission = false;
    +    boolean writePermission = false;
    +    boolean encryptedReadPermission = false;
    +    boolean encryptedWritePermission = false;
    +    boolean encryptedSignedReadPermission = false;
    +    boolean encryptedSignedWritePermission = false;
    +    ReadValueRequestCallback? readValueRequestCallback = null;
    +    SuccessCallback? readValueSendResponseSuccessCallback = null;
    +    ErrorCallback? readValueSendResponseErrorCallback = null;
    +    WriteValueRequestCallback? writeValueRequestCallback = null;
    +    SuccessCallback? writeValueSendResponseSuccessCallback = null;
    +    ErrorCallback? writeValueSendResponseErrorCallback = null;
    +  };
    +

    Since: + 6.0 +

    +
    +

    +This dictionary is used as a definition of a descriptor to be registered in a characteristic of the local GATT server.
    readValueRequestCallback and writeValueRequestCallback are callbacks called when a client reads or writes the value of the descriptor respectively. They can be set or replaced with another functions after registering the service containing the descriptor with BluetoothGATTServerDescriptor.setReadValueRequestCallback() and BluetoothGATTServerDescriptor.setWriteValueRequestCallback().
    readValueSendResponseSuccessCallback and writeValueSendResponseSuccessCallback are success callbacks called when a response sent from readValueRequestCallback or writeValueRequestCallback reaches client. They can be set or replaced with another functions, after registering the service containing the characteristic, with BluetoothGATTServerDescriptor.setReadValueRequestCallback() and BluetoothGATTServerDescriptor.setWriteValueRequestCallback().
    readValueSendResponseErrorCallback and writeValueSendResponseErrorCallback are error callbacks called when an attempt to send a response to a client from readValueRequestCallback or writeValueRequestCallback fails. They can be set or replaced with another functions, after registering the service containing the characteristic, with BluetoothGATTServerDescriptor.setReadValueRequestCallback() and BluetoothGATTServerDescriptor.setWriteValueRequestCallback(). +

    +
    +
    +

    Code example:

    /* readValueCallback, writeValueCallback are read/write request callbacks */
    +/* readValueSendResponseSuccessCallback and writeValueSendResponseSuccessCallback are success */
    +/* callbacks */
    +/* and writeValueSendResponseErrorCallback and readValueSendResponseErrorCallback are error */
    +/* callbacks */
    +var descriptorProperties =
    +{
    +  uuid: "0180",
    +  /* Descriptor's permissions */
    +  readPermission: true,
    +  writePermission: true,
    +  encryptedReadPermission: false,
    +  encryptedWritePermission: false,
    +  encryptedSignedReadPermission: false,
    +  encryptedSignedWritePermission: false,
    +  /* Read/write value callbacks */
    +  readValueRequestCallback: readValueCallback,
    +  readValueSendResponseSuccessCallback: readValueSendResponseSuccessCallback,
    +  readValueSendResponseErrorCallback: readValueSendResponseErrorCallback,
    +  writeValueRequestCallback: writeValueCallback,
    +  writeValueSendResponseSuccessCallback: writeValueSendResponseSuccessCallback,
    +  writeValueSendResponseErrorCallback: writeValueSendResponseErrorCallback
    +};
    +
    +
    +
    +
    +

    2.17. BluetoothGATTServerDescriptor

    +
    + A subclass representing GATT descriptors of characteristics registered in services of the local server. +It extends BluetoothGATTDescriptor with permissions and methods implementing interactions of the descriptor with remote clients. +
    +
      [NoInterfaceObject] interface BluetoothGATTServerDescriptor : BluetoothGATTDescriptor {
    +    readonly attribute boolean readPermission;
    +    readonly attribute boolean writePermission;
    +    readonly attribute boolean encryptedReadPermission;
    +    readonly attribute boolean encryptedWritePermission;
    +    readonly attribute boolean encryptedSignedReadPermission;
    +    readonly attribute boolean encryptedSignedWritePermission;
    +    void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback,
    +                                     optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                     optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException);
    +    void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback,
    +                                      optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                      optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException);
    +  };
    +

    Since: + 6.0 +

    + +
    +

    Attributes

    +
      +
    • + readonly +boolean readPermission
      + Indicates if clients have the permission to read the value of the descriptor. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean writePermission
      + Indicates if clients have the permission to write the value of the descriptor. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedReadPermission
      + Indicates if clients have the permission to read the value of the descriptor through encrypted connections. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedWritePermission
      + Indicates if clients have the permission to write the value of the descriptor through encrypted connections. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedSignedReadPermission
      + Indicates if clients have the permission to perform signed reads of the charactersitic's value. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +boolean encryptedSignedWritePermission
      + Indicates if clients have the permission to perform signed writes of the charactersitic's value. +
      +

      Since: + 6.0 +

      +
    • +
    +
    +
    +

    Methods

    +
    +
    +setReadValueRequestCallback +
    +
    +
    + Registers the callback called when a client reads the value of the descriptor from the local GATT server. +
    +
    void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback,
    +                                 optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                 optional ErrorCallback? sendResponseErrorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The callback, registered with this function, is called when a remote client requests to read the value of the descriptor. +The server can respond to such requests by returning a GATTRequestReply object from the callback. +If ReadValueRequestCallback for the descriptor is not registered, or it does not return a GATTRequestReply, clients will not be able to get the value of this descriptor.

    +

    +A callback set with this function overwrites any previously set ReadValueRequestCallback. +

    +

    +The errorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +

    +The sendResponseErrorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + InvalidValuesError - If GATTRequestReply::statusCode or GATTRequestReply::data is invalid.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +readValueRequestCallback: + The callback called when a client reads the value of the descriptor. +
    • +
    • +successCallback [optional] [nullable]: + Callback function that is called when the readValueRequestCallback is registered successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure of readValueRequestCallback registration. +
    • +
    • +sendResponseSuccessCallback [optional] [nullable]: + Callback function that is called when responses returned from readValueRequestCallbacks are sent successfully. +
    • +
    • +sendResponseErrorCallback [optional] [nullable]: + Callback function that is called when responses returned from readValueRequestCallbacks are not sent due to an error. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server with at least one service which has at least one */
    +/* characteristic with at least one descriptor already exists */
    +var callback = function(clientAddress, offset)
    +{
    +  console.log(clientAddress + " requested to read characteristic's value with offset: " + offset);
    +  return new tizen.GATTRequestReply(0, "0x1234");
    +};
    +server.services[0].characteristics[0].descriptors[0].setReadValueRequestCallback(callback);
    +
    +
    +
    +
    +setWriteValueRequestCallback +
    +
    +
    + Registers the callback called when a remote client writes the value of the descriptor from the local GATT server. +
    +
    void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback,
    +                                  optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback,
    +                                  optional ErrorCallback? sendResponseErrorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The callback, registered with this function, is called when a remote client requests to write the value of the descriptor. +The server can respond to such requests by returning a GATTRequestReply object from the callback. +If WriteValueRequestCallback for the descriptor is not registered, or it does not return a GATTRequestReply, clients will not be able to get the value of this descriptor.

    +

    +A callback set with this function overwrites any previously set WriteValueRequestCallback. +

    +

    +The errorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +

    +The sendResponseErrorCallback will be launched in the following situations: +

    +
      +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + InvalidValuesError - If GATTRequestReply::statusCode or GATTRequestReply::data is invalid.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +writeValueRequestCallback: + The callback called when a client writes the value of the descriptor. +
    • +
    • +successCallback [optional] [nullable]: + Callback function that is called when the writeValueRequestCallback is registered successfully. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure of writeValueRequestCallback registration. +
    • +
    • +sendResponseSuccessCallback [optional] [nullable]: + Callback function that is called when responses returned from writeValueRequestCallbacks are sent successfully. +
    • +
    • +sendResponseErrorCallback [optional] [nullable]: + Callback function that is called when responses returned from writeValueRequestCallbacks are not sent due to an error. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server with at least one service which has at least one */
    +/* characteristic with at least one descriptor already exists */
    +var callback = function(clientAddress, value, offset, replyRequired)
    +{
    +  console.log(clientAddress + " requested to write descriptor's value: " + value +
    +              " with offset: " + offset);
    +  return replyRequired ? new tizen.GATTRequestReply(0, "0x1234") : null;
    +};
    +server.services[0].characteristics[0].descriptors[0].setWriteValueRequestCallback(callback);
    +
    +
    +
    +
    +
    +
    +
    +

    2.18. BluetoothGATTServer

    +
    + The BluetoothGATTServer interface provides access to control the local GATT server: starting and stopping it, registering and unregistering local GATT services, and getting the ATT MTU (Attribute Protocol Maximum Transmission Unit) values. +
    +
      [NoInterfaceObject] interface BluetoothGATTServer {
    +    readonly attribute boolean isRunning;
    +    readonly attribute BluetoothGATTServerService[] services;
    +    void start(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +    void stop(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    +    void registerService(BluetoothGATTServerServiceInit service, optional SuccessCallback? successCallback,
    +                         optional ErrorCallback? errorCallback) raises(WebAPIException);
    +    void unregisterAllServices(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
    +                               raises(WebAPIException);
    +    void getConnectionMtu(BluetoothAddress clientAddress, ConnectionMtuCallback callback, optional ErrorCallback? errorCallback)
    +                          raises(WebAPIException);
    +  };
    +

    Since: + 6.0 +

    +
    +

    Attributes

    +
      +
    • + readonly +boolean isRunning
      + The flag indicating if remote GATT clients can currently connect to the server, exposing services defined in BluetoothGATTServer::services. It is toggled on start() and stop() calls. +
      +

      Since: + 6.0 +

      +
    • +
    • + readonly +BluetoothGATTServerService[] + services
      + The list of GATT services hosted on this server. +
      +

      Since: + 6.0 +

      +
    • +
    +
    +
    +

    Methods

    +
    +
    +start +
    +
    +
    + Starts the local GATT server. After it starts, it can conduct GATT server operations. Also, the remote clients can discover and use the services provided by the local Bluetooth GATT Server. +
    +
    void start(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The ErrorCallback will be launched in the following situations: +

    +
      +
    • + InvalidStateError - If the server is already running.
    • +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +successCallback [optional] [nullable]: + Called when the server is started. +
    • +
    • +errorCallback [optional] [nullable]: + The method to invoke when an error occurs. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type InvalidStateError, if the Bluetooth adapter is not enabled. +

      • +
      • + with error type TypeMismatchError, if any input attribute is not compatible with the expected type for this attribute. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      • + with error type AbortError, if any other error occurs. +

      • +
      +
    +
    +
    +

    Code example:

    var onSuccess = function()
    +{
    +  console.log("Server started successfully!");
    +};
    +
    +var onError = function(e)
    +{
    +  console.error("Server didn't start, error: " + e);
    +};
    +
    +var server = tizen.bluetooth.getGATTServer();
    +
    +server.start(onSuccess, onError);
    +
    +
    +
    +

    Output example:

    Server started successfully!
    +
    +
    +
    +
    +stop +
    +
    +
    + Stops GATT server operation. +
    +
    void stop(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +After the stop, remote clients will not be able to discover the local GATT server's services. +

    +

    +The ErrorCallback will be launched in the following situations: +

    +
      +
    • + InvalidStateError - If the server is not running.
    • +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    Parameters:

    • -successCallback: - Callback function that is called when the descriptor value is read successfully. +successCallback [optional] [nullable]: + Called when the server is stopped.
    • errorCallback [optional] [nullable]: - Callback function that is called in case of failure. + The method to invoke when an error occurs.
    @@ -3599,72 +5331,70 @@

    Methods

    Exceptions:

    • WebAPIException
      • - with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. + with error type InvalidStateError, if the Bluetooth adapter is not enabled.

      • - with error type InvalidStateError, if the local Bluetooth le adapter is currently not enabled. + with error type TypeMismatchError, if any input attribute is not compatible with the expected type for this attribute.

      • with error type SecurityError, if the application does not have the privilege to call this method.

      • +
      • + with error type AbortError, if any other error occurs. +

    -

    Code example:

    function onerror(e)
    +

    Code example:

    /* this example assumes that local gatt server already exists and it is started */
    +var onSuccess = function()
     {
    -  console.log("Failed to connect to device: " + e.message);
    -}
    +  console.log("Server stopped successfully!");
    +};
     
    -function proccessDevice(device)
    +var onError = function(e)
     {
    -  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)
    -      {
    -        console.log("Value read: " + val);
    -        device.disconnect();
    -      });
    -    }
    -  }
    -}
    +  console.error("Server didn't stop, error: " + e);
    +};
     
    -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);
    -  }
    -});
    +server.stop(onSuccess, onError);
    +
    +
    +
    +

    Output example:

    Server stopped successfully!
     
    -
    -writeValue +
    +registerService
    - Writes the descriptor value to the remote device. + Registers a primary service in the local GATT server.
    -
    void writeValue(Bytes value, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +
    void registerService(BluetoothGATTServerServiceInit service, optional SuccessCallback? successCallback,
    +                     optional ErrorCallback? errorCallback);

    Since: - 2.3.1 + 6.0 +

    +
    +

    +The service is available for clients after BluetoothGATTServer::start() call.

    +

    The ErrorCallback is launched with these error types:

    • -UnknownError - If any other error occurs
    • + InvalidStateError - If the service cannot be registered in the current state of the server. +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + InvalidValuesError - If any of the input parameters contains an invalid value
    • +
    • + AbortError - If any other error occurs.

    Privilege level: @@ -3673,20 +5403,23 @@

    Methods

    Privilege: http://tizen.org/privilege/bluetooth

    +

    Remark: + Services can only be registered before starting server. +

    Parameters:

    • -value: - The descriptor value to write. +service: + The definition of a service to be registered in the local GATT server.
    • successCallback [optional] [nullable]: - Callback function that is called when the descriptor value is written successfully. + Called when the local GATT server's services are successfully registered.
    • errorCallback [optional] [nullable]: - Callback function that is called in case of failure. + The method to invoke when an error occurs.
    @@ -3694,10 +5427,10 @@

    Methods

    Exceptions:

    • WebAPIException
      • - with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. + with error type InvalidStateError, if the Bluetooth adapter is not enabled.

      • - with error type InvalidStateError, if the local Bluetooth le adapter is currently not enabled. + with error type TypeMismatchError, if any input attribute is not compatible with the expected type for this attribute.

      • with error type SecurityError, if the application does not have the privilege to call this method. @@ -3706,45 +5439,185 @@

        Methods

    -

    Code example:

    function onerror(e)
    +

    Code example:

    var gattService = {serviceUuid: "0955", isPrimary: false, services: [], characteristics: []};
    +
    +var successCB = function()
     {
    -  console.log("Failed to connect to device: " + e.message);
    -}
    +  console.log("Service successfully registered!");
    +};
     
    -function proccessDevice(device)
    +var errorCB = function(e)
     {
    -  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()
    -          {
    -            console.log("Value written");
    -            device.disconnect();
    -          },
    -          function(e)
    -          {
    -            console.log("Failed to write: " + e.message);
    -          });
    -    }
    -  }
    -}
    +  console.log("Service not registered, error: " + e);
    +};
     
    -var adapter = tizen.bluetooth.getLEAdapter();
    -adapter.startScan(function onsuccess(device)
    +var server = tizen.bluetooth.getGATTServer();
    +
    +server.registerService(gattService, successCB, errorCB);
    +
    +
    +
    +

    Output example:

    Service successfully registered!
    +
    +
    + +
    +unregisterAllServices +
    +
    +
    + Unregisters all services from the local GATT server. +
    +
    void unregisterAllServices(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +This method unregisters all services and all their characteristics from the local GATT server. +

    +
    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • + InvalidStateError - If the service cannot be unregistered in the current state of the GATT server.
    • +
    • + AbortError - If any other error occurs
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +

    Remark: + Currently running local GATT server is stopped after calling this method. +

    +
    +

    Parameters:

    +
      +
    • +successCallback [optional] [nullable]: + Callback function that is called when services are successfully unregistered from the local GATT server. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called in case of failure. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server already exists */
    +var successCB = function()
     {
    -  if (device.address == "11:22:33:44:55:66")
    -  {
    -    console.log("Found device: " + device.name);
    -    proccessDevice(device);
    -  }
    -});
    +  console.log("Services successfully unregistered!");
    +};
    +
    +var errorCB = function(e)
    +{
    +  console.log("Services not unregistered, error: " + e);
    +};
    +
    +server.unregisterAllServices(successCB, errorCB);
    +
    +
    +
    +

    Output example:

    Services successfully unregistered!
    +
    +
    +
    +
    +getConnectionMtu +
    +
    +
    + Gets the ATT MTU for the connection with a client. +
    +
    void getConnectionMtu(BluetoothAddress clientAddress, ConnectionMtuCallback callback, optional ErrorCallback? errorCallback);
    +

    Since: + 6.0 +

    +
    +

    +The ErrorCallback is launched with these error types: +

    +
      +
    • + InvalidStateError - If the server is not running.
    • +
    • + NotSupportedError - If the feature is not supported.
    • +
    • + AbortError - If any other error occurs.
    • +
    +
    +

    Privilege level: + public +

    +

    Privilege: + http://tizen.org/privilege/bluetooth +

    +
    +

    Parameters:

    +
      +
    • +clientAddress: + MAC address of the client, for connection with whom the MTU is to be retrieved. +
    • +
    • +callback: + Callback functions that are called when the connection state changes. +
    • +
    • +errorCallback [optional] [nullable]: + Callback function that is called when getting MTU of a connection fails. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter. +

      • +
      • + with error type SecurityError, if the application does not have the privilege to call this method. +

      • +
      +
    +
    +
    +

    Code example:

    /* this example assumes that the local gatt server already exists */
    +var successCB = function(mtu)
    +{
    +  console.log("ATT MTU value is: " + mtu);
    +};
    +
    +var errorCB = function(e)
    +{
    +  console.log("Cannot retrieve the ATT MTU, error: " + e);
    +};
    +
    +server.getConnectionMtu("12:34:56:78:90:ab", successCB, errorCB);
    +
    +
    +
    +

    Output example:

    ATT MTU value is: 123
     
    @@ -3752,7 +5625,7 @@

    Methods

    -

    2.12. BluetoothLEScanCallback

    +

    2.19. BluetoothLEScanCallback

    Bluetooth scanning process interface that defines the success callback for BluetoothLEAdapter.startScan()
      [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothLEScanCallback {
    @@ -3792,7 +5665,7 @@ 

    Methods

    -

    2.13. BluetoothLEAdvertiseCallback

    +

    2.20. BluetoothLEAdvertiseCallback

    Bluetooth advertising process interface that defines the success callback for BluetoothLEAdapter.startAdvertise()
      [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothLEAdvertiseCallback {
    @@ -3832,7 +5705,7 @@ 

    Methods

    -

    2.14. BluetoothLEConnectChangeCallback

    +

    2.21. BluetoothLEConnectChangeCallback

    Bluetooth LE connecting process interface that defines callbacks for getting notified about changes of connect to a specific LE based service on a remote Bluetooth LE device.
    @@ -3877,7 +5750,7 @@

    Methods

    -

    2.15. ReadValueSuccessCallback

    +

    2.22. ReadValueSuccessCallback

    The ReadValueSuccessCallback interface implements the callback for BluetoothGATTCharacteristic.readValue() and @@ -3919,8 +5792,307 @@

    Methods

    +
    +

    2.23. GATTRequestReply

    +
    + Representation of the local GATT server's response to request read/write to characteristic/descriptor. +
    +
      [Constructor(long statusCode = 0, optional Bytes data)]
    +  interface GATTRequestReply {
    +    attribute long statusCode;
    +    attribute Bytes? data;
    +  };
    +

    Since: + 6.0 +

    +
    +

    Constructors

    +
    +
    +Constructor (long, Bytes) +
    +
    GATTRequestReply(long statusCode = 0, optional Bytes data);
    +
    +
    +
    +

    Attributes

    + +
    +
    +
    +

    2.24. ReadValueRequestCallback

    +
    + The ReadValueRequestCallback interface implements the callback for +BluetoothGATTServerCharacteristicInit.readValueRequestCallback(), +BluetoothGATTServerCharacteristic.setReadValueRequestCallback(), +BluetoothGATTServerDescriptorInit.readValueRequestCallback() and +BluetoothGATTServerDescriptor.setReadValueRequestCallback(). +
    +
      [Callback=FunctionOnly, NoInterfaceObject] interface ReadValueRequestCallback {
    +    GATTRequestReply? onreadrequest(BluetoothAddress clientAddress, long offset);
    +  };
    +

    Since: + 6.0 +

    +

    Remark: + Example of using can be found at BluetoothGATTServerCharacteristic.setReadValueRequestCallback() and BluetoothGATTServerDescriptor.setReadValueRequestCallback() code examples. +

    +
    +

    Methods

    +
    +
    +onreadrequest +
    +
    +
    + Called when a client makes a read request for GATT characteristic to the connected local GATT server. +
    +
    GATTRequestReply? onreadrequest(BluetoothAddress clientAddress, long offset);
    +

    Since: + 6.0 +

    +
    +

    +The server should reply to requests by returning a GATTRequestReply object with requested data and a proper status code. +If the callback does not return a GATTRequestReply, the client will not receive a response. +

    +
    +
    +

    Parameters:

    +
      +
    • +clientAddress: + MAC address of the client that requested the value read of the GATT entity. +
    • +
    • +offset: + The offset given for the value of characteristic to read. +
    • +
    +
    +
    +

    Return value:

    +
      +GATTRequestReply [nullable]: + GATTRequestReply object with a status code and requested data. +
    +
    +
    +
    +
    +
    +
    +

    2.25. WriteValueRequestCallback

    +
    + The WriteValueRequestCallback interface implements the callback for +BluetoothGATTServerCharacteristicInit.writeValueRequestCallback(), +BluetoothGATTServerCharacteristic.setWriteValueRequestCallback(), +BluetoothGATTServerDescriptorInit.writeValueRequestCallback() and +BluetoothGATTServerDescriptor.setWriteValueRequestCallback(). +
    +
      [Callback=FunctionOnly, NoInterfaceObject] interface WriteValueRequestCallback {
    +    GATTRequestReply? onwriterequest(BluetoothAddress clientAddress, byte[] value, long offset, boolean replyRequired);
    +  };
    +

    Since: + 6.0 +

    +

    Remark: + Example of using can be found at BluetoothGATTServerCharacteristic.setWriteValueRequestCallback() and BluetoothGATTServerDescriptor.setWriteValueRequestCallback() code examples. +

    +
    +

    Methods

    +
    +
    +onwriterequest +
    +
    +
    + Called when a client connected to the local GATT server requests characteristic's value write. +
    +
    GATTRequestReply? onwriterequest(BluetoothAddress clientAddress, byte[] value, long offset, boolean replyRequired);
    +

    Since: + 6.0 +

    +
    +

    +The server should reply to requests by returning a GATTRequestReply object with a status code. +If the callback does not return a GATTRequestReply, the client will not receive a response. +

    +
    +
    +

    Parameters:

    +
      +
    • +clientAddress: + MAC address of the client that requested the value write of the GATT entity. +
    • +
    • +value: + Value to be written to the GATT entity. +
    • +
    • +offset: + Offset from which the value is to be written. +
    • +
    • +replyRequired: + Flag indicating whether the client requested an answer to the request. If it's false, the client preforms the write without response operation defined in Bluetooth Core Specification. +
    • +
    +
    +
    +
    +
    +
    +
    +

    2.26. NotificationCallback

    +
    + The NotificationCallback interface implements the success callback for BluetoothGATTServerCharacteristic.notifyAboutValueChange(). +
    +
      [Callback=FunctionOnly, NoInterfaceObject] interface NotificationCallback {
    +    void onnotificationsuccess(BluetoothAddress clientAddress);
    +    void onnotificationfail(BluetoothAddress clientAddress, WebAPIException error);
    +    void onnotificationfinish(BluetoothAddress clientAddress);
    +  };
    +

    Since: + 6.0 +

    +

    Remark: + Example of using can be found at BluetoothGATTServerCharacteristic.notifyAboutValueChange() code examples. +

    +
    +

    Methods

    +
    +
    +onnotificationsuccess +
    +
    +
    + Called when the local GATT server successfully notifies a client of a characteristic's value change. +
    +
    void onnotificationsuccess(BluetoothAddress clientAddress);
    +

    Since: + 6.0 +

    +
    +

    Parameters:

    +
      +
    • +clientAddress: + MAC address of the client that was notified. +
    • +
    +
    +
    +
    +onnotificationfail +
    +
    +
    + Called when the local GATT server fails to notify a client of a characteristic's value change. +
    +
    void onnotificationfail(BluetoothAddress clientAddress, WebAPIException error);
    +

    Since: + 6.0 +

    +
    +

    Parameters:

    +
      +
    • +clientAddress: + MAC address of the client that was notified. +
    • +
    • +error: + The error type and an error message from Tizen's Bluetooth LE stack. +
    • +
    +
    +
    +
    +onnotificationfinish +
    +
    +
    + Called when the last of all client notifications was sent. +
    +
    void onnotificationfinish(BluetoothAddress clientAddress);
    +

    Since: + 6.0 +

    +
    +

    Parameters:

    +
      +
    • +clientAddress: + MAC address of the last client that was notified. +
    • +
    +
    +
    +
    +
    +
    +
    +

    2.27. ConnectionMtuCallback

    +
    + The ConnectionMtuCallback interface implements the callback for BluetoothGATTServer.getConnectionMtU(). +
    +
      [Callback=FunctionOnly, NoInterfaceObject] interface ConnectionMtuCallback {
    +    void onsuccess(long mtu);
    +  };
    +

    Since: + 6.0 +

    +

    Remark: + Example of using can be found at BluetoothGATTServer.getConnectionMtu() code example. +

    +
    +

    Methods

    +
    +
    +onsuccess +
    +
    +
    + Called when the requested ATT MTU size for a connection is ready. +
    +
    void onsuccess(long mtu);
    +

    Since: + 6.0 +

    +
    +

    Parameters:

    +
      +
    • +mtu: + The requested ATT MTU value for the connection with another Bluetooth LE device. +
    • +
    +
    +
    +
    +
    +
    -

    2.16. BluetoothDevice

    +

    2.28. BluetoothDevice

    The BluetoothDevice interface represents a remote Bluetooth device.
    @@ -4283,7 +6455,7 @@

    Methods

    -

    2.17. BluetoothLEDevice

    +

    2.29. BluetoothLEDevice

    The BluetoothLEDevice interface represents a remote Bluetooth LE device.
    @@ -4296,13 +6468,18 @@

    Methods

    readonly attribute BluetoothLESolicitationUUID[]? solicitationuuids; readonly attribute BluetoothLEServiceData[]? serviceData; readonly attribute BluetoothLEManufacturerData? manufacturerData; - readonly attribute long rssi; + readonly attribute long? rssi; void connect(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void disconnect(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); + boolean isConnected() raises(WebAPIException); BluetoothGATTService getService(BluetoothUUID uuid) raises(WebAPIException); BluetoothUUID[] getServiceAllUuids() raises(WebAPIException); long addConnectStateChangeListener(BluetoothLEConnectChangeCallback listener) raises(WebAPIException); void removeConnectStateChangeListener(long watchID); + unsigned long getAttMtu() raises(WebAPIException); + void requestAttMtuChange(unsigned long newAttMtu) raises(WebAPIException); + long addAttMtuChangeListener(ConnectionMtuCallback callback) raises(WebAPIException); + void removeAttMtuChangeListener(long watchId) raises(WebAPIException); };

    Since: 2.3.1 @@ -4314,6 +6491,8 @@

    Methods

    @@ -4344,6 +6523,9 @@

    Attributes

    Since: 2.3.1

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4366,6 +6548,9 @@ 

    Attributes

    Since: 2.3.1

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4383,6 +6568,9 @@ 

    Attributes

    Since: 2.3.1

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4401,6 +6589,9 @@ 

    Attributes

    Since: 2.3.1

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4425,6 +6616,9 @@ 

    Attributes

    Since: 2.3.1

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4452,6 +6646,9 @@ 

    Attributes

    Remark: On devices prior to Tizen 6.0, service data is found only when its BluetoothLEServiceData::uuid is 16-bit. Finding service data with 128-bit BluetoothLEServiceData::uuid is supported since Tizen 6.0.

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4475,6 +6672,9 @@ 

    Attributes

    Since: 2.3.1

    +

    Remark: + This value will be set to null, if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     
    @@ -4513,7 +6713,7 @@ 

    Attributes

  • readonly -long rssi
    +long rssi [nullable]
    The received signal strength indicator in dBm (decibel-milliwatts) units.
    @@ -4524,6 +6724,9 @@

    Attributes

    Since: 3.0

    +

    Remark: + Since Tizen 6.0, this value can be a null, but only if the object is obtained from BluetoothLEConnectChangeCallback. +

    Code example:

    var adapter = tizen.bluetooth.getLEAdapter();
     adapter.startScan(function onsuccess(device)
    @@ -4694,15 +6897,76 @@ 

    Methods

    device.disconnect(ondisconnect, onerror); } - 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); + } +} + +var adapter = tizen.bluetooth.getLEAdapter(); +adapter.startScan(onDeviceFound, onerror); +
    +
    + +
    +isConnected +
    +
    +
    + Checks if Bluetooth Low Energy device is currently connected. +
    +
    boolean isConnected();
    +

    Since: + 6.0 +

    +
    +

    Return value:

    +
      +boolean: + true if the device is currently connected, false otherwise. +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
      • + with error type UnknownError, if any error occurs. +

      +
    +
    +
    +

    Code example:

    var dev;
    +
    +function onerror(e)
    +{
    +  console.log("Failed to connect to device: " + e.message);
    +}
    +
    +function onconnected()
    +{
    +  console.log("Connected to device: " + dev.isConnected());
     }
     
     var adapter = tizen.bluetooth.getLEAdapter();
    -adapter.startScan(onDeviceFound, onerror);
    +adapter.startScan(function onsuccess(device)
    +{
    +  if (device.address == "11:22:33:44:55:66")
    +  {
    +    adapter.stopScan();
    +    dev = device;
    +    var connected = dev.isConnected();
    +    console.log("Found device: " + device.name + ", connected: " + connected);
    +    if (!connected)
    +    {
    +      device.connect(onconnected, onerror);
    +    }
    +  }
    +});
    +
    +
    +
    +

    Output example:

    Found device: TestDevice, connected: false
    +Connected to device: true
     
    @@ -4887,7 +7151,7 @@

    Methods

    Exceptions:

    • WebAPIException
      • - with error type UnknownError, if any other error occurs. + with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    @@ -4984,11 +7248,282 @@

    Methods

  • +
    +getAttMtu +
    +
    +
    + Gets the current value of Attribute Protocol(ATT) Maximum Transmission Unit(MTU) from the connected device. +
    +
    unsigned long getAttMtu();
    +

    Since: + 6.0 +

    +
    +

    Return value:

    +
      +unsigned long: + Current ATT MTU value. +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type InvalidStateError, if the remote device is not connected. +

      • +
      • + with error type UnknownError, if any other error occurs. +

      • +
      +
    +
    +
    +

    Code example:

    var dev;
    +
    +function onerror(e)
    +{
    +  console.log("Failed to connect to device: " + e.message);
    +}
    +
    +function onconnected()
    +{
    +  console.log("Connected to device, ATT MTU: " + dev.getAttMtu());
    +}
    +
    +var adapter = tizen.bluetooth.getLEAdapter();
    +adapter.startScan(function onsuccess(device)
    +{
    +  if (device.address == "11:22:33:44:55:66")
    +  {
    +    dev = device;
    +    console.log("Found device: " + device.name);
    +    device.connect(onconnected, onerror);
    +  }
    +});
    +
    +
    +
    +

    Output example:

    Found device: TestDevice
    +Connected to device, ATT MTU: 23
    +
    +
    +
    +
    +requestAttMtuChange +
    +
    +
    + Requests the GATT server to change the Attribute Protocol (ATT) Maximum Transmission Unit (MTU) value. +
    +
    void requestAttMtuChange(unsigned long newAttMtu);
    +

    Since: + 6.0 +

    +

    Remark: + ATT MTU value is determined between two connected devices and change will be successful only if both devices support the given value of ATT MTU. +

    +
    +

    Parameters:

    +
      +
    • +newAttMtu: + The new ATT MTU value, that will be sent to GATT server. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
      • + with error type UnknownError, if any error occurs. +

      +
    +
    +
    +

    Code example:

    function proccessDevice(device)
    +{
    +  function onConnected()
    +  {
    +    var attMtu = device.getAttMtu();
    +    console.log("Initial ATT MTU value: " + attMtu);
    +    watchID = device.addAttMtuChangeListener(function(value)
    +    {
    +      console.log("ATT MTU changed to: " + value);
    +      device.removeAttMtuChangeListener(watchID);
    +      device.disconnect();
    +    });
    +    device.requestAttMtuChange(64);
    +  }
    +  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);
    +  }
    +});
    +
    +
    +
    +

    Output example:

    Found device: TestDevice
    +Initial ATT MTU value: 31
    +ATT MTU changed to: 64
    +
    +
    +
    +
    +addAttMtuChangeListener +
    +
    +
    + Registers a listener to be called when ATT MTU value is changed. +
    +
    long addAttMtuChangeListener(ConnectionMtuCallback callback);
    +

    Since: + 6.0 +

    +

    Remark: + ATT MTU value is determined between two connected devices and change takes place after both devices agrees to new value, both connected devices can initiate the ATT MTU value change by sending the request. +

    +
    +

    Parameters:

    +
      +
    • +callback: + Listener function that is called when the connection's ATT MTU changes. +
    • +
    +
    +
    +

    Return value:

    +
      +long: + The watchID to be used to unregister the listener. +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
        +
      • + with error type TypeMismatchError, if an input attribute is not compatible with the expected type for this attribute. +

      • +
      • + with error type UnknownError, if any other error occurs. +

      • +
      +
    +
    +
    +

    Code example:

    function proccessDevice(device)
    +{
    +  function onConnected()
    +  {
    +    var attMtu = device.getAttMtu();
    +    console.log("Initial ATT MTU value: " + attMtu);
    +    watchID = device.addAttMtuChangeListener(function(value)
    +    {
    +      console.log("ATT MTU changed to: " + value);
    +      device.removeAttMtuChangeListener(watchID);
    +      device.disconnect();
    +    });
    +    device.requestAttMtuChange(64);
    +  }
    +  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);
    +  }
    +});
    +
    +
    +
    +

    Output example:

    Found device: TestDevice
    +Initial ATT MTU value: 31
    +ATT MTU changed to: 64
    +
    +
    +
    +
    +removeAttMtuChangeListener +
    +
    +
    + Unregisters the ATT MTU value change listener. +
    +
    void removeAttMtuChangeListener(long watchId);
    +

    Since: + 6.0 +

    +
    +

    Parameters:

    +
      +
    • +watchId: + The watchID identifier returned by the addAttMtuChangeListener() method. +
    • +
    +
    +
    +

    Exceptions:

    +
    • WebAPIException
      • + with error type UnknownError, if any error occurs. +

      +
    +
    +
    +

    Code example:

    function proccessDevice(device)
    +{
    +  function onConnected()
    +  {
    +    var attMtu = device.getAttMtu();
    +    console.log("Initial ATT MTU value: " + attMtu);
    +    watchID = device.addAttMtuChangeListener(function(value)
    +    {
    +      console.log("ATT MTU changed to: " + value);
    +      device.removeAttMtuChangeListener(watchID);
    +      device.disconnect();
    +    });
    +    device.requestAttMtuChange(64);
    +  }
    +  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);
    +  }
    +});
    +
    +
    +
    +

    Output example:

    Found device: TestDevice
    +Initial ATT MTU value: 31
    +ATT MTU changed to: 64
    +
    +
    +
    -

    2.18. BluetoothSocket

    +

    2.30. BluetoothSocket

    The BluetoothSocket interface represents the Bluetooth socket.
    @@ -5481,7 +8016,7 @@

    Methods

    -

    2.19. BluetoothClass

    +

    2.31. BluetoothClass

    The BluetoothClass interface represents Bluetooth Class of Device/Service(CoD).
    @@ -5658,7 +8193,7 @@

    Methods

    -

    2.20. BluetoothClassDeviceMajor

    +

    2.32. BluetoothClassDeviceMajor

    The BluetoothClassDeviceMajor interface holds the identifiers for major device classes of Bluetooth CoD.
    @@ -5680,7 +8215,7 @@

    Methods

    -

    2.21. BluetoothClassDeviceMinor

    +

    2.33. BluetoothClassDeviceMinor

    The BluetoothClassDeviceMinor interface holds the identifiers for minor device classes of Bluetooth CoD.
    @@ -5763,7 +8298,7 @@

    Methods

    -

    2.22. BluetoothClassDeviceService

    +

    2.34. BluetoothClassDeviceService

    The BluetoothClassDeviceService interface holds identifiers for the major service classes of Bluetooth CoD.
    @@ -5783,7 +8318,7 @@

    Methods

    -

    2.23. BluetoothServiceHandler

    +

    2.35. BluetoothServiceHandler

    The BluetoothServiceHandler interface provides methods to handle Bluetooth service.
    @@ -5995,7 +8530,7 @@

    Methods

    -

    2.24. BluetoothProfileHandler

    +

    2.36. BluetoothProfileHandler

    The BluetoothProfileHandler interface represents the Bluetooth profile handler.
    @@ -6041,7 +8576,7 @@

    Attributes

    -

    2.25. BluetoothHealthProfileHandler

    +

    2.37. BluetoothHealthProfileHandler

    This interface represents the handler of Bluetooth health device profile. The BluetoothHealthProfileHandler object is created by BluetoothAdapter.getBluetoothProfileHandler(). @@ -6260,7 +8795,7 @@

    Methods

    -

    2.26. BluetoothHealthApplication

    +

    2.38. BluetoothHealthApplication

    The BluetoothHealthApplication interface represents the Bluetooth health application.
    @@ -6479,7 +9014,7 @@

    Methods

    -

    2.27. BluetoothHealthChannel

    +

    2.39. BluetoothHealthChannel

    The BluetoothHealthChannel interface represents the Bluetooth health channel.
    @@ -6886,7 +9421,7 @@

    Methods

    -

    2.28. BluetoothAdapterChangeCallback

    +

    2.40. BluetoothAdapterChangeCallback

    The BluetoothAdapterChangeCallback interface specifies a set of methods to be invoked when the changes of Bluetooth adapter occur.
    @@ -6971,7 +9506,7 @@

    Methods

    -

    2.29. BluetoothDeviceSuccessCallback

    +

    2.41. BluetoothDeviceSuccessCallback

    The BluetoothDeviceSuccessCallback interface implements the success callback BluetoothAdapter.getDevice() and BluetoothAdapter.createBonding().
    @@ -7012,7 +9547,7 @@

    Methods

    -

    2.30. BluetoothDeviceArraySuccessCallback

    +

    2.42. BluetoothDeviceArraySuccessCallback

    The BluetoothDeviceArraySuccessCallback interface that defines the success callback for BluetoothAdapter.getKnownDevices().
    @@ -7054,7 +9589,7 @@

    Methods

    -

    2.31. BluetoothDiscoverDevicesSuccessCallback

    +

    2.43. BluetoothDiscoverDevicesSuccessCallback

    The BluetoothDiscoverDevicesSuccessCallback interface that defines the success callback for BluetoothAdapter.discoverDevices().
    @@ -7153,7 +9688,7 @@

    Methods

    -

    2.32. BluetoothSocketSuccessCallback

    +

    2.44. BluetoothSocketSuccessCallback

    The BluetoothSocketSuccessCallback interface that defines the success method for BluetoothDevice.connectToServiceByUUID().
    @@ -7194,7 +9729,7 @@

    Methods

    -

    2.33. BluetoothServiceSuccessCallback

    +

    2.45. BluetoothServiceSuccessCallback

    The BluetoothServiceSuccessCallback interface implements the success callback for BluetoothAdapter.registerRFCOMMServiceByUUID().
    @@ -7235,7 +9770,7 @@

    Methods

    -

    2.34. BluetoothHealthApplicationSuccessCallback

    +

    2.46. BluetoothHealthApplicationSuccessCallback

    The BluetoothHealthApplicationSuccessCallback interface that defines the success method for BluetoothHealthProfileHandler.registerSinkApplication().
    @@ -7282,7 +9817,7 @@

    Methods

    -

    2.35. BluetoothHealthChannelSuccessCallback

    +

    2.47. BluetoothHealthChannelSuccessCallback

    The BluetoothHealthChannelSuccessCallback interface that defines the success method for BluetoothHealthProfileHandler.connectToSource() and the event callback for BluetoothHealthApplication.onconnect().
    @@ -7329,7 +9864,7 @@

    Methods

    -

    2.36. BluetoothHealthChannelChangeCallback

    +

    2.48. BluetoothHealthChannelChangeCallback

    The BluetoothHealthChannelChangeCallback interface specifies a set of methods to be invoked when the changes of heath channel occur.
    @@ -7429,6 +9964,14 @@

    3. Related Feature

  • http://tizen.org/feature/network.bluetooth.le.gatt.client
  • +
    +

    +

    +To guarantee that the Bluetooth Low Energy application runs on a device with Bluetooth Low Energy GATT Server feature, declare the following feature requirements in the config file: +

    +

    +
  • http://tizen.org/feature/network.bluetooth.le.gatt.server
  • +

    For more information, see Application Filtering. @@ -7438,6 +9981,9 @@

    4. Full WebIDL

    typedef DOMString BluetoothUUID; typedef DOMString BluetoothLESolicitationUUID; typedef (byte[] or DOMString or Uint8Array) Bytes; + typedef (BluetoothGATTService or BluetoothGATTServerService) BluetoothGATTServiceVariant; + typedef (BluetoothGATTCharacteristic or BluetoothGATTServerCharacteristic) BluetoothGATTCharacteristicVariant; + typedef (BluetoothGATTDescriptor or BluetoothGATTServerDescriptor) BluetoothGATTDescriptorVariant; enum BluetoothSocketState { "CLOSED", "OPEN" }; enum BluetoothAdvertisePacketType { "ADVERTISE", "SCAN_RESPONSE" }; enum BluetoothAdvertisingState { "STARTED", "STOPPED" }; @@ -7448,9 +9994,54 @@

    4. Full WebIDL

    BluetoothLESolicitationUUID[]? solicitationuuids; unsigned long? appearance; boolean? includeTxPowerLevel; - BluetoothLEServiceData? serviceData; + BluetoothLEServiceData[]? servicesData; BluetoothLEManufacturerData? manufacturerData; }; + dictionary BluetoothGATTServerServiceInit { + BluetoothUUID serviceUuid; + boolean isPrimary = true; + BluetoothGATTServerServiceInit[]? includedServices = null; + BluetoothGATTServerCharacteristicInit[]? characteristics = null; + }; + dictionary BluetoothGATTServerCharacteristicInit { + BluetoothUUID uuid; + BluetoothGATTServerDescriptorInit[]? descriptors = null; + boolean isBroadcast = false; + boolean hasExtendedProperties = false; + boolean isNotify = false; + boolean isIndication = false; + boolean isReadable = false; + boolean isSignedWrite = false; + boolean isWritable = false; + boolean isWriteNoResponse = false; + boolean readPermission = false; + boolean writePermission = false; + boolean encryptedReadPermission = false; + boolean encryptedWritePermission = false; + boolean encryptedSignedReadPermission = false; + boolean encryptedSignedWritePermission = false; + ReadValueRequestCallback? readValueRequestCallback = null; + SuccessCallback? readValueSendResponseSuccessCallback = null; + ErrorCallback? readValueSendResponseErrorCallback = null; + WriteValueRequestCallback? writeValueRequestCallback = null; + SuccessCallback? writeValueSendResponseSuccessCallback = null; + ErrorCallback? writeValueSendResponseErrorCallback = null; + }; + dictionary BluetoothGATTServerDescriptorInit { + BluetoothUUID uuid; + boolean readPermission = false; + boolean writePermission = false; + boolean encryptedReadPermission = false; + boolean encryptedWritePermission = false; + boolean encryptedSignedReadPermission = false; + boolean encryptedSignedWritePermission = false; + ReadValueRequestCallback? readValueRequestCallback = null; + SuccessCallback? readValueSendResponseSuccessCallback = null; + ErrorCallback? readValueSendResponseErrorCallback = null; + WriteValueRequestCallback? writeValueRequestCallback = null; + SuccessCallback? writeValueSendResponseSuccessCallback = null; + ErrorCallback? writeValueSendResponseErrorCallback = null; + }; Tizen implements BluetoothManagerObject; [NoInterfaceObject] interface BluetoothManagerObject { readonly attribute BluetoothManager bluetooth; @@ -7472,7 +10063,7 @@

    4. Full WebIDL

    attribute BluetoothLESolicitationUUID[]? solicitationuuids; attribute unsigned long? appearance; attribute boolean? includeTxPowerLevel; - attribute BluetoothLEServiceData? serviceData; + attribute BluetoothLEServiceData[]? servicesData; attribute BluetoothLEManufacturerData? manufacturerData; }; [NoInterfaceObject] interface BluetoothManager { @@ -7482,6 +10073,7 @@

    4. Full WebIDL

    readonly attribute BluetoothClassDeviceService deviceService; BluetoothAdapter getDefaultAdapter() raises(WebAPIException); BluetoothLEAdapter getLEAdapter() raises(WebAPIException); + BluetoothGATTServer getGATTServer() raises(WebAPIException); byte[] toByteArray(Bytes data) raises(WebAPIException); DOMString toDOMString(Bytes data) raises(WebAPIException); Uint8Array toUint8Array(Bytes data) raises(WebAPIException); @@ -7515,18 +10107,25 @@

    4. Full WebIDL

    [NoInterfaceObject] interface BluetoothLEAdapter { void startScan(BluetoothLEScanCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void stopScan() raises(WebAPIException); + boolean isScanning() raises(WebAPIException); void startAdvertise(BluetoothLEAdvertiseData advertiseData, BluetoothAdvertisePacketType packetType, BluetoothLEAdvertiseCallback successCallback, optional ErrorCallback? errorCallback, optional BluetoothAdvertisingMode? mode, optional boolean? connectable) raises(WebAPIException); void stopAdvertise() raises(WebAPIException); + long addConnectStateChangeListener(BluetoothLEConnectChangeCallback listener) raises(WebAPIException); + void removeConnectStateChangeListener(long watchID); }; [NoInterfaceObject] interface BluetoothGATTService { readonly attribute BluetoothUUID? serviceUuid; - readonly attribute BluetoothGATTService[] services; - readonly attribute BluetoothGATTCharacteristic[] characteristics; + readonly attribute BluetoothGATTServiceVariant[] services; + readonly attribute BluetoothGATTCharacteristicVariant[] characteristics; + }; + [NoInterfaceObject] interface BluetoothGATTServerService : BluetoothGATTService { + readonly attribute boolean isPrimary; + void unregister(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); }; [NoInterfaceObject] interface BluetoothGATTCharacteristic { - readonly attribute BluetoothGATTDescriptor[] descriptors; + readonly attribute BluetoothGATTDescriptorVariant[] descriptors; readonly attribute boolean isBroadcast; readonly attribute boolean hasExtendedProperties; readonly attribute boolean isNotify; @@ -7542,12 +10141,54 @@

    4. Full WebIDL

    long addValueChangeListener(ReadValueSuccessCallback callback) raises(WebAPIException); void removeValueChangeListener(long watchID); }; + [NoInterfaceObject] interface BluetoothGATTServerCharacteristic : BluetoothGATTCharacteristic { + readonly attribute boolean readPermission; + readonly attribute boolean writePermission; + readonly attribute boolean encryptedReadPermission; + readonly attribute boolean encryptedWritePermission; + readonly attribute boolean encryptedSignedReadPermission; + readonly attribute boolean encryptedSignedWritePermission; + void notifyAboutValueChange(Bytes value, BluetoothAddress? clientAddress, optional NotificationCallback? notificationCallback, + optional ErrorCallback? errorCallback) raises(WebAPIException); + void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback, + optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, + optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException); + void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback, + optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, + optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException); + }; [NoInterfaceObject] interface BluetoothGATTDescriptor { readonly attribute BluetoothUUID? uuid; void readValue(ReadValueSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void writeValue(Bytes value, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); }; + [NoInterfaceObject] interface BluetoothGATTServerDescriptor : BluetoothGATTDescriptor { + readonly attribute boolean readPermission; + readonly attribute boolean writePermission; + readonly attribute boolean encryptedReadPermission; + readonly attribute boolean encryptedWritePermission; + readonly attribute boolean encryptedSignedReadPermission; + readonly attribute boolean encryptedSignedWritePermission; + void setReadValueRequestCallback(ReadValueRequestCallback readValueRequestCallback, optional SuccessCallback? successCallback, + optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, + optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException); + void setWriteValueRequestCallback(WriteValueRequestCallback writeValueRequestCallback, optional SuccessCallback? successCallback, + optional ErrorCallback? errorCallback, optional SuccessCallback? sendResponseSuccessCallback, + optional ErrorCallback? sendResponseErrorCallback) raises(WebAPIException); + }; + [NoInterfaceObject] interface BluetoothGATTServer { + readonly attribute boolean isRunning; + readonly attribute BluetoothGATTServerService[] services; + void start(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); + void stop(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); + void registerService(BluetoothGATTServerServiceInit service, optional SuccessCallback? successCallback, + optional ErrorCallback? errorCallback) raises(WebAPIException); + void unregisterAllServices(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) + raises(WebAPIException); + void getConnectionMtu(BluetoothAddress clientAddress, ConnectionMtuCallback callback, optional ErrorCallback? errorCallback) + raises(WebAPIException); + }; [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothLEScanCallback { void onsuccess(BluetoothLEDevice device); }; @@ -7561,6 +10202,25 @@

    4. Full WebIDL

    [Callback=FunctionOnly, NoInterfaceObject] interface ReadValueSuccessCallback { void onread(byte[] value); }; + [Constructor(long statusCode = 0, optional Bytes data)] + interface GATTRequestReply { + attribute long statusCode; + attribute Bytes? data; + }; + [Callback=FunctionOnly, NoInterfaceObject] interface ReadValueRequestCallback { + GATTRequestReply? onreadrequest(BluetoothAddress clientAddress, long offset); + }; + [Callback=FunctionOnly, NoInterfaceObject] interface WriteValueRequestCallback { + GATTRequestReply? onwriterequest(BluetoothAddress clientAddress, byte[] value, long offset, boolean replyRequired); + }; + [Callback=FunctionOnly, NoInterfaceObject] interface NotificationCallback { + void onnotificationsuccess(BluetoothAddress clientAddress); + void onnotificationfail(BluetoothAddress clientAddress, WebAPIException error); + void onnotificationfinish(BluetoothAddress clientAddress); + }; + [Callback=FunctionOnly, NoInterfaceObject] interface ConnectionMtuCallback { + void onsuccess(long mtu); + }; [NoInterfaceObject] interface BluetoothDevice { readonly attribute DOMString name; readonly attribute BluetoothAddress address; @@ -7581,13 +10241,18 @@

    4. Full WebIDL

    readonly attribute BluetoothLESolicitationUUID[]? solicitationuuids; readonly attribute BluetoothLEServiceData[]? serviceData; readonly attribute BluetoothLEManufacturerData? manufacturerData; - readonly attribute long rssi; + readonly attribute long? rssi; void connect(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void disconnect(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); + boolean isConnected() raises(WebAPIException); BluetoothGATTService getService(BluetoothUUID uuid) raises(WebAPIException); BluetoothUUID[] getServiceAllUuids() raises(WebAPIException); long addConnectStateChangeListener(BluetoothLEConnectChangeCallback listener) raises(WebAPIException); void removeConnectStateChangeListener(long watchID); + unsigned long getAttMtu() raises(WebAPIException); + void requestAttMtuChange(unsigned long newAttMtu) raises(WebAPIException); + long addAttMtuChangeListener(ConnectionMtuCallback callback) raises(WebAPIException); + void removeAttMtuChangeListener(long watchId) raises(WebAPIException); }; [NoInterfaceObject] interface BluetoothSocket { readonly attribute BluetoothUUID uuid; diff --git a/docs/application/web/guides/connectivity/bluetooth.md b/docs/application/web/guides/connectivity/bluetooth.md index 5adbe22725..dfcb5072de 100755 --- a/docs/application/web/guides/connectivity/bluetooth.md +++ b/docs/application/web/guides/connectivity/bluetooth.md @@ -2,80 +2,207 @@ You can use Bluetooth functionalities in your application, such as managing the local Bluetooth adapter, bonding, and exchanging data between Bluetooth-enabled devices. The Bluetooth standard provides a peer-to-peer (P2P) data exchange functionality over short distance between compliant devices. -This feature is supported in mobile and wearable applications only. +## Main features of Bluetooth API The main features of the Bluetooth API include: -- Managing the local Bluetooth adapter +- Handle UUIDs and binary data - You can [enable and disable the local Bluetooth adapter](#managing-the-local-bluetooth-adapter), and change the device name for it. + You can [convert UUIDs and binary data between equivalent formats and compare UUIDs in different formats](#handle-uuids-and-binary-data). -- Discovering devices +- Manage the local Bluetooth adapter - You can [discover other Bluetooth devices](#discovering-bluetooth-devices). + You can [enable and disable the local Bluetooth adapter](#manage-the-local-bluetooth-adapter), and change the device name for it. -- Creating a bond with a Bluetooth device +- Discover devices - You can [create a bond](#creating-a-bond-with-a-bluetooth-device) with another device retrieved through the discovery process. Bonding allows the 2 devices to establish a connection. + You can [discover other Bluetooth devices](#discover-bluetooth-devices). -- Connecting to and exchanging data with a Bluetooth device +- Create a bond with a Bluetooth device - You can [connect to and exchange data with a remote Bluetooth device](#connecting-to-and-exchanging-data-with-a-bluetooth-device). + You can [create a bond](#create-a-bond-with-a-bluetooth-device) with another device retrieved through the discovery process. Bonding allows the two devices to establish a connection. -The main Bluetooth (4.0) Low Energy features include: +- Connect to and exchange data with a Bluetooth device -- Managing the local Bluetooth adapter + You can [connect to and exchange data with a remote Bluetooth device](#connect-to-and-exchange-data-with-a-bluetooth-device). - The [Bluetooth adapter management](#managing-the-local-bluetooth-adapter) is performed the same way as in the regular Bluetooth API. +The main Bluetooth (4.0) Low Energy features include: -- Discovering Bluetooth Low Energy devices +- Manage the local Bluetooth adapter - You can [discover Bluetooth Low Energy devices](#discovering-bluetooth-low-energy-devices) in range. Through the discovery process, you can obtain basic information about available remote devices, such as their names and provided services. + The [Bluetooth adapter management](#manage-the-local-bluetooth-adapter) is performed the same way as in the regular Bluetooth API. -- Managing the advertising options +- Discover Bluetooth Low Energy devices - You can [manage advertising](#managing-the-advertising-options) to control how your device announces itself to other Bluetooth Low Energy devices for discovery. + You can [discover Bluetooth Low Energy devices](#discover-bluetooth-low-energy-devices) in range. Through the discovery process, you can obtain basic information about available remote devices, such as their names and provided services. -- Connecting to a Bluetooth Low Energy device +- Connect to a Bluetooth Low Energy device - You can [connect to a remote Bluetooth Low Energy device](#connecting-to-a-bluetooth-low-energy-device). When connected, you can access services and characteristics of the remote device. + You can [connect to a remote Bluetooth Low Energy device](#connect-to-a-bluetooth-low-energy-device). When connected, you can access services and characteristics of the remote device. -- Receiving notifications on connection state changes +- Receive notifications on connection state changes - You can [monitor the connection state](#receiving-notifications-on-connection-state-changes) to detect when the connection to the remote device is lost. + You can [monitor the connection state](#receive-notifications-on-connection-state-changes) to detect when the connection to the remote device is lost. -- Retrieving Bluetooth GATT services +- Retrieve Bluetooth GATT services - You can [retrieve information about Bluetooth GATT services](#retrieving-bluetooth-gatt-services) provided by the remote device. + You can [retrieve information about Bluetooth GATT services](#retrieve-bluetooth-gatt-services) provided by the remote device. Every GATT service defines characteristics it includes. By knowing the service, you know what features the Bluetooth device exposes. -- Accessing the Bluetooth GATT characteristic value +- Access the Bluetooth GATT characteristic value + + You can [read and write the Bluetooth GATT characteristic value](#access-the-bluetooth-gatt-characteristic-value). + + Characteristic allows you to monitor and sometimes control remote Bluetooth Low Energy devices. For example, a sensor reading can be exposed by the sensor device as a Bluetooth GATT characteristic. + +- Receive notifications on characteristic value changes + + You can [monitor a characteristic value](#receive-notifications-on-characteristic-value-changes) to detect any changes, for example, in sensor readings and battery level. + +- Access the Bluetooth GATT descriptor value + + You can [read and write the Bluetooth GATT descriptor value](#access-the-bluetooth-gatt-descriptor-value). + +- Monitor ATT MTU of a connection with a remote GATT server + + You can [read the current value of connection's ATT MTU](#access-the-att-mtu-of-connected-device) and [register a listener to receive information about its changes](#receive-notifications-on-att-mtu-changes). - You can [read and write the Bluetooth GATT characteristic value](#accessing-the-bluetooth-gatt-characteristic-value). +- Manage the advertise options - Characteristics allows you to monitor and sometimes control remote Bluetooth Low Energy devices. For example, a sensor reading can be exposed by the sensor device as a Bluetooth GATT characteristic. + You can [manage advertise](#manage-the-advertise-options) to control how your device announces itself to other Bluetooth Low Energy devices for discovery. -- Receiving notifications on characteristic value changes +- Start and stop the local GATT server - You can [monitor a characteristic value](#receiving-notifications-on-characteristic-value-changes) to detect any changes, for example, in sensor readings and battery level. + You can [start](#start-the-server) and [stop](#stop-the-server) exposing services registered in the local GATT server. -- Accessing the Bluetooth GATT descriptor value +- Receive notifications on GATT connection state changes - You can [read and write the Bluetooth GATT descriptor value](#accessing-the-bluetooth-gatt-descriptor-value). + You can [register a listener to monitor GATT connection changes](#receive-notifications-on-gatt-connection-state-changes). + +- Check ATT MTU of a connection with a remote GATT client + + You can [read ATT MTU of a connection with a remote client](#access-connections-att-mtu). + +- Manage services in the local GATT server + + You can [register](#register-services) and [unregister](#unregister-services) services in the local GATT server. + +- Notify remote GATT clients about changes of characteristic's value + + You can [send notifications and indications about changes of characteristic's value](#send-notifications-about-characteristics-value-changes-to-the-clients) to remote GATT clients. + +- Enable reading and writing values of characteristics and descriptors registered in the local GATT server + + You can [register callbacks to respond to read and write value requests from server clients](#respond-to-read-and-write-value-requests-from-server-clients). ## Prerequisites -To use the Application (in [mobile](../../api/latest/device_api/mobile/tizen/application.html) and [wearable](../../api/latest/device_api/wearable/tizen/application.html) applications) and Bluetooth (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html) applications) APIs, the application has to request permission by adding the following privileges to the `config.xml` file: +To use the Application (in [mobile](../../api/latest/device_api/mobile/tizen/application.html), [wearable](../../api/latest/device_api/wearable/tizen/application.html), and [tv](../../api/latest/device_api/tv/tizen/application.html) applications) and Bluetooth (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html) applications) APIs, the application has to request permission by adding the following privileges to the `config.xml` file: ``` ``` - -## Managing the Local Bluetooth Adapter - -You can enable or disable the local Bluetooth adapter, and set the device name using the system-provided service through the `ApplicationControl` interface (in [mobile](../../api/latest/device_api/mobile/tizen/application.html#ApplicationControl) and [wearable](../../api/latest/device_api/wearable/tizen/application.html#ApplicationControl) applications). +## Handle UUIDs and binary data + +With Bluetooth API, you can handle UUIDs and binary data. + +### Handle UUIDs +According to the [Bluetooth Core Specification](https://www.bluetooth.com/specifications/bluetooth-core-specification/), UUIDs that are used to represent Bluetooth objects can take the following three forms: + + - 128-bit representation: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", where each 'X' stands for a hexadecimal digit. + For example: "198d3a9c-e21a-4f72-a48b-39a6bad7e583". + - 32-bit representation: "D1D2D3D4D5D6D7D8", equivalent to "D1D2D3D4D5D6D7D8-0000-1000-8000-00805F9B34FB", where D1..D8 stand for hexadecimal digits. + For example: "e72ad71b". + - 16-bit representation: "D1D2D3D4", equivalent to "0000D1D2D3D4-0000-1000-8000-00805F9B34FB", where D1..D4 stand for hexadecimal digits. + For example: "d182". + +Functions taking UUIDs as parameters accept any of these three forms and make appropriate conversions. +Each UUID returned from a function and each UUID attribute of an object may be a 16-bit, 32-bit or 128-bit UUID. +All exceptions to these rules are noted in the API reference for [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html) devices. +Bluetooth API functions are case-insensitive with regard to UUIDs. Lowercase (abcdef) and uppercase (ABCDEF) characters are recognized as valid hexadecimal digits. + +The 128-bit UUID that is the base for UUIDs having 16-bit or 32-bit equivalents is defined available through the API in `BluetoothManager` as `BASE_UUID`. + +`BluetoothManager` methods to manipulate UUIDs: + + - `uuidTo128bit()` converts a UUID to its 128-bit equivalent: + ``` + var uuidFrom16bits = tizen.bluetooth.uuidTo128bit("1234"); + var uuidFrom32bits = tizen.bluetooth.uuidTo128bit("ab5690ef"); + var uuidFrom128bits = tizen.bluetooth.uuidTo128bit("abcdef01-2345-6789-abcd-ef0123456789"); + ``` + + uuidFrom16bits is equal to "00001234-0000-1000-8000-00805f9b34fb" + uuidFrom32bits is equal to "ab5690ef-0000-1000-8000-00805f9b34fb" + uuidFrom128bits is equal to "abcdef01-2345-6789-abcd-ef0123456789" + + - `uuidToShortestPossible()` converts a UUID to its shortest possible equivalent: + ``` + var from16Bit = tizen.bluetooth.uuidToShortestPossible("1234"); + var from32Bit = tizen.bluetooth.uuidToShortestPossible("0000acdf"); + var from128BitFirst = tizen.bluetooth.uuidToShortestPossible("ab5690ef-0000-1000-8000-00805F9B34FB"); + var from128BitSecond = tizen.bluetooth.uuidToShortestPossible("abcdef01-2345-6789-abcd-ef0123456789"); + ``` + + from16Bit is equal to "1234" + from32Bit is equal to "acdf" + from128BitFirst is equal to "ab5690ef" + from128BitSecond is equal to "abcdef01-2345-6789-abcd-ef0123456789" + + - `uuidsEqual()` tests if two UUIDs have a single common equivalent UUID: + ``` + var first = tizen.bluetooth.uuidsEqual("1234", "00001234"); + var second = tizen.bluetooth.uuidsEqual("ab5690ef", "ab5690ef-0000-1000-8000-00805F9B34FB"); + var third = tizen.bluetooth.uuidsEqual("abcdef01-2345-6789-abcd-ef0123456789", "abcdef01"); + ``` + + Both `first`, and `second` are `true`. `third` is false. + +### Handle binary data +The `Bytes` type, that aggregates all types in Bluetooth API used to pass binary data. It can be either a `byte[]` or a `DOMString` or a `Uint8Array`. + +`BluetoothManager` methods to manipulate binary data: + - `toByteArray()` converts a variable from any of the `Bytes` types to `byte[]`: + ``` + var dataInt8Array = new Int8Array([24, 177]); + var dataUint8Array = new Uint8Array([24, 177]); + var dataString = "0x18b1"; + + var first = tizen.bluetooth.toByteArray(dataInt8Array); + var second = tizen.bluetooth.toByteArray(dataUint8Array); + var third = tizen.bluetooth.toByteArray(dataString); + ``` + `first`, `second`, and `third` variables are equal arrays. + + - `toDOMString()` converts a variable from any of the `Bytes` types to `DOMString`: + ``` + var dataInt8Array = new Int8Array([24, 177]); + var dataUint8Array = new Uint8Array([24, 177]); + var dataString = "0x18b1"; + + var first = tizen.bluetooth.toDOMString(dataInt8Array); + var second = tizen.bluetooth.toDOMString(dataUint8Array); + var third = tizen.bluetooth.toDOMString(dataString); + ``` + `first`, `second`, and `third` variables are equal arrays. + + - `toUint8Array()` converts a variable from any of the `Bytes` types to `Uint8Array`: + ``` + var dataInt8Array = new Int8Array([24, 177]); + var dataUint8Array = new Uint8Array([24, 177]); + var dataString = "0x18b1"; + + var first = tizen.bluetooth.toUint8Array(dataInt8Array); + var second = tizen.bluetooth.toUint8Array(dataUint8Array); + var third = tizen.bluetooth.toUint8Array(dataString); + ``` + `first`, `second`, and `third` variables are equal. + +## Manage the Local Bluetooth Adapter + +You can enable or disable the local Bluetooth adapter, and set the device name using the system-provided service through the `ApplicationControl` interface (in [mobile](../../api/latest/device_api/mobile/tizen/application.html#ApplicationControl), [wearable](../../api/latest/device_api/wearable/tizen/application.html#ApplicationControl), and [tv](../../api/latest/device_api/tv/tizen/application.html#ApplicationControl) applications). To use the Bluetooth functionality of the device, you must switch the Bluetooth adapter on. The Bluetooth API does not provide a method to enable or disable the Bluetooth adapter of the device directly. When Bluetooth is required, you must request the built-in Settings application on the device to let the user enable or disable Bluetooth. @@ -83,7 +210,7 @@ To use the Bluetooth functionality of the device, you must switch the Bluetooth ![Bluetooth setting screen](./media/bluetooth_onoff.png) -1. Retrieve a `BluetoothAdapter` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothAdapter) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothAdapter) applications) with the `getDefaultAdapter()` method and prepare the `ApplicationControl` object (in [mobile](../../api/latest/device_api/mobile/tizen/application.html#ApplicationControl) and [wearable](../../api/latest/device_api/wearable/tizen/application.html#ApplicationControl) applications) to request the Bluetooth switching operation: +1. Retrieve a `BluetoothAdapter` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothAdapter), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothAdapter), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothAdapter) applications) with the `getDefaultAdapter()` method and prepare the `ApplicationControl` object (in [mobile](../../api/latest/device_api/mobile/tizen/application.html#ApplicationControl), [wearable](../../api/latest/device_api/wearable/tizen/application.html#ApplicationControl), and [tv](../../api/latest/device_api/tv/tizen/application.html#ApplicationControl) applications) to request the Bluetooth switching operation: ``` var bluetoothSwitchAppControl = new tizen.ApplicationControl('http://tizen.org/appcontrol/operation/edit', null, 'application/x-bluetooth-on-off'); @@ -101,7 +228,7 @@ To use the Bluetooth functionality of the device, you must switch the Bluetooth } ``` -3. Define the reply callback of the application control which implements the `ApplicationControlDataArrayReplyCallback` (in [mobile](../../api/latest/device_api/mobile/tizen/application.html#ApplicationControlDataArrayReplyCallback) and [wearable](../../api/latest/device_api/wearable/tizen/application.html#ApplicationControlDataArrayReplyCallback) applications): +3. Define the reply callback of the application control which implements the `ApplicationControlDataArrayReplyCallback` (in [mobile](../../api/latest/device_api/mobile/tizen/application.html#ApplicationControlDataArrayReplyCallback), [wearable](../../api/latest/device_api/wearable/tizen/application.html#ApplicationControlDataArrayReplyCallback), and [tv](../../api/latest/device_api/tv/tizen/application.html#ApplicationControlDataArrayReplyCallback) applications): ``` var serviceReply = { @@ -131,7 +258,7 @@ To use the Bluetooth functionality of the device, you must switch the Bluetooth } ``` -5. To display the Bluetooth visibility switch, use the `application/x-bluetooth-visibility` MIME option. Bluetooth visibility means that the device is discoverable by other Bluetooth devices. +5. To display the Bluetooth visibility switch, use the `application/x-bluetooth-visibility` MIME option. Bluetooth visibility means that the device is discoverable by other Bluetooth devices: ``` var bluetoothVisibilityAppControl = new tizen.ApplicationControl('http://tizen.org/appcontrol/operation/edit', null, 'application/x-bluetooth-visibility'); @@ -152,23 +279,23 @@ To use the Bluetooth functionality of the device, you must switch the Bluetooth tizen.application.launchAppControl(bluetoothVisibilityAppControl, null, null, launchVisibilityError, serviceVisibilityReply); ``` -6. Set a friendly name for the device using the `setName()` method. - - The name helps to recognize the device in a list of [retrieved devices](#discovering-bluetooth-devices). +6. Set a friendly name for the device using the `setName()` method. The name helps to recognize the device in a list of [retrieved devices](#discover-bluetooth-devices): ``` adapter.setName(chatServerName); ``` -## Discovering Bluetooth Devices +## Manage remote devices + +### Discover Bluetooth devices -The device discovery process can retrieve multiple types of Bluetooth devices, such as printers, mobile phones, and headphones. To find the kind of devices you want to communicate with, the `BluetoothClass` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothClass) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothClass) applications) is used to define characteristics and capabilities of a Bluetooth device. The `BluetoothClassDeviceMajor` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothClassDeviceMajor) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothClassDeviceMajor) applications) and `BluetoothClassDeviceMinor` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothClassDeviceMinor) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothClassDeviceMinor) applications) specify the identifiers for major and minor Class of Device (CoD). +The device discovery process can retrieve multiple types of Bluetooth devices, such as printers, mobile phones, and headphones. To find the kind of devices you want to communicate with, the `BluetoothClass` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothClass), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothClass), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothClass) applications) is used to define characteristics and capabilities of a Bluetooth device. The `BluetoothClassDeviceMajor` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothClassDeviceMajor), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothClassDeviceMajor), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothClassDeviceMajor) applications), and `BluetoothClassDeviceMinor` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothClassDeviceMinor), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothClassDeviceMinor), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothClassDeviceMinor) applications) specify the identifiers for major and minor Class of Device (CoD). You can also retrieve the known devices which were bonded or found in a prior discovery process. To search for remote devices and get the known devices: -1. Retrieve a `BluetoothAdapter` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothAdapter) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothAdapter) applications) with the `getDefaultAdapter()` method: +1. Retrieve a `BluetoothAdapter` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothAdapter), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothAdapter), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothAdapter) applications) with the `getDefaultAdapter()` method: ``` var adapter = tizen.bluetooth.getDefaultAdapter(); @@ -176,7 +303,7 @@ To search for remote devices and get the known devices: 2. To search for remote devices, use the `discoverDevices()` method. - The results of the search are returned in the `BluetoothDiscoverDevicesSuccessCallback` (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothDiscoverDevicesSuccessCallback) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothDiscoverDevicesSuccessCallback) applications). + The results of the search are returned in the `BluetoothDiscoverDevicesSuccessCallback` (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothDiscoverDevicesSuccessCallback), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothDiscoverDevicesSuccessCallback), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothDiscoverDevicesSuccessCallback) applications): ``` var discoverDevicesSuccessCallback = { @@ -190,12 +317,12 @@ To search for remote devices and get the known devices: adapter.discoverDevices(discoverDevicesSuccessCallback, null); ``` - > **Note** + > [!NOTE] > To allow other Bluetooth devices to find your device, you must set the device to be visible through the system settings. 3. To retrieve known devices (which have been previously paired or searched for), use the `getKnownDevices()` method. - The results of the search are returned in the `BluetoothDeviceArraySuccessCallback` (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothDeviceArraySuccessCallback) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothDeviceArraySuccessCallback) applications). + The results of the search are returned in the `BluetoothDeviceArraySuccessCallback` (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothDeviceArraySuccessCallback), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothDeviceArraySuccessCallback), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothDeviceArraySuccessCallback) applications): ``` /* When a known device is found */ @@ -207,11 +334,11 @@ To search for remote devices and get the known devices: adapter.getKnownDevices(onGotDevices); ``` -## Creating a Bond with a Bluetooth Device +### Create a bond with a Bluetooth device To create a bond with a Bluetooth device: -1. Retrieve a `BluetoothAdapter` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothAdapter) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothAdapter) applications) with the `getDefaultAdapter()` method: +1. Retrieve a `BluetoothAdapter` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothAdapter), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothAdapter), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothAdapter) applications) with the `getDefaultAdapter()` method: ``` var adapter = tizen.bluetooth.getDefaultAdapter(); @@ -231,8 +358,8 @@ To create a bond with a Bluetooth device: adapter.createBonding('35:F4:59:D1:7A:03', onBondingSuccessCallback, onErrorCallback); ``` - > **Note** - > The MAC address of the Bluetooth device is a `BluetoothAddress` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothAddress) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothAddress) applications). You can get the MAC address of the peer device from the `BluetoothDevice` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothDevice) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothDevice) applications), which is returned in the success callback of the `BluetoothAdapter`'s `getKnownDevices()` and `discoverDevices()` methods. + > [!NOTE] + > The MAC address of the Bluetooth device is a `BluetoothAddress` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothAddress), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothAddress), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothAddress) applications). You can get the MAC address of the peer device from the `BluetoothDevice` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothDevice), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothDevice), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothDevice) applications), which is returned in the success callback of the `BluetoothAdapter`'s `getKnownDevices()` and `discoverDevices()` methods. 3. To end the bond with a remote device, use the `destroyBonding()` method: @@ -240,17 +367,19 @@ To create a bond with a Bluetooth device: adapter.destroyBonding('35:F4:59:D1:7A:03'); ``` -## Connecting to and Exchanging Data with a Bluetooth Device +### Connect to and exchange data with a Bluetooth device -When you attempt to open a connection to another device, a Service Discovery Protocol (SDP) look-up is performed on the device, and the protocol and channel to be used for the connection are determined. If a connection is established and the socket is opened successfully, a `BluetoothSocket` instance (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothSocket) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothSocket) applications) with an open state is returned. The socket is subsequently used for exchanging data between the connected devices. +When you attempt to open a connection to another device, a Service Discovery Protocol (SDP) look-up is performed on the device, and the protocol and channel to be used for the connection are determined. If a connection is established and the socket is opened successfully, a `BluetoothSocket` instance (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothSocket), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothSocket), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothSocket) applications) with an open state is returned. The socket is subsequently used for exchanging data between the connected devices. The Radio Frequency Communication (RFCOMM) is a set of transport protocols which allows multiple simultaneous connections to a device. If a device allows other devices to use its functionalities through this kind of connection, it is said to provide a service and it is called a server device. The devices that request the service are called client devices. To connect to services provided by a server device to the client devices: -1. Retrieve a `BluetoothAdapter` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothAdapter) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothAdapter) applications) with the `getDefaultAdapter()` method: +1. Retrieve a `BluetoothAdapter` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothAdapter), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothAdapter), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothAdapter) applications) with the `getDefaultAdapter()` method: - `var adapter = tizen.bluetooth.getDefaultAdapter();` + ``` + var adapter = tizen.bluetooth.getDefaultAdapter(); + ``` 2. To register a service and allow client devices to connect to it, use the `registerRFCOMMServiceByUUID()` method on the server device: @@ -258,12 +387,12 @@ To connect to services provided by a server device to the client devices: adapter.registerRFCOMMServiceByUUID(serviceUUID, 'My service'); ``` - > **Note** - > For P2P communication between 2 instances of the same application, the UUID can be hard-coded in your application. To retrieve the UUID of a Bluetooth device, use the `BluetoothDevice` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothDevice) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothDevice) applications). The object has an array of UUIDs available for the device. + > [!NOTE] + > For P2P communication between two instances of the same application, the UUID can be hard-coded in your application. To retrieve the UUID of a Bluetooth device, use the `BluetoothDevice` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothDevice), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothDevice), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothDevice) applications). The object has an array of UUIDs available for the device. - When the service has been successfully registered, the `BluetoothServiceSuccessCallback` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothServiceSuccessCallback) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothServiceSuccessCallback) applications) is triggered. + When the service has been successfully registered, the `BluetoothServiceSuccessCallback` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothServiceSuccessCallback), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothServiceSuccessCallback), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothServiceSuccessCallback) applications) is triggered. -3. Before establishing a connection, your device must be bonded with a peer device. For more information, see [Creating a Bond with a Bluetooth Device](#creating-a-bond-with-a-bluetooth-device). +3. Before establishing a connection, your device must be bonded with a peer device. For more information, see [Create a Bond with a Bluetooth Device](#create-a-bond-with-a-bluetooth-device). 4. To connect to the server device, use the `connectToServiceByUUID()` method on the client device: @@ -276,7 +405,7 @@ To connect to services provided by a server device to the client devices: }); ``` - When a connection between 2 devices is established, the `BluetoothSocketSuccessCallback` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothSocketSuccessCallback) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothSocketSuccessCallback) applications) on the client device and the `onconnect` event handler in the `BluetoothServiceHandler` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothServiceHandler) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothServiceHandler) applications) on the server device are triggered. + When a connection between two devices is established, the `BluetoothSocketSuccessCallback` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothSocketSuccessCallback), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothSocketSuccessCallback), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothSocketSuccessCallback) applications) on the client device and the `onconnect` event handler in the `BluetoothServiceHandler` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothServiceHandler), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothServiceHandler), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothServiceHandler) applications) on the server device are triggered. 5. To send data to the peer device, use the `writeData()` method: @@ -295,12 +424,13 @@ To connect to services provided by a server device to the client devices: When an incoming message is received from the peer device, the `onmessage` event handler in the `BluetoothSocket` interface is triggered. -## Discovering Bluetooth Low Energy Devices + +### Discover Bluetooth Low Energy devices To search for remote Bluetooth devices: -1. Define a scan event handler by implementing the `BluetoothLEScanCallback` callback (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEScanCallback) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEScanCallback) applications). - The callback is invoked when a remote device has been detected. +1. Define a scan event handler by implementing the `BluetoothLEScanCallback` callback (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEScanCallback), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEScanCallback), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothLEScanCallback) applications). + The callback is invoked when a remote device has been detected: ``` function successcallback(device) { @@ -308,10 +438,10 @@ To search for remote Bluetooth devices: } ``` - > **Note** + > [!NOTE] > To allow other Bluetooth devices to find your device, you must set the device to be visible through the system settings. -2. Retrieve a `BluetoothLEAdapter` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter) applications) with the `getLEAdapter()` method of the `BluetoothManager` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothManager) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothManager) applications): +2. Retrieve a `BluetoothLEAdapter` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothLEAdapter) applications) with the `getLEAdapter()` method of the `BluetoothManager` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothManager), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothManager), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothManager) applications): ``` var adapter = tizen.bluetooth.getLEAdapter(); @@ -329,48 +459,11 @@ To search for remote Bluetooth devices: adapter.stopScan(); ``` -## Managing the Advertising Options - -The Bluetooth Low Energy technology allows a device to broadcast some information without a connection between devices. The Bluetooth Low Energy API provides methods to control this advertising (broadcasting). - -To control what information is advertised by the device: - -1. Retrieve a `BluetoothLEAdapter` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter) applications) with the `getLEAdapter()` method of the `BluetoothManager` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothManager) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothManager) applications): - - ``` - var adapter = tizen.bluetooth.getLEAdapter(); - ``` - -2. Set up options and start advertising with the `startAdvertise()` method of the `BluetoothLEAdapter` interface: - - ``` - var advertiseData = new tizen.BluetoothLEAdvertiseData({ - includeName: true, - serviceuuids: ['180f'] /* 180F is 16bit Battery Service UUID */ - }); - var connectable = true; - - adapter.startAdvertise(advertiseData, 'ADVERTISE', function onstate(state) { - console.log('Advertising configured: ' + state); - }, function(error) { - console.log('startAdvertise() failed: ' + error.message); - }, 'LOW_LATENCY', connectable); - ``` - - > **Note** - > To learn how to make your mobile device visible to other Bluetooth devices, see [Managing the Local Bluetooth Adapter](#managing-the-local-bluetooth-adapter). - -3. To disable the advertising, use the `stopAdvertise()` method of the `BluetoothLEAdapter` interface: - - ``` - adapter.stopAdvertise(); - ``` - -## Connecting to a Bluetooth Low Energy Device +### Connect to a Bluetooth Low Energy device To connect to other Bluetooth Low Energy devices: -1. Retrieve a `BluetoothLEAdapter` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter) applications) with the `getLEAdapter()` method of the `BluetoothManager` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothManager) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothManager) applications): +1. Retrieve a `BluetoothLEAdapter` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothLEAdapter) applications) with the `getLEAdapter()` method of the `BluetoothManager` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothManager), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothManager), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothManager) applications): ``` var adapter = tizen.bluetooth.getLEAdapter(); @@ -388,9 +481,9 @@ To connect to other Bluetooth Low Energy devices: } ``` -3. Define a callback for the scan operation that connects to a found device and stops the scan. +3. Define a callback for the scan operation that connects to a not connected found device and stops the scan. - Within the callback request, establish a connection with the found device using the `connect()` method of the `BluetoothLEDevice` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice) applications): + Within the callback request, check if the found device is connected and establish a connection with the not connected device using the `isConnected()` and `connect()` methods of the `BluetoothLEDevice` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothLEDevice) applications): ``` var remoteDevice = null; @@ -398,9 +491,10 @@ To connect to other Bluetooth Low Energy devices: function onDeviceFound(device) { if (remoteDevice === null) { remoteDevice = device; - console.log('Found device ' + device.name + '. Connecting...'); - - device.connect(connectSuccess, connectFail); + if (!device.isConnected()) { + console.log('Found not connected device ' + device.name + '. Connecting...'); + device.connect(connectSuccess, connectFail); + } } adapter.stopScan(); @@ -419,17 +513,17 @@ To connect to other Bluetooth Low Energy devices: remoteDevice.disconnect(); ``` -## Receiving Notifications on Connection State Changes +### Receive notifications on connection state changes To receive notifications whenever the device connection is established or lost: -1. Retrieve a `BluetoothLEAdapter` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter) applications) with the `getLEAdapter()` method of the `BluetoothManager` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothManager) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothManager) applications): +1. Retrieve a `BluetoothLEAdapter` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothLEAdapter) applications) with the `getLEAdapter()` method of the `BluetoothManager` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothManager), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothManager), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothManager) applications): ``` var adapter = tizen.bluetooth.getLEAdapter(); ``` -2. Define a connection state change listener by implementing the `BluetoothLEConnectChangeCallback` callback (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEConnectChangeCallback) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEConnectChangeCallback) applications): +2. Define a connection state change listener by implementing the `BluetoothLEConnectChangeCallback` callback (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEConnectChangeCallback), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEConnectChangeCallback), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothLEConnectChangeCallback) applications): ``` var connectionListener = { @@ -444,7 +538,7 @@ To receive notifications whenever the device connection is established or lost: 3. Define a callback for the scan operation that connects to a found device and stops the scan. - Within the callback, register a connection state change listener using the `addConnectStateChangeListener()` method of the `BluetoothLEDevice` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice) applications): + Within the callback, register a connection state change listener using the `addConnectStateChangeListener()` method of the `BluetoothLEDevice` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothLEDevice) applications): ``` var remoteDevice = null; @@ -476,13 +570,13 @@ To receive notifications whenever the device connection is established or lost: remoteDevice.removeConnectStateChangeListener(watchId); ``` -## Retrieving Bluetooth GATT Services +### Retrieve Bluetooth GATT services To retrieve a list of GATT services (Generic Attribute) provided by a remote device: -1. [Connect to a Bluetooth Low Energy device](#connecting-to-a-bluetooth-low-energy-device). +1. [Connect to a Bluetooth Low Energy device](#connect-to-a-bluetooth-low-energy-device). -2. Define a connection state change listener by implementing the `BluetoothLEConnectChangeCallback` (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEConnectChangeCallback) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEConnectChangeCallback) applications): +2. Define a connection state change listener by implementing the `BluetoothLEConnectChangeCallback` (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEConnectChangeCallback), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEConnectChangeCallback), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothLEConnectChangeCallback) applications): ``` function showGATTService(service, indent) { @@ -490,7 +584,7 @@ To retrieve a list of GATT services (Generic Attribute) provided by a remote dev indent = ''; } - console.log(indent + 'Service ' + service.uuid + '. Has ' + service.characteristics.length + + console.log(indent + 'Service ' + service.serviceUuid + '. Has ' + service.characteristics.length + ' characteristics and ' + service.services.length + ' sub-services.'); for (var i = 0; i < service.services.length; i++) { @@ -499,7 +593,7 @@ To retrieve a list of GATT services (Generic Attribute) provided by a remote dev } ``` -3. Retrieve a list of GATT service UUIDs from the `uuids` attribute of the `BluetoothLEDevice` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice) applications): +3. Retrieve a list of GATT service UUIDs from the `uuids` attribute of the `BluetoothLEDevice` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothLEDevice) applications): ``` var serviceUUIDs = remoteDevice.uuids; @@ -525,13 +619,13 @@ To retrieve a list of GATT services (Generic Attribute) provided by a remote dev console.log('Services length ' + services.length); ``` -## Accessing the Bluetooth GATT Characteristic Value +### Access the Bluetooth GATT characteristic value To read and write a value of the Bluetooth characteristic: -1. [Connect to a Bluetooth Low Energy device](#connecting-to-a-bluetooth-low-energy-device). +1. [Connect to a Bluetooth Low Energy device](#connect-to-a-bluetooth-low-energy-device). -2. Retrieve a list of GATT service UUIDs from the `uuids` attribute of the `BluetoothLEDevice` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice) applications): +2. Retrieve a list of GATT service UUIDs from the `uuids` attribute of the `BluetoothLEDevice` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothLEDevice) applications): ``` var serviceUUIDs = remoteDevice.uuids; @@ -543,13 +637,13 @@ To read and write a value of the Bluetooth characteristic: var gattService = remoteDevice.getService(serviceUUIDs[0]); ``` -4. Select an interesting characteristic from the `characteristics` attribute of the `BluetoothGATTService` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTService) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTService) applications). In this example, the first characteristic is used: +4. Select an interesting characteristic from the `characteristics` attribute of the `BluetoothGATTService` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTService), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTService), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothGATTService) applications). The characteristic may be selected by the `uuid` attribute: ``` - var property = gattService.characteristics[0]; + var property = gattService.characteristics.find(characteristic => characteristic.uuid === "abcd"); ``` -5. Define a callback implementing the `ReadValueSuccessCallback` callback (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#ReadValueSuccessCallback) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#ReadValueSuccessCallback) applications), which receives the value of the characteristic: +5. Define a callback implementing the `ReadValueSuccessCallback` callback (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#ReadValueSuccessCallback), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#ReadValueSuccessCallback), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#ReadValueSuccessCallback) applications), which receives the value of the characteristic: ``` function readSuccess(value) { @@ -561,7 +655,7 @@ To read and write a value of the Bluetooth characteristic: } ``` -6. To retrieve the GATT characteristic value, use the `readValue()` method of the `BluetoothGATTCharacteristic` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTCharacteristic) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTCharacteristic) applications): +6. To retrieve the GATT characteristic value, use the `readValue()` method of the `BluetoothGATTCharacteristic` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTCharacteristic), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTCharacteristic), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothGATTCharacteristic) applications): ``` if (!property.isReadable) { @@ -589,13 +683,13 @@ To read and write a value of the Bluetooth characteristic: property.writeValue(newValue, writeSuccess, writeFail); ``` -## Receiving Notifications on Characteristic Value Changes +### Receive notifications on characteristic value changes To monitor changes in a Bluetooth characteristic: -1. [Connect to a Bluetooth Low Energy device](#connecting-to-a-bluetooth-low-energy-device). +1. [Connect to a Bluetooth Low Energy device](#connect-to-a-bluetooth-low-energy-device). -2. Retrieve a list of GATT service UUIDs from the `uuids` attribute of the `BluetoothLEDevice` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice) applications): +2. Retrieve a list of GATT service UUIDs from the `uuids` attribute of the `BluetoothLEDevice` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothLEDevice) applications): ``` var serviceUUIDs = remoteDevice.uuids; @@ -607,13 +701,13 @@ To monitor changes in a Bluetooth characteristic: var gattService = remoteDevice.getService(serviceUUIDs[0]); ``` -4. Select an interesting characteristic from the `characteristics` attribute of the `BluetoothGATTService` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTService) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTService) applications). In this example, the first characteristic is used: +4. Select an interesting characteristic from the `characteristics` attribute of the `BluetoothGATTService` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTService), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTService), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothGATTService) applications). In this example, the first characteristic is used: ``` var property = gattService.characteristics[0]; ``` -5. Define a callback implementing the `ReadValueSuccessCallback` callback (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#ReadValueSuccessCallback) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#ReadValueSuccessCallback) applications), which receives the value of the characteristic every time the value changes: +5. Define a callback implementing the `ReadValueSuccessCallback` callback (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#ReadValueSuccessCallback), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#ReadValueSuccessCallback), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#ReadValueSuccessCallback) applications), which receives the value of the characteristic every time the value changes: ``` function onValueChange(value) { @@ -621,7 +715,7 @@ To monitor changes in a Bluetooth characteristic: } ``` -6. Register a value change listener using the `addValueChangeListener()` method of the `BluetoothGATTCharacteristic` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTCharacteristic) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTCharacteristic) applications): +6. Register a value change listener using the `addValueChangeListener()` method of the `BluetoothGATTCharacteristic` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTCharacteristic), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTCharacteristic), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothGATTCharacteristic) applications): ``` var watchId = property.addValueChangeListener(onValueChange); @@ -633,13 +727,13 @@ To monitor changes in a Bluetooth characteristic: property.removeValueChangeListener(watchId); ``` -## Accessing the Bluetooth GATT Descriptor Value +### Access the Bluetooth GATT descriptor value To read and write a value of the Bluetooth descriptor: -1. [Connect to a Bluetooth Low Energy device](#connecting-to-a-bluetooth-low-energy-device). +1. [Connect to a Bluetooth Low Energy device](#connect-to-a-bluetooth-low-energy-device). -2. Retrieve a list of GATT service UUIDs from the `uuids` attribute of the `BluetoothLEDevice` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice) applications): +2. Retrieve a list of GATT service UUIDs from the `uuids` attribute of the `BluetoothLEDevice` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEDevice), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEDevice), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothLEDevice) applications): ``` var serviceUUIDs = remoteDevice.uuids; @@ -651,19 +745,19 @@ To read and write a value of the Bluetooth descriptor: var gattService = remoteDevice.getService(serviceUUIDs[0]); ``` -4. Select an interesting characteristic from the `characteristics` attribute of the `BluetoothGATTService` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTService) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTService) applications). In this example, the first characteristic is used: +4. Select an interesting characteristic from the `characteristics` attribute of the `BluetoothGATTService` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTService), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTService), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothGATTService) applications). The characteristic may be selected by the `uuid` attribute: ``` - var characteristic = gattService.characteristics[0]; + var characteristic = gattService.characteristics.find(characteristic => characteristic.uuid === "abcd"); ``` -5. Select an interesting descriptor from the `descriptors` attribute of the `BluetoothGATTCharacteristic` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTCharacteristic) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTCharacteristic) applications). In this example, the first descriptor is used: +5. Select an interesting descriptor from the `descriptors` attribute of the `BluetoothGATTCharacteristic` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTCharacteristic), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTCharacteristic), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothGATTCharacteristic) applications). The descriptor may be selected by the `uuid` attribute: ``` - var descriptor = characteristic.descriptors[0]; + var descriptor = characteristic.descriptors.find(descriptor => descriptor.uuid === "dcba"); ``` -6. Define a callback implementing the `ReadValueSuccessCallback` callback (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#ReadValueSuccessCallback) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#ReadValueSuccessCallback) applications), which receives the value of the descriptor: +6. Define a callback implementing the `ReadValueSuccessCallback` callback (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#ReadValueSuccessCallback), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#ReadValueSuccessCallback), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#ReadValueSuccessCallback) applications), which receives the value of the descriptor: ``` function readSuccess(value) { @@ -675,7 +769,7 @@ To read and write a value of the Bluetooth descriptor: } ``` -7. To retrieve the GATT descriptor value, use the `readValue()` method of the `BluetoothGATTDescriptor` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTDescriptor) and [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTDescriptor) applications): +7. To retrieve the GATT descriptor value, use the `readValue()` method of the `BluetoothGATTDescriptor` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTDescriptor), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTDescriptor), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothGATTDescriptor) applications): ``` descriptor.readValue(readSuccess, readFail); @@ -697,8 +791,531 @@ To read and write a value of the Bluetooth descriptor: descriptor.writeValue(newValue, writeSuccess, writeFail); ``` +### Access the ATT MTU of connected device + +To get the ATT MTU value or request change of the ATT MTU value, follow these steps: + +1. [Connect to a Bluetooth Low Energy device](#connect-to-a-bluetooth-low-energy-device). +2. If the `device` has been connected call `getAttMtu()` on the `device` object to get current ATT MTU value: + ``` + var attMtu = device.getAttMtu(); + ``` +3. If the `device` is connected, call `requestAttMtuChange()` on the `device` object to request a change of the ATT MTU value. Pass desired ATT MTU value as an argument: + ``` + var newAttMtuValue = 64; + device.requestAttMtuChange(newAttMtuValue); + ``` + > [!NOTE] + > After calling `requestAttMtuChange()` ATT MTU value change should be accepted if both devices support new ATT MTU value according to the [Bluetooth Core Specification](https://www.bluetooth.com/specifications/bluetooth-core-specification/). + +### Receive notifications on ATT MTU changes + +To receive notifications on ATT MTU value changes: + +1. [Connect to a Bluetooth Low Energy device](#connect-to-a-bluetooth-low-energy-device). +2. If the `device` is connected, call `addAttMtuChangeListener()` providing as a parameter the callback to be called on each change of the ATT MTU value: + ``` + function attMtuChangeCallback(newAttMtuValue) { + console.log("ATT MTU value has changed to: " + newAttMtuValue); + } + var listenerId = device.addAttMtuChangeListener(attMtuChangeCallback); + ``` + The `listenerId` value stores an identifier of the listener, which is needed to remove the listener. +3. After setting up the listener with `addAttMtuChangeListener()`, the callback can be invoked by changing the ATT MTU value: + ``` + var newAttMtuValue = 50; + device.requestAttMtuChange(newAttMtuValue); + ``` + The change of ATT MTU value will trigger the callback. + > [!NOTE] + > After calling `requestAttMtuChange()` ATT MTU value change should be accepted if both devices support new ATT MTU value according to the [Bluetooth Core Specification](https://www.bluetooth.com/specifications/bluetooth-core-specification/). + +4. When a listener monitoring the ATT MTU value changes is no longer needed, you can remove it. To do this, call `removeAttMtuChangeListener()` providing the identifier of the listener you want to remove: + ``` + device.removeAttMtuChangeListener(listenerId); + ``` + After removing of the listener, changes of the ATT MTU value will no longer trigger the callback. + +### Manage the advertise options + +The Bluetooth Low Energy technology allows a device to broadcast some information without a connection between devices. The Bluetooth Low Energy API provides methods to control this advertising (broadcasting). + +To control what information is advertised by the device: + +1. Retrieve a `BluetoothLEAdapter` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothLEAdapter) applications) with the `getLEAdapter()` method of the `BluetoothManager` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothManager), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothManager), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothManager) applications): + + ``` + var adapter = tizen.bluetooth.getLEAdapter(); + ``` + +2. Set up options and start advertising with the `startAdvertise()` method of the `BluetoothLEAdapter` interface: + + ``` + var advertiseData = new tizen.BluetoothLEAdvertiseData({ + includeName: true, + serviceuuids: ['180f'] /* 180F is 16bit Battery Service UUID */ + }); + var connectable = true; + + adapter.startAdvertise(advertiseData, 'ADVERTISE', function onstate(state) { + console.log('Advertising configured: ' + state); + }, function(error) { + console.log('startAdvertise() failed: ' + error.message); + }, 'LOW_LATENCY', connectable); + ``` + + > [!NOTE] + > To learn how to make your mobile device visible to other Bluetooth devices, see [Manage the Local Bluetooth Adapter](#manage-the-local-bluetooth-adapter). + +3. To disable the advertising, use the `stopAdvertise()` method of the `BluetoothLEAdapter` interface: + + ``` + adapter.stopAdvertise(); + ``` + +## Manage the local GATT server + +### Start the server + +To start the local GATT server: + +1. Retrieve `BluetoothGATTServer` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTServer), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTServer), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothGATTServer) applications) with `getGATTServer()` method of the `BluetoothManager` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothManager), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothManager), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothManager) applications): + + ``` + var server = tizen.bluetooth.getGATTServer(); + ``` + +2. Set up callbacks and start the local GATT server with `start()` method of `BluetoothGATTServer` (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTServer), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTServer), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothGATTServer) applications) interface: + + ``` + var onSuccess = function() { + console.log("Server started successfully"); + }; + + var onError = function(error) { + console.error("Failed to start the server, error: " + error.message); + }; + + server.start(onSuccess, onError); + ``` + +### Stop the server + +To stop the local GATT server: + +1. Retrieve `BluetoothGATTServer` object (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTServer), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTServer), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothGATTServer) applications) with `getGATTServer()` method of the `BluetoothManager` interface (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothManager), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothManager), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothManager) applications): + + ``` + var server = tizen.bluetooth.getGATTServer(); + ``` + +2. Set up callbacks and stop the local GATT server with `stop()` method of `BluetoothGATTServer` (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTServer), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTServer), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothGATTServer) applications) interface: + + ``` + var onSuccess = function() { + console.log("Server stopped successfully"); + }; + + var onError = function(error) { + console.error("Failed to stop the server, error: " + error.message); + }; + + server.stop(onSuccess, onError); + ``` + +### Receive notifications on GATT connection state changes + +To receive notifications whenever a GATT connection with the device is established or lost: + +1. Define `BluetoothLEConnectChangeCallback`: + + ``` + var connectChangeCallback = { + onconnected: function(device) { + console.log("A device connected: " + device.address); + }, + ondisconnected: function(device) { + console.log("A device disconnected: " + device.address); + } + }; + ``` + +2. Add the defined callback with `addConnectStateChangeListener()` method (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothLEAdapter::addConnectStateChangeListener), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothLEAdapter::addConnectStateChangeListener), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothLEAdapter::addConnectStateChangeListener) applications): + + ``` + var adapter = tizen.bluetooth.getLEAdapter(); + var watchId = adapter.addConnectStateChangeListener(connectChangeCallback); + ``` + + The `watchId` value stores an identifier of the listener, which is needed to remove the listener. + +3. When a listener monitoring the connection changes is no longer needed, it can be removed: + + ``` + adapter.removeConnectStateChangeListener(watchId); + ``` + +### Access connection's ATT MTU + +To get the value of connection's ATT MTU value: + +1. Define the `ConnectionMtuCallback` and (optionally) the error callback: + + ``` + var connectionMtuCB = function(mtu) { + console.log("The ATT MTU value: " + mtu); + }; + + var errorCB = function(error) { + console.log("Cannot retrieve ATT MTU value, error: " + error.message); + }; + ``` + +2. Select proper remote client's address and get the value of ATT MTU with `getConnectionMtu()` method (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#BluetoothGATTServer::getConnectionMtu), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#BluetoothGATTServer::getConnectionMtu), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#BluetoothGATTServer::getConnectionMtu) applications): + + ``` + var clientAddress = "12:34:56:78:90:ab"; + var server = tizen.bluetooth.getGATTServer(); + server.getConnectionMtu(clientAddress, connectionMtuCB, errorCB); + ``` + +### Register services +To register a GATT service in the local server: + +1. Define the init data of the service and all of its components: + + ``` + var descriptorInitData = { + uuid: 'abcd' + /* Define more attributes, if needed */ + }; + + var characteristicInitData = { + uuid: '9876', + descriptors: [descriptorInitData] + /* Define more attributes, if needed */ + }; + + var includedServiceInitData = { + serviceUuid: '5678', + isPrimary: true + }; + + var serviceInitData = { + serviceUuid: '1234', + includedServices: [includedServiceInitData], + characteristics: [characteristicInitData], + isPrimary: true + }; + ``` + +2. Register the service in the local server: + + ``` + function successCallback() { + console.log('Service registered successfully'); + } + + function errorCallback(error) { + console.log('Registering GATT service failed: ' + error.message); + } + + var server = tizen.bluetooth.getGATTServer(); + server.registerService(serviceInitData, successCallback, errorCallback); + ``` + > [!NOTE] + > The service will be unregistered from the server when: + > - service's `unregister()` method is called, + > - server's `unregisterAllServices()` method is called, + > - application is reloaded, + > - application is closed. + +### Unregister services +GATT services can be unregistered either one at a time or all at once. + +To unregister a single service from the local GATT server: + +1. Choose the service to be unregistered: + ``` + var server = tizen.bluetooth.getGATTServer(); + var serviceToBeUnregistered = server.services[3]; + ``` + +2. Call `unregister()` method: + ``` + function successCallback() { + console.log('Service unregistered successfully'); + } + + function errorCallback(error) { + console.log('Unregistering GATT service failed: ' + error.message); + } + + serviceToBeUnregistered.unregister(successCallback, errorCallback); + ``` + > [!NOTE] + > After `unregister()` is called for the last registered service, the server is stopped. + > If new services are then registered, server's `start()` method has to be + > called to make them visible to clients. + +To unregister all services from the local GATT server at once, call server's +`unregisterAllServices()` method: + + ``` + function successCallback() { + console.log('All services unregistered successfully'); + } + + function errorCallback(error) { + console.log('Unregistering all GATT services failed: ' + error.message); + } + + var server = tizen.bluetooth.getGATTServer(); + server.unregisterAllServices(successCallback, errorCallback); + ``` + > [!NOTE] + > After the calling `unregisterAllServices()`, the server is stopped. + > If new services are then registered, server's `start()` method has to be + > called to make them visible to clients. + +### Send notifications about characteristic's value changes to the clients +GATT clients connected to the server running on the local device can register for updates of its characteristics' values. +The server can send two types of such updates - `notifications` and `indications`. +The difference in notifications and indications is that the clients receiving indications have to acknowledge them. This means that the clients must send a message back to the server, telling that they received the new value. Clients do not acknowledge notifications. + +Notifications and indications are not enabled in characteristics by default. +To enable notifications or indications in a characteristic: + +1. Set its `isNotify` or `isIndication` property: + + ``` + var notificationEnabledCharacteristicInitData = { + uuid: '1234', + isNotify: true // or set isIndication to enable indications + /* Define more attributes, if needed */ + }; + ``` +2. The characteristic requires a special kind of descriptor, Client Characteristic Configuration Descriptor (CCCD). +For more details about CCCD, see [Bluetooth Core Specification](https://www.bluetooth.com/specifications/bluetooth-core-specification/). +To define a CCCD and add it to the characteristic: + + ``` + /* Set the exact UUID, properties and permissions as below */ + var cccdInitData = { + uuid: '2902', // "2902" UUID is reserved for CCCDs + isReadable: true, + isWritable: true, + readPermission: true, + writePermission: true + }; + + notificationEnabledCharacteristicInitData.descriptors = [cccdInitData]; + ``` +3. The characteristic can be now added to a service: + + ``` + var serviceInitData = { + serviceUuid: '1234', + characteristics: [notificationEnabledCharacteristicInitData] + }; + ``` +`notificationEnabledCharacteristicInitData` is now ready to be added to a service that will [be registered in a local GATT server](#register-services). + +To update clients on characteristic's value change after registering the service: + +1. Define a `NotificationCallback` (in [mobile](../../api/latest/device_api/mobile/tizen/bluetooth.html#NotificationCallback), [wearable](../../api/latest/device_api/wearable/tizen/bluetooth.html#NotificationCallback), and [tv](../../api/latest/device_api/tv/tizen/bluetooth.html#NotificationCallback) applications): + + ``` + var notificationCallback = { + onnotificationsuccess: function(clientAddress) { + /* + * When sending a notification, this callback will be called when the + * notification is sent from the server to the client addressed + * by clientAddress. + * + * When sending an indication, this callback will be called when the + * acknowledgment from the client addressed by clientAddress + * is received. + */ + }, + onnotificationfail: function(clientAddress, error) { + /* + * This callback will be called when something goes wrong in the + * process of sending a notification/indication to the client + * addressed by clientAddress or receiving the acknowledgment + * from that client. + */ + }, + onnotificationfinish: function(clientAddress) { + /* + * This callback will be called when the process of sending notifications + * or indications is finished. + * clientAddress is the address of the last client updated on the change + * of the value. + */ + } + }; + ``` + +2. Send the notification: + + ``` + // Choose the characteristic, that has changed its value + var characteristic = server.services[0].characteristics[0]; + var newValue = '55'; + + function errorCallback(error) { + console.log('Sending notification failed: ' + error.message); + } + + /* + * Only one client will be updated on the change. + * To simultaneously update all the clients, that subscribed for + * notifications/indications, set targetClient to null. + */ + var targetClient = '12:34:56:78:90:ab'; + + characteristic.notifyAboutValueChange(newValue, targetClient, + notificationCallback, errorCallback); + ``` +The notification is sent and `notificationCallback`'s members will be called soon. + +### Respond to read and write value requests from server clients + +In order to react and respond to the read and write value requests from a client connected to the server running on the device, the callbacks need to be set on the characteristics or on the descriptors. + +To set a callback for read or write value request on a characteristic or a descriptor: + +1. Prepare a GATT service containing at least one characteristic or a characteristic with at least one descriptor, that can be read or written: + ``` + var exampleDescriptor = { + uuid: "0155", + readPermission: true, + writePermission: true + }; + + var exampleCharacteristic = { + uuid: "0180", + descriptors: [exampleDescriptor], + isReadable: true, + isWritable: true, + readPermission: true, + writePermission: true + }; + + var gattService = { + serviceUuid: "0955", + isPrimary: true, + includedServices: [], + characteristics: [exampleCharacteristic] + }; + ``` + +2. Register the service: + ``` + var registerServiceSuccesCB = function() { + console.log("Service successfully registered!"); + }; + + var registerServiceErrorCB = function(error) { + console.log("Service not registered, error: " + error.name + "; " + error.message); + }; + + var server = tizen.bluetooth.getGATTServer(); + + server.registerService(gattService, registerServiceSuccesCB, registerServiceErrorCB); + ``` + +3. Start the GATT server: + ``` + var serverStartSuccessCB = function() { + console.log("Server started successfully!"); + }; + + var serverStartErrorCB = function(error) { + console.error("Server didn't start, error: " + error.name + "; " + error.message); + }; + + server.start(serverStartSuccessCB, serverStartErrorCB); + ``` + +4. Optional callbacks that are used by the functions that set the callbacks to the read value requests and the write value requests should be defined: + ``` + var setCallbackSuccessCB() { + console.log("Callback set successfully!"); + }; + + var setCallbackErrorCB = function(error) { + console.error("Callback is not set correctly, error: " + error.name + "; " + error.message); + }; + + var sendResponseSuccessCB() { + console.log("Response sent successfully!"); + }; + + var sendResponseErrorCB = function(error) { + console.error("Response send failure, error: " + error.name + "; " + error.message); + }; + ``` + +5. To register the callback called when a client reads the value of the characteristic from the local GATT server, create the callback and pass it as an argument to `setReadValueRequestCallback()`: + ``` + var characteristicReadRequestCallback = function(clientAddress, offset) { + console.log(clientAddress + " requested to read characteristic's value with offset: " + offset); + return new tizen.GATTRequestReply(0, "0x1234"); + }; + server.services[0].characteristics[0].setReadValueRequestCallback(characteristicReadRequestCallback, setCallbackSuccessCB, setCallbackErrorCB, sendResponseSuccessCB, sendResponseErrorCB); + ``` + + > [!NOTE] + > A callback set with `setReadValueRequestCallback()` overwrites any previously set `ReadValueRequestCallback` on this characteristic. + +6. To register the callback called when a client writes a value of the characteristic of the local GATT server, create the callback and pass it as an argument to `setWriteValueRequestCallback()` method called on the characteristic object: + ``` + var characteristicWriteRequestCallback = function(clientAddress, value, offset, replyRequired) { + console.log(clientAddress + " requested to write characteristic's value: " + value + + " with offset: " + offset); + return replyRequired ? new tizen.GATTRequestReply(0) : null; + }; + + server.services[0].characteristics[0].setWriteValueRequestCallback(characteristicWriteRequestCallback, setCallbackSuccessCB, setCallbackErrorCB, sendResponseSuccessCB, sendResponseErrorCB); + ``` + + > [!NOTE] + > A callback set with `setWriteValueRequestCallback()` overwrites any previously set `WriteValueRequestCallback` on this characteristic. + +7. To register the callback called when a client reads the value of the descriptor from the local GATT server, create the callback and pass it as an argument to the `setReadValueRequestCallback()` method called on the descriptor object: + ``` + var descriptorReadRequestCallback = function(clientAddress, offset) { + console.log(clientAddress + " requested to read descriptor's value with offset: " + offset); + return new tizen.GATTRequestReply(0, "0x1234"); + }; + server.services[0].characteristics[0].descriptors[0].setReadValueRequestCallback(descriptorReadRequestCallback, setCallbackSuccessCB, setCallbackErrorCB, sendResponseSuccessCB, sendResponseErrorCB); + ``` + + > [!NOTE] + > A callback set with `setReadValueRequestCallback()` overwrites any previously set `ReadValueRequestCallback` on this descriptor. + +8. To register the callback called when a client writes a value of the descriptor of the local GATT server, create the callback and pass it as an argument to the `setWriteValueRequestCallback()` method called on the descriptor object: + ``` + var descriptorWriteRequestCallback = function(clientAddress, value, offset, replyRequired) { + console.log(clientAddress + " requested to write descriptor's value: " + value + + " with offset: " + offset); + return replyRequired ? new tizen.GATTRequestReply(0) : null; + }; + + server.services[0].characteristics[0].descriptors[0].setWriteValueRequestCallback(descriptorWriteRequestCallback, setCallbackSuccessCB, setCallbackErrorCB, sendResponseSuccessCB, sendResponseErrorCB); + ``` + + > [!NOTE] + > A callback set with `setWriteValueRequestCallback()` overwrites any previously set `WriteValueRequestCallback` on this descriptor. + + > [!NOTE] + > The callbacks described here can also be registered by putting them in `BluetoothGATTServerCharacteristicInit` or `BluetoothGATTServerDescriptorInit`. + ## Related information -* Dependencies +- Dependencies - Tizen 2.4 and Higher for Mobile - Tizen 2.3.1 and Higher for Wearable + - Tizen 6.0 and Higher for TV