Use a obniz device as a BLE device. Peripheral and Central mode are supported

Hierarchy

Constructors

Properties

Obniz: Obniz

obniz to be used

characteristic: typeof BleCharacteristic
descriptor: typeof BleDescriptor
extendedAdvertisement?: BleExtendedAdvertisement
hciProtocol: Hci
onUpdatePhy?: ((txPhy, rxPhy, handler?) => void)

Type declaration

    • (txPhy, rxPhy, handler?): void
    • This is a callback function used when an external device gets connected or disconnected.

      await obniz.ble.initWait();
      obniz.ble.onUpdatePhy = ((txPhy, rxPhy) => {
      console.log("txPhy "+txPhy+" rxPhy "+rxPhy);
      });

      Parameters

      • txPhy: "1m" | "2m" | "coded"
      • rxPhy: "1m" | "2m" | "coded"
      • Optional handler: number

      Returns void

peripheral: BlePeripheral
scan: BleScan
service: typeof BleService
timeout: number = ...

Rsponse waiting timeout in milliseconds

prefixed: string | boolean

Accessors

  • get isInitialized(): boolean
  • Initialized status.

    // Javascript Example
    obniz.ble.isInitialized; // => false
    await obniz.ble.initWait();
    obniz.ble.isInitialized; // => true

    Returns boolean

Methods

  • Connect to peripheral without scanning. Returns a peripheral instance, but the advertisement information such as localName is null because it has not been scanned.

    // Javascript Example

    await obniz.ble.initWait();
    var peripheral = obniz.ble.directConnect("e4b9efb29218","random");
    peripheral.onconnect = ()=>{
    console.log("connected");
    }

    Parameters

    Returns null | BleRemotePeripheral

    Deprecated

    replaced by #directConnectWait()

  • Connect to peripheral without scanning, and wait to finish connecting.

    It throws when connection establish failed. Returns a peripheral instance, but the advertisement information such as localName is null because it has not been scanned.

    // Javascript Example
    await obniz.ble.initWait();
    try {
    var peripheral = await obniz.ble.directConnectWait("e4b9efb29218","random");
    console.log("connected");
    } catch(e) {
    console.log("can't connect");
    }

    Parameters

    Returns Promise<BleRemotePeripheral>

  • Calls each of the listeners registered for a given event.

    Parameters

    • event: string
    • Rest ...args: any[]

    Returns boolean

  • Return an array listing the events for which the emitter has registered listeners.

    Returns string[]

  • Return connected peripherals.

    // Javascript Example
    await obniz.ble.initWait();
    let target = {
    localName: "Blank"
    };
    var peripheral = await obniz.ble.scan.startOneWait(target);
    if(peripheral) {
    try {
    await peripheral.connectWait();
    } catch(e) {
    console.error(e);
    }
    }
    console.log(obniz.ble.getConnectedPeripherals());

    Returns BleRemotePeripheral[]

    connected peripherals

  • Initialize BLE module. You need call this first everything before. This throws if device is not supported device.

    esp32 C3 or esp32 S3 Put true in the argument when not using the BLE5.0 extended advertise

    // Javascript Example
    await obniz.ble.initWait();

    Parameters

    Returns Promise<void>

  • Return the number of listeners listening to a given event.

    Parameters

    • event: string

    Returns number

  • Return the listeners registered for a given event.

    Parameters

    • event: string

    Returns ListenerFn[]

  • Parameters

    • event: string
    • Optional fn: ListenerFn
    • Optional context: any
    • Optional once: boolean

    Returns ObnizBLE

  • Add a listener for a given event.

    Parameters

    • event: string
    • fn: ListenerFn
    • Optional context: any

    Returns ObnizBLE

  • Add a one-time listener for a given event.

    Parameters

    • event: string
    • fn: ListenerFn
    • Optional context: any

    Returns ObnizBLE

  • Remove the listeners of a given event.

    Parameters

    • event: string
    • Optional fn: ListenerFn
    • Optional context: any
    • Optional once: boolean

    Returns ObnizBLE

  • Reset Target Device and current SDK status without rebooting. If error occured while reset, then target device will reboot.

    // Javascript Example
    await obniz.ble.resetWait();

    Returns Promise<void>

  • ESP32 C3 or ESP32 S3 only

    Sets the PHY to use by default

    // Javascript Example
    await obniz.ble.setDefaultPhyWait(false,false,true);//coded only

    Parameters

    • usePhy1m: boolean
    • usePhy2m: boolean
    • usePhyCoded: boolean

    Returns Promise<void>

Generated using TypeDoc