1.0.5 • Published 6 years ago

noble_base v1.0.5

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

noble_base

Typescript compatible Noble base class for manipulating BLE peripheral devices

Install

npm install noble_base

Usage

Take a look at the src/examples. Basic pattern is as follows: 1. Extend NobleBase.Base class

```typescript
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
  }
}
```
  1. Implement is() and onConnectAndSetupDone() methods
  2. In your application code instantiate ScanHelper for your child class
    let scanHelper = new NobleBase.ScanHelper<ExamplePeripheral>(ExamplePeripheral);
  3. (optional) Apply scan filter
    scanHelper.setScanFilter((peripheral) => {
        //return true if peripheral should be connected
    });
  4. (optional) Attach device discovered callback
        //called each time new SimplePeripheral is connected
        const deviceDiscoveredCallback = (peripheral: ExamplePeripheral) => {
            //do something with peripheral
        }
        scanHelper.on('discoveredDevice', deviceDiscoveredCallback);
  5. Start scanning
    scanHelper.discoverAll();
  6. Done!
1.0.5

6 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago