BluetoothGatt (Firefox OS)

This API is available on Firefox OS for internal applications only.

The BluetoothGatt interface of the Web Bluetooth API handles initial communications and connections with Gatt services.

Interface overview

JavaScript
[CheckPermissions="bluetooth"]
interface BluetoothGatt : EventTarget
{
  [Cached, Pure]
  readonly attribute sequence<<a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#BluetoothGattService" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService">BluetoothGattService</a>> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#services" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt">services</a>;
  readonly attribute <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#BluetoothConnectionState" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt">BluetoothConnectionState</a> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#connectionState" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt">connectionState</a>;

           attribute EventHandler <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#oncharacteristicchanged" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt">oncharacteristicchanged</a>;
           attribute EventHandler <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#onconnectionstatechanged" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt">onconnectionstatechanged</a>;

  [NewObject] Promise<void> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#connect.28.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt">connect()</a>;
  [NewObject] Promise<void> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#disconnect.28.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt">disconnect()</a>;
  [NewObject] Promise<void> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#discoverServices.28.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt">discoverServices()</a>;
  [NewObject] Promise<short> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#readRemoteRssi.28.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt">readRemoteRssi()</a>;
  // Reliable write
  [NewObject] Promise<void> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#beginReliableWrite.28.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt">beginReliableWrite()</a>;
  [NewObject] Promise<void> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#executeReliableWrite.28.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt">executeReliableWrite()</a>;
  [NewObject] Promise<void> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#abortReliableWrite.28.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt">abortReliableWrite()</a>;
};

Properties

BluetoothGatt.services Read only
Returns the list of GATT services offered by the remote LE device. This property is set to an empty array by default before a connection is established.
BluetoothGatt.connectionState
The current connection state of GATT client to the remote LE device. This property is set to disconnected by default, before a connection is established.

Event handlers

BluetoothGatt.oncharacteristicchanged
Defines a handler to trigger as a result of the characteristicchanged event firing; this occurs when a remote characteristic changes.
BluetoothGatt.onconnectionstatechanged
Defines a handler to trigger as a result of the connectionstatechanged event firing; this occurs when the connection state of the GATT client to the remote LE device (i.e. the BluetoothGatt.connectionState property) changes.

Methods

BluetoothGatt.connect()
Connects to the remote LE device.
BluetoothGatt.disconnect()
Disconnects an already-established connection to a remote LE device.
BluetoothGatt.discoverServices()
Discovers services, characteristics, and descriptors offered by the remote GATT server.
BluetoothGatt.readRemoteRssi()
Reads the RSSI for a connected remote LE device.
BluetoothGatt.beginReliableWrite()
Initiates a reliable write transaction for the remote LE device.
BluetoothGatt.executeReliableWrite()
Executes all queued up characteristic value write operations for the remote LE device.
BluetoothGatt.abortReilableWrite()
Cancels all queued characteristic value write operations for the remote LE device.

Specifications

Specification Status Comment
Web Bluetooth
The definition of 'BluetoothGatt' in that specification.
Draft Rough draft; not part of any official specification yet. It should be discussed as part of the W3C's System Applications Working Group.

Browser Compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support No support No support No support No support No support
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support No support No support No support 2.1 No support No support No support No support

 

See also

Using the Web Bluetooth API

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/bluetoothgatt_(firefox_os)

API B2G Bluetooth BluetoothGatt Certified Firefox OS Interface Non-standard Reference Web Bluetooth