Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • BleScan

Index

Constructors

constructor

  • Parameters

    Returns BleScan

Properties

Optional onfind

onfind: undefined | ((peripheral: BleRemotePeripheral) => void)

This function gets called when obniz Board finds a new peripheral.

// Javascript Example

obniz.ble.scan.onfind = function(peripheral){
 console.log(peripheral)
};

await obniz.ble.initWait();
await obniz.ble.scan.startWait();

Optional onfinish

onfinish: undefined | ((peripherals: BleRemotePeripheral[], error?: Error) => void)

This function gets called when obniz Board finishes scanning.

// Javascript Example

obniz.ble.scan.onfind = function(peripheral){
  console.log(peripheral)
};

obniz.ble.scan.onfinish = function(peripherals){
   console.log("scan timeout!")
};

await obniz.ble.initWait();
await obniz.ble.scan.startWait();

state

state: BleScanState = "stopping"

Methods

clearAdvertisementFilter

  • clearAdvertisementFilter(): void
  • Clear advertisement filter.

    Returns void

end

  • end(): void
  • Use endWait() instead

    deprecated

    Returns void

endWait

  • endWait(): Promise<void>
  • This stops scanning BLE.

    // Javascript Example
    await obniz.ble.initWait();
    await obniz.ble.scan.startWait();
    await obniz.wait(5000);
    await obniz.ble.scan.endWait();

    Returns Promise<void>

start

  • Use startWait() instead.

    deprecated

    Parameters

    Returns void

startAllWait

  • This scans and returns all the peripherals found.

    This function does not return until scanning gets timed out.(default 30sec) If you want to change the default duration, you can do so with the duration param.

    // Javascript Example
    
    await obniz.ble.initWait();
    var target = {
     uuids: ["fff0"],
    };
    var setting = {
      duration : 10
    }
    
    var peripherals = await obniz.ble.scan.startAllWait(target,setting);
    
    for(var peripheral of peripherals){
      console.log(peripheral);
    }

    Parameters

    Returns Promise<BleRemotePeripheral[]>

startOneWait

  • This scans and returns the first peripheral that was found among the objects specified in the target.

    // Javascript Example
    
    await obniz.ble.initWait();
    var target = {
      uuids: ["fff0"],
    };
    
    var peripheral = await obniz.ble.scan.startOneWait(target);
    console.log(peripheral);

    Parameters

    Returns Promise<BleRemotePeripheral | null>

startWait

  • This starts scanning BLE.

    You can filter uuids or localName using the target param.

    // Javascript Example
    var target = {
        uuids: ["fff0","FFF1"],     //scan only has uuids "fff0" and "FFF1"
        localName: "obniz-BLE",     //scan only has localName "obniz-BLE"
    };
    
    var setting = {
       duration : 10  //scan duration time in seconds. default is 30 sec.
    }
    
    await obniz.ble.initWait();
    await obniz.ble.scan.startWait(target, setting);

    This is also possible without params being valid.

    // Javascript Example
    await obniz.ble.scan.startWait();

    Scanning starts with no error and results with not advertisement found while a device is trying to connect a peripheral. Before start scannnig. Establishing connection must be completed or canceled.

    Parameters

    Returns Promise<void>

Generated using TypeDoc