Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ObnizUIs

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

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.debugprint = true
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.debugprint = true
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.debugprint = true
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 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);
}

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

Accessors

Static version

  • get version(): any

Methods

addListener

  • Parameters

    Returns this

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();
    }

    Returns 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);
    obniz.close();
    
    • with timeout
    var obniz = new Obniz('1234-5678');
    
    await obniz.connectWait({timeout:10});  //timeout 10sec
    
    if(connected){
       obniz.io0.output(true);
       obniz.close();
    }
    • 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);
      obniz.close();
    }

    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

eventNames

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

    Returns Array<ObnizConnectionEventNames>

getAD

getExtraInterface

  • getExtraInterface(interfaceName: string): any

getFreeI2C

getFreePwm

getFreeSpi

getFreeTcp

  • getFreeTcp(): any

getFreeUart

getI2CWithConfig

getIO

getSpiWithConfig

hasExtraInterface

  • hasExtraInterface(interfaceName: string): 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

keepWorkingAtOffline

  • keepWorkingAtOffline(working: any): void
  • By default, obniz Board resets after disconnection from the cloud. It means the output value and pwm will all stop at that point. But the above function with the argument true can nullify that default setting and change it to "do not reset when offline". This configuration remains as long as obniz Board is on.

    // Example
    obniz.keepWorkingAtOffline(true);

    Parameters

    • working: any

    Returns void

listenerCount

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

    Parameters

    Returns number

listeners

  • Return the listeners registered for a given event.

    Parameters

    Returns Array<ListenerFn>

off

  • Parameters

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

    Returns this

on

  • Add a listener for a given event.

    Parameters

    Returns this

once

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

    Parameters

    Returns this

pingWait

  • pingWait(unixtime?: undefined | number, rand?: undefined | number, forceGlobalNetwork?: undefined | false | true): Promise<void>
  • Ping to obniz device and wait pong response.

    If debugprint option enabled, it display ping/pong response time on console.

    await obniz.pingWait(); //waiting pong.

    Parameters

    • Optional unixtime: undefined | number

      start time of measure response time

    • Optional rand: undefined | number

      Unique identifier of ping data

    • Optional forceGlobalNetwork: undefined | false | true

    Returns Promise<void>

reboot

  • reboot(): void
  • reboot device

    obniz.reboot();

    Returns void

removeAllListeners

  • Remove all listeners, or those of the specified event.

    Parameters

    Returns this

removeListener

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

    Parameters

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

    Returns this

reset

  • reset(): void
  • This forces the obniz Board to go back to the initial state when the power was just turned on.

    // Example
    obniz = new Obniz("1234-5678");
    obniz.onconnect = function() {
      obniz.reset();
    }

    Returns void

resetOnDisconnect

  • resetOnDisconnect(reset: any): void
  • This lets you change the setting of reset_obniz_on_ws_disconnection after connection is established.

    By default, obniz cloud resets target obniz Board when the all websocket to obniz cloud was closed. It means the output value and pwm will all stop at that point. With the above function, you can nullify these resetting activities. This configuration will remain until target obniz Board gets disconnected. Set this function to false to keep working without any of the websocket connections.

    // Example
    obniz.resetOnDisconnect(false);

    Parameters

    • reset: any

    Returns void

send

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

    Parameters

    • obj: object | object[]

      send data

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

      send option

    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

sleep

  • sleep(date: Date): void
  • Action only with obniz Board 1Y.

    Obniz Board sleeps for the value specified in Date type. Sleep for up to 45 days (64800 minutes).

    // JavaScript example
    let dt = new Date();
    dt.setHours(dt.getHours () + 1,0,0,0);
    obniz.sleep(dt);

    Parameters

    • date: Date

    Returns void

sleepIoTrigger

  • sleepIoTrigger(trigger: any): void
  • Action only with obniz Board 1Y.

    It returns from sleep depending on the pin state of IO0.

    // JavaScript example
    obniz.sleepIoTrigger (true);

    Parameters

    • trigger: any
      • true: Rise (LOW -> HIGH)
      • false: Falling (HIGH -> LOW)

    Returns void

sleepMinute

  • sleepMinute(minute: any): void
  • Action only with obniz Board 1Y.

    Obniz Board sleeps for the value specified in minutes.

    // JavaScript example
    obniz.sleepMinute (60); // 60 minutes

    Parameters

    • minute: any

      up to 64800 minutes(45 days ).

    Returns void

sleepSeconds

  • sleepSeconds(sec: any): void
  • Action only with obniz Board 1Y.

    Obniz Board sleeps for the value specified in seconds.

    // JavaScript example
    obniz.sleepSeconds (60); // 60 seconds

    Parameters

    • sec: any

      up to 64800 seconds (18 hours).

    Returns void

wait

  • wait(msec: any): Promise<void>
  • This pauses obniz Board for a period given in terms of ms (millisecond).

    // Javascript Example
    led.on();
    obniz.wait(1000); // led ON 1sec.
    led.off();

    This method pauses only obniz Board, not JavaScript.

    // Javascript Example
    var time = new Date();
    led.on();
    obniz.wait(1000); // led ON 1sec.
    led.off();
    console.log((new Date()).getTime() - time.getTime()) // 0 or very few ms. not 1000ms.

    However, when you call this method together with the await function, JavaScript will pause for the given period in ms.

    // Javascript Example
    var time = new Date();
    led.on();
    await obniz.wait(1000); // led ON 1sec.
    led.off();
    console.log((new Date()).getTime() - time.getTime()) // => about 1000

    Parameters

    • msec: any

    Returns Promise<void>

wired

  • wired<K>(partsname: K, options?: WiredNameOptionsMap[K]): WiredNameMap[K]
  • Setup Parts of parts library

    Type parameters

    Parameters

    • partsname: K
    • Optional options: WiredNameOptionsMap[K]

    Returns WiredNameMap[K]

Static PartsRegistrate

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

    Parameters

    • arg0: typeof ObnizPartsInterface

      Parts class

    • Optional arg1: any

    Returns void

Static getPartsClass

  • getPartsClass<K>(name: K): any

Generated using TypeDoc