Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ObnizComponents

Hierarchy

Index

Constructors

constructor

Embeds Properties

Optional ble

ble: ObnizHciBLE

If obnizOS ver >= 3.0.0, automatically load ObnizHciBLE, and obnizOS ver < 3.0.0 throw unsupported Error,

Optional display

display: Display

Optional switch

switch: ObnizSwitch

Measurement Properties

Optional logicAnalyzer

logicAnalyzer: LogicAnalyzer

Optional measure

measure: ObnizMeasure

Other Properties

Optional connected_network

connected_network: ConnectedNetwork

Target obniz device's connected network information. This could be changed when obniz device connect another netowrk.

var obniz = new Obniz('1234-5678');
obniz.onconnect = async function() {
  console.log(obniz.connected_network.online_at) // online since in unix time.
}

connectionState

connectionState: "closed" | "connecting" | "connected" | "closing"

This let you know connection state to your obniz Board as string value.

  • 'closed' : not connected.
  • 'connecting' : connecting
  • 'connected' : connection established
  • 'closing' : closing connection.
var obniz = new Obniz('1234-5678');
console.log(obniz.connectionState) // => === "connecting"
obniz.onconnect = async function() {
 console.log(obniz.connectionState) // => === "connected"
}

debugprint

debugprint: boolean

This lets obniz.js to show logs like communicated jsons and connection logs in console.log.

var obniz = new Obniz('1234-5678');
obniz.onconnect = async function() {
 obniz.io0.output(true);
}

Optional firmware_ver

firmware_ver: undefined | string

This variable indicate installed firmware version of target device

var obniz = new Obniz('1234-5678');
obniz.onconnect = async function() {
  console.log(obniz.firmware_ver) // ex. "2.0.0"
}

Optional hw

hw: undefined | string

This variable indicate connected hardware identifier of target device

var obniz = new Obniz('1234-5678');
obniz.onconnect = async function() {
  console.log(obniz.hw) // ex. "obnizb1"
}

id

id: string

obniz id

isNode

isNode: boolean

Is node.js environment or not.

readonly

Optional metadata

metadata: undefined | {}

Device metadata set on obniz cloud.

var obniz = new Obniz('1234-5678');
obniz.onconnect = async function() {
  console.log(obniz.metadata.description) // value for "description"
}

Optional onclose

onclose: undefined | ((obniz: this) => void)

onclose will be called when disconnected.

var obniz = new Obniz('1234-5678');
obniz.onconnect = async function() {

}
obniz.onclose = async function() {

}

Optional onconnect

onconnect: undefined | ((obniz: this) => void)

Once connection is established, onconnect function will be called.

var obniz = new Obniz('1234-5678');
obniz.onconnect = async function() {

}

Operations like turning on/off an io becomes possible only after connection is established, so any operations you want obniz Board to undertake must be written in onconnect

var obniz = new Obniz('1234-5678');
obniz.onconnect = async function() {
  obniz.io0.output(true);
}

Optional onerror

onerror: undefined | ((obniz: this, error: Error) => void)

If an error occurs, the onerror function is called.

var obniz = new Obniz('1234-5678');
obniz.onconnect = async function() {

}
obniz.onerror = async function(ob, error) {
   console.error(error);
}

Optional onloop

onloop: undefined | ((obniz: this) => void | Promise<void>)

Called continuously while obniz device is online. Put your main code inside of onloop and put your setup code inside of onconnect.

onloop will be called after onconnect called. If your funciton set to onconnect return promise, onloop wait until done promise. Even onconnect throws an error onloop will start.

onloop call pingWait() every time to keep connection data buffer between device to your software clean.

var obniz = new Obniz('1234-5678');
obniz.onconnect = async function() {

}
obniz.onloop = async function() {

}

Static prefixed

prefixed: string | boolean

Peripherals Properties

Optional ad0

Optional ad1

Optional ad10

Optional ad11

Optional ad2

Optional ad3

Optional ad4

Optional ad5

Optional ad6

Optional ad7

Optional ad8

Optional ad9

Optional i2c0

Optional io

io: PeripheralDirective

Optional io0

Optional io1

Optional io10

Optional io11

Optional io2

Optional io3

Optional io4

Optional io5

Optional io6

Optional io7

Optional io8

Optional io9

Optional pwm0

Optional pwm1

Optional pwm2

Optional pwm3

