Typescript compatible Noble base class for manipulating BLE peripheral devices
Typescript compatible Noble base class for manipulating BLE peripheral devices
npm install noble_base
Take a look at the src/examples
. Basic pattern is as follows:
Extend NobleBase.Base
class
class ExamplePeripheral extends NobleBase.Base {
public is(peripheral: Noble.Peripheral): boolean {
//return true if you want connect to this peripheral
}
protected async onConnectAndSetupDone() {
//do something when peripheral is connected
}
}
is()
and onConnectAndSetupDone()
methods
let scanHelper = new NobleBase.ScanHelper<ExamplePeripheral>(ExamplePeripheral);
scanHelper.setScanFilter((peripheral) => {
//return true if peripheral should be connected
});
//called each time new SimplePeripheral is connected
const deviceDiscoveredCallback = (peripheral: ExamplePeripheral) => {
//do something with peripheral
}
scanHelper.on('discoveredDevice', deviceDiscoveredCallback);
scanHelper.discoverAll();