LogoPear Docs
ReferencesBareModules

bare-bluetooth-android

Reference overview for bare-bluetooth-android: Android Bluetooth Low Energy bindings for Bare, covering both the central (scanner/client) and peripheral (GATT server) roles.

bare-bluetooth-android provides Android Bluetooth Low Energy (BLE) bindings for Bare, covering both the central (scanner/client) role and the peripheral (GATT server) role. It's a native addon and runs on Android only—on Apple platforms use bare-bluetooth-apple. This page is an overview; the surface is large, so see the repository README for the full API.

npm i bare-bluetooth-android

Usage

const { Central } = require('bare-bluetooth-android')

const central = new Central()

central.on('stateChange', (state) => {
  if (state === 'on') central.startScan(['180D']) // Heart Rate service
})

central.on('discover', (peripheral) => {
  console.log('Found:', peripheral.name, peripheral.id)
  central.stopScan()
})

API overview

  • Central — the BLE central (scanner/client) role. Drive scanning with central.startScan([serviceUUIDs]) and central.stopScan(), and observe adapter state and discoveries via the stateChange and discover events. Discovered peripherals can be connected to, with their services and characteristics read, written, and subscribed for notifications.

  • Server — the BLE peripheral (GATT server) role. Supports advertising, service registration, characteristic read/write request handling, value updates with subscriber notifications, and L2CAP connection-oriented channel publishing. See the repository README for the full Server API.

The module builds on bare-events and bare-stream. For the complete peripheral/service/characteristic API, refer to the repository.

See also

On this page