Class ObnizSystemMethods

Hierarchy

Constructors

Properties - Embeds

ble?: ObnizBLE

If obnizOS ver >= 3.0.0, automatically load [[ObnizCore.Components.Ble.Hci.ObnizBLE|ObnizHciBLE]], and obnizOS ver < 3.0.0 throw unsupported Error,

display?: Display
location?: Location
motion?: Motion
storage?: Storage
switch?: ObnizSwitch

Properties - Measurement

logicAnalyzer?: LogicAnalyzer
measure?: ObnizMeasure

Properties - Other

boot_reason?: string

This variable indicate installed boot reason of target device

var obniz = new Obniz('1234-5678');
obniz.onconnect = async function() {
console.log(obniz.boot_reason) // ex. "DEEPSLEEP_RESET"
}
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.
}
connectionCheckLoopInterval: null | number = null

This variable sets interval time to check connection state to obniz Device.

connectionState: "closed" | "connected" | "connecting" | "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: 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);
}
deviceTimestamp: null | number = null
firmware_ver?: 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"
}
hw?: 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: string

obniz id

isNode: boolean

Is node.js environment or not.

metadata?: {
    [key: string]: string;
}

Device metadata set on obniz cloud.

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

Type declaration

  • [key: string]: string
onclose?: ((obniz) => void)

Type declaration

    • (obniz): void
    • onclose will be called when disconnected.

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

      }
      obniz.onclose = async function() {

      }

      Parameters

      Returns void

onconnect?: ((obniz) => void)

Type declaration

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

      Parameters

      Returns void

onerror?: ((obniz, error) => void)

Type declaration

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

      Parameters

      Returns void

onloop?: ((obniz) => void | Promise<void>)

Type declaration

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

      }

      Parameters

      Returns void | Promise<void>

plugin_name?: string

This variable indicate installed plugin_name of target device

var obniz = new Obniz('1234-5678');
obniz.onconnect = async function() {
console.log(obniz.plugin_name) // ex. "my_plugin"
}
prefixed: string | boolean

Properties - Peripherals

Properties - hardware specific components

Properties - network

wifi?: WiFi

Properties - plugin

plugin?: Plugin

Accessors

Methods

  • 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

    Deprecated

    replace with closeWait

  • 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>

  • 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

  • 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: {
          timeout?: number;
      }
      • Optional timeout?: number

        timeout in seconds

    Returns Promise<boolean>

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

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

    Parameters

    Returns boolean

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

    • 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
  • 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

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

    Parameters

    Returns number

  • Return the listeners registered for a given event.

    Parameters

    Returns ListenerFn[]

  • 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: number

      start time of measure response time

    • Optional rand: number

      Unique identifier of ping data

    • Optional forceGlobalNetwork: boolean

    Returns Promise<void>

  • Set onloop function. Use onloop property instead. This is deprecated function.

    Parameters

    • callback: any
    • Optional interval: number

      default 100. It mean 100ms interval loop.

    Returns void

    Deprecated

  • 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

  • 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: boolean

    Returns void

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

  • Send json/binary data to obniz Cloud or device.

    Parameters

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

      send data

    • Optional options: {
          connect_check?: boolean;
          local_connect?: boolean;
      }

      send option

      • Optional connect_check?: boolean
      • Optional local_connect?: boolean

        If false, send data via gloval internet.

    Returns void

  • Set the internal clock of the obniz device. This will be set to device immediately and used as device timestamp.

    // JavaScript example
    obniz.setClock();

    Parameters

    • Optional unix_milliseconds: number

      number of milliseconds since January 1, 1970 00:00:00 UTC. If not specified, the current time will be used.

    Returns 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

  • Parameters

    • params: {
          interval: number;
          timestamp: "none" | "unix_seconds" | "unix_milliseconds";
      }
      • interval: number
      • timestamp: "none" | "unix_seconds" | "unix_milliseconds"

    Returns 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

  • Action only with obniz Board 1Y.

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

    // JavaScript example
    obniz.sleepIoTrigger (true);

    Parameters

    • trigger: boolean

      true: Rise (LOW -> HIGH)

      • false: Falling (HIGH -> LOW)

    Returns 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: number

      up to 64800 minutes(45 days ).

    Returns 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: number

      up to 64800 seconds (18 hours).

    Returns 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: number

    Returns Promise<void>

Generated using TypeDoc