Hi All,
We bluetooth team have almost finished the implementation of General
Attribute Profile (GATT) client API to add an initial bluetooth low energy
(BLE) support on Firefox OS for privileged apps, which is previously
discussed in the mail list [1], and some known action items will be
addressed before v3 (security review for example). Our next step is to
support GATT server API and we would like to obtain your valuable feedback
on our GATT server API draft.
With GATT server API, applications will be able to provide services for
exposing some information in the local device to remote BLE devices (GATT
clients).
For example,
1.
Alert Notification Service [2]: Expose alert information in a device,
including different types of alerts(ex: email) with the short text
messages, the count of new alert messages, and the count of unread alerts.
A remote GATT client can also subscribe notifications on the alert
information.
2.
Battery Service [3]: Expose the state of battery within a device.
3.
Time-Related Services: Current time service [4] for example.
4.
Customized services defined by applications.
The GATT server API is based on our prior refinement and GATT client API,
and including following additional attributes, methods, dictionaries, and
interfaces.
-
Attribute
-
BluetoothAdapter.gattServer
<
https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#BluetoothAdapter>
-
Method
-
BluetoothGattService.addCharacteristic
<
https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#BluetoothGattService>
-
BluetoothGattService.addIncludedService
<
https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#BluetoothGattService>
-
BluetoothGattCharacteristic.addDescriptor
<
https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#BluetoothGattCharacteristic>
-
Dictionary
-
Permissions
<
https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#Permissions>
-
Interface
-
BluetoothGattServer
<
https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#BluetoothGattServer>
Please find the full documentation at
https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2.
Sample code of setting up the GATT server which exposes a service with a
characteristic value for connected GATT clients to read:
if (adapter.gattServer) {
// Setting up a GATT server with a service and a characteristic
var service = new BluetoothGattService(serviceUuid, true);
service.addCharacteristic(
charUuid, {read: true}, {read:true},
*charValue*).then(function(characteristic)
{
gattServer.addService(service);
});
adapter.gattServer.onattributereadreq = function onAttributeReadReq(evt) {
sendResponse(evt.address, 0, evt.requestId, evt.characteristic.value);
};
// Connect to a GATT client which was discovered by classic discovery or
LE scan
// and start to listen to client’s requests
adapter.gattServer.connect(devAddr).then(function() {
console.log(“A GATT client has been connected”);
});
}
[1]
https://groups.google.com/d/topic/mozilla.dev.webapi/Z-ZXdtigktI/discussion
[2]
https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.alert_notification.xml
[3]
https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.battery_service.xml
[4]
https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.current_time.xml