Optional pwm4

Optional pwm5

Optional spi0

Optional spi1

Optional uart0

Optional uart1

network Properties

Optional wifi

wifi: WiFi

plugin Properties

Optional plugin

plugin: Plugin

Accessors

autoConnect

  • get autoConnect(): boolean
  • set autoConnect(val: boolean): void

Static version

  • get version(): any
  • obniz.js version

    Returns any

Methods

_stopPingLoopInBackground

  • _stopPingLoopInBackground(): void

addListener

close

  • close(): void
  • This closes the current connection. You need to set auto_connect to false. Otherwise the connection will be recovered.

    var obniz = new Obniz('1234-5678', {
      auto_connect: false,
      reset_obniz_on_ws_disconnection: false
    });
    
    obniz.connect();
    obniz.onconnect = async function() {
      obniz.io0.output(true);
      obniz.close();
    }
    deprecated

    replace with closeWait

    Returns void

closeWait

  • closeWait(): Promise<void>
  • This closes the current connection. You need to set auto_connect to false. Otherwise the connection will be recovered.

    var obniz = new Obniz('1234-5678', {
      auto_connect: false,
      reset_obniz_on_ws_disconnection: false
    });
    
    obniz.connect();
    obniz.onconnect = async function() {
      obniz.io0.output(true);
      await obniz.closeWait();
    }

    Returns Promise<void>

connect

  • connect(): void
  • You can connect to obniz Board manually by calling connect() when auto_connect is set to be false.

    var obniz = new Obniz('1234-5678', { auto_connect: false });
    
    obniz.connect();
    obniz.onconnect = async function() {
     obniz.io0.output(true);
    }

    Returns void

connectWait

  • connectWait(option?: undefined | { timeout?: undefined | number }): Promise<boolean>
  • With this you wait until the connection to obniz Board succeeds.

    var obniz = new Obniz('1234-5678');
    
    await obniz.connectWait();
    
    obniz.io0.output(true);
    await obniz.closeWait();
    
    • with timeout
    var obniz = new Obniz('1234-5678');
    
    await obniz.connectWait({timeout:10});  //timeout 10sec
    
    if(connected){
       obniz.io0.output(true);
       await obniz.closeWait();
    }
    • with auto_connect:false

    If the param auto_connect is set as false, it will try to connect only once and, if unsuccessful, return false.

    var obniz = new Obniz('1234-5678',{auto_connect: false});
    
    var connected = await obniz.connectWait();  //try once
    
    if(connected){
      obniz.io0.output(true);
      await obniz.closeWait();
    }

    Parameters

    • Optional option: undefined | { timeout?: undefined | number }

    Returns Promise<boolean>

    False will be returned when connection is not established within a set timeout.

emit

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

    Parameters

    Returns boolean

endCommandPool

  • endCommandPool(): null | any[]

endTrafficMeasurement

  • endTrafficMeasurement(): { ceilByte: number; readByte: number; readCount: number; sendByte: number; sendCount: number }
  • Returns { ceilByte: number; readByte: number; readCount: number; sendByte: number; sendCount: number }

    • ceilByte: number
    • readByte: number
    • readCount: number
    • sendByte: number
    • sendCount: number

eventNames

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

    Returns Array<ObnizConnectionEventNames | ObnizConnectionEventNamesInternal>

getAD

  • GET AD module from pin no

    Parameters

    • io: number

    Returns PeripheralAD

getExtraInterface

  • getExtraInterface(interfaceName: string): any
  • Parameters

    • interfaceName: string

    Returns any

getFreeI2C

  • It returns unused I2C module.

    Returns PeripheralI2C

getFreePwm

  • It returns unused PWM module.

    Returns PeripheralPWM

getFreeSpi

  • It returns unused SPI module.

    Returns PeripheralSPI

getFreeTcp

  • getFreeTcp(): any
  • It returns unused TCP module.

    Returns any

getFreeUart

  • It returns unused UART module.

    Returns PeripheralUART

getI2CWithConfig

  • It returns setuped I2C module .

    Parameters

    • config: any

    Returns PeripheralI2C

getIO

  • Get IO module from pin no

    Parameters

    • io: number

    Returns PeripheralIO

getSpiWithConfig

  • It returns setuped SPI module.

    Parameters

    • config: any

    Returns PeripheralSPI

