Skip to content
This repository has been archived by the owner on Apr 29, 2023. It is now read-only.
/ noble_base Public archive

Typescript compatible Noble base class for manipulating BLE peripheral devices

License

Notifications You must be signed in to change notification settings

keton/noble_base

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Typescript compatible Noble base class for manipulating BLE peripheral devices

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published