This feature is not on a current W3C standards track, but it is supported on the Firefox OS platform. Although implementations may change in the future and it is not supported widely across browsers, it is suitable for use in code dedicated to Firefox OS apps.
The Web Bluetooth API lets an open web app discover, pair with, and connect to Bluetooth devices. As it is a completely experimental and non-standard API, the Bluetooth API is currently available for certified applications only. However, there is some traction to have such an API available for regular Web content; this will be discussed as part of the W3C's System Applications Working Group.
Note: App developers who wish to send data to a Bluetooth device can use the share activity. This activity allows sharing of images, audio, video and vCard content only.
The following interfaces provide an app with basic Bluetooth functionality
- Allows access to all Bluetooth adapters available on the device. Adapters are the connection interface to connect another Bluetooth-enabled device to the current device.
- Used to handle all the operations requested by Bluetooth networks.
- Provides identifying/classification information about a given remote Bluetooth device, available at discovery stage.
- Provides information regarding a given remote Bluetooth device.
- Used to notify the current application about the discovery of a remote bluetooth device.
- Contains the functionality required for completing a device pairing operation, including passkeys, and mechanisms to reply to user-entered pin codes and confirm passkeys.
- Defines event handlers triggered for different pairing operations.
The following interfaces allow Firefox OS to communicate with and consume Gatt (Generic Attribute Profile)-based services on remote Smart/LE (low energy) devices.
- Handles initial communications and connections with Gatt services.
- Provides Bluetooth GATT server functionality to allow creation of Bluetooth Smart/LE services and characteristics.
- Represents a service provided by a GATT server, including the service definition, a list of included services, and a list of the characteristics of this service.
- Represents a GATT service characteristic, which includes characteristic definition, value, properties and configuration info, and a list of descriptors that provide related information.
- Represents a GATT descriptor, which contains related information about a characteristic value.
These objects represent different events occuring within a Bluetooth interaction.
- Provides access to a
BluetoothAdapterobject and its address as the parameter of a
adapterremovedevent handler (see
BluetoothManager.onadapterremoved), when fired.
- Provides access to changed attributes and their new values as the parameter of
attributechangedevent handlers (including
BluetoothDevice.onattributechanged), when fired.
- Provides access to a found/paired device (
BluetoothDevice) object or the address or an unpaired device as the parameter of a
deviceunpairedevent handler (see
BluetoothAdapter.ondeviceunpaired), when fired.
- Provides access to an updated
BluetoothGattCharacteristicobject as the parameter of the
BluetoothGatt.oncharacteristicchanged, handler, when the
characteristicchangedevent is fired.
- Provides access to an LE device
BluetoothDeviceobject and its RSSI value and advertisement record, as the parameter of a
devicefoundevent handler (see
BluetoothDiscoveryHandle.ondevicefound), when fired.
- Provides access to a device's name and the
BluetoothPairingHandleobject required for pairing devices as the parameter of pairing-related handlers (for example including
BluetoothPairingListener.onenterpincodereq), when fired.
Because some actions from remote devices can require waking up an app to handle them, there are several system messages related to Bluetooth:
- Provides access to information regarding any change to the status of a Bluetooth device.
|Web Bluetooth||Draft||Rough draft; not part of any official specification yet. It should be discussed as part of the W3C's System Applications Working Group.|
- The Web Bluetooth API is implemented in Firefox OS 1.0.1 and above.
- However, on Firefox OS <1.2, you need to be careful with Bluetooth file sharing. If you are sharing a file directly from the SDCard you are ok, but if you are sharing say, an image blob directly from the camera via a Web Activity you will run into problems, as Bluetooth is expecting a valid path to the SDCard as a file location (see B2G 1.0.1 Gaia Bluetooth app.) This is fixed in Firefox OS 1.2. In Firefox <1.2 you'd have to write it to an SDCard via Device Storage first, then transfer it via Bluetooth.
- There is an added complication too: Device Storage is only available to privileged (packaged) apps, so if your app is hosted then you can't use Device Storage to solve the above problem.
- Another problem you may run into when attempting to use Bluetooth File sharing between Firefox OS and another device is that the other devce may not have Bluetooth Sharing enabled (Firefox OS has it enabled by default.) For eample on Mac OSX 10.9 it is turned on via System Preferences > Sharing > check "Bluetooth Sharing".