bare-bluetooth-apple
v0.4.1
Published
CoreBluetooth bindings for Bare
Readme
bare-bluetooth-apple
CoreBluetooth bindings for Bare. Provides BLE central and peripheral roles, GATT services and characteristics, and L2CAP channels on Apple platforms.
npm i bare-bluetooth-appleUsage
const bluetooth = require('bare-bluetooth-apple')
const manager = new bluetooth.PeripheralManager()
manager.on('stateChange', (state) => {
if (state !== 'poweredOn') return
const char = new bluetooth.Characteristic('01230001-0000-1000-8000-00805F9B34FB', {
write: true,
notify: true
})
const service = new bluetooth.Service('01230000-0000-1000-8000-00805F9B34FB', [char])
manager.addService(service)
})
manager.on('serviceAdd', (uuid, error) => {
if (error) return
manager.startAdvertising({
name: 'MyDevice',
serviceUUIDs: ['01230000-0000-1000-8000-00805F9B34FB']
})
})
manager.on('error', (err) => {
console.error('manager error:', err.code, err.message)
})
manager.on('writeRequest', (requests) => {
// Handle incoming write requests
manager.respondToRequest(requests[0], bluetooth.PeripheralManager.ATT_SUCCESS, null)
})API
See the bare-bluetooth-apple reference.
License
Apache-2.0
