LogoPear Docs
ReferencesBareModules

bare-bluetooth-android

Reference overview for bare-bluetooth-android: Android Bluetooth Low Energy bindings for Bare, in the central (scanner/client) role.

bare-bluetooth-android provides Android Bluetooth Low Energy (BLE) bindings for Bare. 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.

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