Skip to content
AnswerWell geo Documentation

Research · 6 min read · Answerwell

Bluetooth Low Energy GATT API: Connections, Notifications and Sockets

How Chrome Apps connect over BLE GATT, enable characteristic notifications, run peripheral mode, and manage Bluetooth socket lifecycle.

This page summarizes Chrome Apps documentation for talking to hardware over Bluetooth Low Energy (BLE) with chrome.bluetoothLowEnergy and over Bluetooth Classic-style sockets with chrome.bluetoothSocket. The BLE path is GATT-based (services, characteristics, descriptors); the socket path is for streamed byte I/O over RFCOMM or L2CAP. Both APIs assume a packaged app with the right manifest permissions—not a normal website.

chrome.bluetoothLowEnergy: central role and GATT access

Section titled “chrome.bluetoothLowEnergy: central role and GATT access”

chrome.bluetoothLowEnergy is how an app acts as a GATT central: connect to a device by address, discover services, then read, write, and subscribe to characteristics. The connect method establishes (or reaffirms) a link and triggers service discovery when the device was not already connected:

Establishes a connection between the application and the device with the given address. A device may be already connected and its GATT services available without calling connect, however, an app that wants to access GATT services of a device should call this function to make sure that a connection to the device is maintained. If the device is not connected, all GATT services of the device will be discovered after a successful call to connect.

— Chrome, chrome.bluetoothLowEnergy

disconnect closes your app’s connection only; other apps may still hold the radio link:

Closes the app’s connection to the device with the given address. Note that this will not always destroy the physical link itself, since there may be other apps with open connections.

— Chrome, chrome.bluetoothLowEnergy

After connect, you typically call getServices / getCharacteristics, then readCharacteristicValue, writeCharacteristicValue, or notification APIs below. getDevice on chrome.bluetooth returns system-known device metadata by address when you need identity before BLE steps.

GATT service discovery: empty or partial service lists

Section titled “GATT service discovery: empty or partial service lists”

If you call getServices before discovery finishes, you may see an incomplete list. The reference documents a practical workaround:

Note: If service discovery is not yet complete on the device, this API will return a subset (possibly empty) of services. A work around is to add a time based delay and/or call repeatedly until the expected number of services is returned.

— Chrome, chrome.bluetoothLowEnergy

Poll after connect succeeds, or gate UI on the expected service count, instead of assuming the first call is complete.

Characteristic notifications: subscribe with startCharacteristicNotifications

Section titled “Characteristic notifications: subscribe with startCharacteristicNotifications”

Many sensors (for example heart rate) push values with notifications or indications rather than constant reads. The Bluetooth app guide describes the event-driven pattern:

Some characteristics make their value known using notifications or indications. For example the Heart Rate Measurement characteristic is neither readable nor writable but sends updates on its current value at regular intervals. Applications can listen to these notifications using the bluetoothLowEnergy.onCharacteristicValueChanged event.

— Chrome, Bluetooth

Notifications are off by default. Enable them with startCharacteristicNotifications and stop with stopCharacteristicNotifications:

Enable value notifications/indications from the specified characteristic. Once enabled, an application can listen to notifications using the onCharacteristicValueChanged event.

— Chrome, chrome.bluetoothLowEnergy

Disable value notifications/indications from the specified characteristic. After a successful call, the application will stop receiving notifications/indications from this characteristic.

— Chrome, chrome.bluetoothLowEnergy

Handle payloads in one listener; filter by characteristicId / instanceId when several characteristics notify.

onCharacteristicValueChanged: reads and notifications in one handler

Section titled “onCharacteristicValueChanged: reads and notifications in one handler”

The same event fires for notifications and, when reads are supported, after a successful readCharacteristicValue:

Once notifications are started, the application will receive the bluetoothLowEnergy.onCharacteristicValueChanged every time a notification or indication is received from the characteristic. If the characteristic supports reads, then this event will also be sent after a successful call to bluetoothLowEnergy.readCharacteristicValue. This allows apps to unify the control flow of a value update triggered through a read request and notifications:

— Chrome, Bluetooth

A common pattern: call startCharacteristicNotifications, then readCharacteristicValue for the initial value and rely on onCharacteristicValueChanged for both the first read and later pushes.

notify and indicate: properties and CCC descriptor

Section titled “notify and indicate: properties and CCC descriptor”

A characteristic that supports subscriptions exposes notify or indicate in its properties field. BLE devices use the Client Characteristic Configuration (CCC) descriptor to toggle notifications; Chrome blocks direct descriptor writes for that:

NOTE: If a characteristic supports notifications/indications, it will have the “Client Characteristic Configuration” descriptor to enable/disable notifications. Chrome does not permit apps to write to this descriptor. Apps should instead use the bluetoothLowEnergy.startCharacteristicNotifications and bluetoothLowEnergy.stopCharacteristicNotifications methods to control notification behavior.

— Chrome, Bluetooth

Use the platform methods—do not call writeDescriptorValue on CCC.

GATT peripheral mode: local server, advertising, and permissions

Section titled “GATT peripheral mode: local server, advertising, and permissions”

With bluetooth:low_energy and bluetooth:peripheral (peripheral not available to every app), the app can host a local GATT server: createService, createCharacteristic, createDescriptor, then registerService. Answer remote centrals with sendRequestResponse on onCharacteristicReadRequest, onCharacteristicWriteRequest, and descriptor read/write events. Push updates with notifyCharacteristicValueChanged; set shouldIndicate in the notification object to send an indication instead of a notification.

registerAdvertisement is tightly constrained: kiosk auto-launch or the --enable-ble-advertising-in-apps switch; see the Bluetooth manifest notes. On hardware that cannot run central and peripheral together, using both roles can break discovery for other apps.

setAdvertisingInterval is best-effort (hardware may enforce a ~100 ms minimum). unregisterAdvertisement may require a device restart if unregister fails.

chrome.bluetoothSocket: when to use sockets instead of GATT

Section titled “chrome.bluetoothSocket: when to use sockets instead of GATT”

Use chrome.bluetoothSocket when the peer exposes a Bluetooth socket profile (RFCOMM or L2CAP), not GATT attributes. Typical flow: create → connect (client) or listenUsingRfcomm / listenUsingL2cap (server) → send and receive events. setPaused can throttle inbound data or defer onAccept for listening sockets until unpaused.

The Bluetooth guide uses bluetoothSocket.disconnect to drop an active client link or stop accepting on a server socket:

To hang up the connection and disconnect the socket use bluetoothSocket.disconnect.

— Chrome, Bluetooth

disconnect versus close on bluetoothSocket

Section titled “disconnect versus close on bluetoothSocket”
Method Socket ID after call Effect
disconnect Remains valid Drops connection; ID can be reused
close Invalid immediately Disconnects and destroys socket; fully closed in callback

Disconnects the socket. The socket identifier remains valid.

— Chrome, chrome.bluetoothSocket

Disconnects and destroys the socket. Each socket created should be closed after use. The socket id is no longer valid as soon at the function is called. However, the socket is guaranteed to be closed only when the callback is invoked.

— Chrome, chrome.bluetoothSocket

Prefer close when you are done with the socket; use disconnect for a temporary hang-up on the same ID.

Section titled “Related Chrome Apps device APIs (same platform, different transports)”

The same Chrome Apps device stack exposes other local I/O when Bluetooth is not the right fit: chrome.serial for COM/tty ports, chrome.usb (claim interface, then bulk/control/interrupt transfers), chrome.hid for HID reports, and chrome.sockets.tcp / chrome.sockets.udp for IP. Those paths are documented separately; this page stays on BLE GATT and Bluetooth sockets.

  • Writing the CCC descriptor instead of startCharacteristicNotifications / stopCharacteristicNotifications.
  • Assuming getServices right after connect returns the full GATT tree.
  • Calling bluetoothLowEnergy.disconnect expecting the radio to drop for all apps.
  • Using bluetoothSocket.disconnect when you mean to destroy the socket (close).
  • Running central + peripheral + advertising without checking hardware and manifest constraints.
  • Ignoring chrome.runtime.lastError after startCharacteristicNotifications (failures leave notifications disabled).
  1. Confirm the app manifest declares the Bluetooth permissions your flow needs (bluetooth, bluetooth:low_energy, and bluetooth:peripheral for local GATT server or advertising), using Bluetooth manifest and the API pages linked above.

  2. In a development build, exercise connect → getServices → startCharacteristicNotifications and verify onCharacteristicValueChanged fires when the peripheral pushes data, matching Bluetooth.

  3. For socket-based peers, open a test connection with bluetoothSocket.create and connect (or listen), send a small payload with send, and confirm teardown with getInfo before close.

  4. For peripheral mode, register a minimal service, respond promptly to read/write request events (delayed responses can disconnect the central, per chrome.bluetoothLowEnergy), and test notifyCharacteristicValueChanged toward a separate central device.

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page does not match the official behavior you see, or you need a clarification on a specific API, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.