Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

Index

Constructors

constructor

  • Create Characteristics

    await obniz.ble.initWait();
    var characteristic = new obniz.ble.characteristic({
         "uuid" : "FFF1",
         "properties" : ["read","write"],  // read, write, notify
         "data" : [0x0e, 0x00, ...],     //data for dataArray or  text for string
         "descriptors" : [{
             "uuid" : "2901",   //Characteristic User Description
             "text" : "hello world characteristic",    //data for dataArray or  text for string
         }]
    });
    
    var service = new obniz.ble.service({
                   "uuid" : "fff0",
                   "characteristics" : [ characteristic ]
    });
    obniz.ble.peripheral.addService(service);

    Parameters

    Returns BleCharacteristic

Properties

Optional onreadfromremote

onreadfromremote: undefined | ((address: BleDeviceAddress) => void)

This is a callback function used when characteristic is read by an external device.

characteristic.onreadfromremote = function(address){
  console.log("remote address :",address);
}

Optional onwritefromremote

onwritefromremote: undefined | ((address: BleDeviceAddress, data: number[]) => void)

This is a callback function used when characteristic is read by an external device.

characteristic.onwritefromremote = function(address, newvalue){
   console.log("remote address :",address);
   console.log("remote data :",newvalue);
}

service

service: BleService

Service instance

uuid

uuid: UUID

It is uuid as string.

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

Accessors

descriptors

  • Get descriptor array

    Returns BleDescriptor[]

Methods

addDescriptor

addProperty

  • Add property

    Parameters

    Returns void

getDescriptor

  • Get descriptor

    Parameters

    Returns BleDescriptor | null

notify

  • notify(): void
  • This sends notify to the connected central.

    var characteristic = new obniz.ble.characteristic({
      uuid: 'FFF1',
      data: [0x0e, 0x00],
      properties : ["read","write","notify"],  // add notify properties
    });
    
     var service = new obniz.ble.service({
      uuid: 'FFF0',
      characteristics: [characteristic],
    });
    obniz.ble.peripheral.addService(service);
    
    
    // after central connected
    characteristic.notify();

    Returns void

readWait

  • readWait(): Promise<number[]>
  • It reads data.

    Even you wrote string or number, it returns binary array. It throws an error when failed.

    // Javascript Example
    let data =  await attr.readWait()
     console.log("data: " , data );

    Returns Promise<number[]>

removeProperty

  • Remove property

    Parameters

    Returns void

writeWait

  • writeWait(data: any): Promise<boolean>
  • This writes dataArray. It throws an error when failed.

    // Javascript Example
    await attr.writeWait([0xf0,0x27]);
    console.log("write success");

    Parameters

    • data: any

    Returns Promise<boolean>

Generated using TypeDoc