Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

Index

Constructors

constructor

Properties

characteristic

characteristic: BleRemoteCharacteristic

Optional onread

onread: undefined | ((data: any) => void)

Callback function when read value.

Optional onwrite

onwrite: undefined | ((result: any) => void)

Callback function when write value finished.

uuid

uuid: UUID

It is uuid as string.

console.log(attr.uuid); // => '4C84'

Methods

readNumberWait

  • readNumberWait(): Promise<number | null>
  • Wrapper for writeWait with data converting from number. It writes data as 1byte.

    It throws an error when failed.

    Returns Promise<number | null>

    val

readTextWait

  • readTextWait(): Promise<string | null>
  • Wrapper for readWait with data converting to text. It convert UTF-8 and write binary array to string.

    It throws an error when failed.

    Returns Promise<string | null>

readWait

  • readWait(): Promise<number[]>
  • Read data from descriptor.

    The return value appears in the callback function onread. If reading succeeds an Array with data will be returned. It throws an error when failed.

    // Javascript Example
    await obniz.ble.initWait();
    var target = {
      uuids: ["fff0"],
    };
    var peripheral = await obniz.ble.scan.startOneWait(target);
    if(peripheral){
      await peripheral.connectWait();
      console.log("connected");
      await obniz.wait(1000);
    
      var dataArray = await peripheral.getService("FF00").getCharacteristic("FF01").readWait();
      console.log(dataArray);
    }

    Returns Promise<number[]>

writeNumberWait

  • writeNumberWait(val: number, needResponse?: undefined | false | true): Promise<boolean>
  • Wrapper for writeWait with data converting from number. It writes data as 1byte.

    It throws an error when failed.

    Parameters

    • val: number
    • Optional needResponse: undefined | false | true

    Returns Promise<boolean>

writeTextWait

  • writeTextWait(str: string, needResponse?: undefined | false | true): Promise<boolean>
  • Wrapper for writeWait with data converting from text. It convert string to UTF-8 and write binary array.

    It throws an error when failed.

    Parameters

    • str: string
    • Optional needResponse: undefined | false | true

    Returns Promise<boolean>

writeWait

  • writeWait(data: number[]): Promise<boolean>
  • This writes dataArray to descriptor. It throws an error when failed.

    // Javascript Example
    
    await obniz.ble.initWait();
    var target = {
      uuids: ["fff0"],
    };
    var peripheral = await obniz.ble.scan.startOneWait(target);
    if(peripheral){
      await peripheral.connectWait();
      console.log("connected");
      await obniz.wait(1000);
    
      var dataArray = [0x02, 0xFF];
      await peripheral.getService("FF00").getCharacteristic("FF01").getDescriptor("2901").writeWait(dataArray);
      console.log("write success");
    }

    Parameters

    • data: number[]

    Returns Promise<boolean>

Generated using TypeDoc