getTrafficData

  • getTrafficData(): { ceilByte: number; readByte: number; readCount: number; sendByte: number; sendCount: number }
  • Returns { ceilByte: number; readByte: number; readCount: number; sendByte: number; sendCount: number }

    • ceilByte: number
    • readByte: number
    • readCount: number
    • sendByte: number
    • sendCount: number

hasExtraInterface

  • hasExtraInterface(interfaceName: string): boolean
  • Parameters

    • interfaceName: string

    Returns boolean

isValidAD

  • isValidAD(ad: any): boolean
  • Check the param is valid ad pin no.

    Parameters

    • ad: any

    Returns boolean

isValidIO

  • isValidIO(io: any): boolean
  • Check the param is valid io pin no.

    Parameters

    • io: any

    Returns boolean

listenerCount

listeners

off

  • off(event: ObnizConnectionEventNames | ObnizConnectionEventNamesInternal, fn?: EventEmitter.ListenerFn, context?: any, once?: undefined | false | true): this
  • Parameters

    • event: ObnizConnectionEventNames | ObnizConnectionEventNamesInternal
    • Optional fn: EventEmitter.ListenerFn
    • Optional context: any
    • Optional once: undefined | false | true

    Returns this

on

once

Abstract pingWait

  • pingWait(unixtime?: undefined | number, rand?: undefined | number, forceGlobalNetwork?: undefined | false | true): Promise<void>
  • Parameters

    • Optional unixtime: undefined | number
    • Optional rand: undefined | number
    • Optional forceGlobalNetwork: undefined | false | true

    Returns Promise<void>

removeAllListeners

removeListener

  • removeListener(event: ObnizConnectionEventNames | ObnizConnectionEventNamesInternal, fn?: EventEmitter.ListenerFn, context?: any, once?: undefined | false | true): this
  • Remove the listeners of a given event.

    Parameters

    • event: ObnizConnectionEventNames | ObnizConnectionEventNamesInternal
    • Optional fn: EventEmitter.ListenerFn
    • Optional context: any
    • Optional once: undefined | false | true

    Returns this

repeat

  • repeat(callback: any, interval?: undefined | number): void
  • Set onloop function. Use onloop property instead. This is deprecated function.

    deprecated

    Parameters

    • callback: any
    • Optional interval: undefined | number

      default 100. It mean 100ms interval loop.

    Returns void

resetTrafficMeasurement

  • resetTrafficMeasurement(): null | { ceilByte: number; readByte: number; readCount: number; sendByte: number; sendCount: number }
  • Returns null | { ceilByte: number; readByte: number; readCount: number; sendByte: number; sendCount: number }

send

  • send(obj: Record<string, any> | Record<string, any>[], options?: undefined | { connect_check?: undefined | false | true; local_connect?: undefined | false | true }): void
  • Send json/binary data to obniz Cloud or device.

    Parameters

    • obj: Record<string, any> | Record<string, any>[]

      send data

    • Optional options: undefined | { connect_check?: undefined | false | true; local_connect?: undefined | false | true }

      send option

    Returns void

setLoopInterval

  • setLoopInterval(interval: number): void
  • Sets the execution interval of onLoop function. Changes will be reflected after the next onloop is executed.

    Parameters

    • interval: number

      interval of execution in milliseconds.

    Returns void

setVccGnd

  • setVccGnd(vcc: number | null | undefined, gnd: number | null | undefined, drive: DriveType): void
  • Output pin Vcc and Gnd

    Parameters

    • vcc: number | null | undefined
    • gnd: number | null | undefined
    • drive: DriveType

    Returns void

startCommandPool

  • startCommandPool(): void

startTrafficMeasurement

  • startTrafficMeasurement(ceil?: number): void

wired

  • wired<K>(partsName: K, options?: PartsList[K]["options"]): Parts<K>
  • Setup Parts of parts library

    Type parameters

    Parameters

    • partsName: K
    • Optional options: PartsList[K]["options"]

    Returns Parts<K>

Static PartsRegistrate

  • PartsRegistrate(arg0: typeof ObnizPartsInterface, arg1?: any): void
  • Register Parts class

    Parameters

    • arg0: typeof ObnizPartsInterface

      Parts class

    • Optional arg1: any

      param for parts

    Returns void

Static getBleParts

Static getPartsClass

Static isIpAddress

  • isIpAddress(str: string): boolean

Generated using TypeDoc