Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ObnizParts

Hierarchy

Index

Constructors

constructor

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

Accessors

Static version

  • get version(): any

Methods

addListener

  • Parameters

    Returns this

close

  • close(): 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>

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

  • 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

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

  • 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

repeat

  • repeat(callback: any, interval: any): void
  • Repeat will call the callback function periodically while it is connected to obniz Board. It will stop calling once it is disconnected from obniz Board.

    // Javascript Example
     obniz.ad0.start();
     obniz.repeat(function(){
       if (obniz.ad0.value > 2.5) {
         obniz.io0.output(true);
       } else {
         obniz.io0.output(false);
       }
     }, 100)

    Parameters

    • callback: any
    • interval: any

      default 100. It mean 100ms interval loop.

    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

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
  • Get parts class.

    constructor

    Type parameters

    Parameters

    • name: K

    Returns any

Generated using TypeDoc