Hierarchy

  • Plugin

Constructors

Properties

onCloudTransaction?: PluginCloudTransactionHandler

Handler called when Lua runs cloud.transactionWait(data) on the device.

// Javascript Example
obniz.plugin.onCloudTransaction = async (data, str) => {
// do something with the request from Lua and return the result
return "result for lua";
};
onError?: ((error) => void)

Type declaration

    • (error): void
    • Callback function is called when Frame Information Received

      // Javascript Example
      obniz.plugin.onError = error => {
      console.log(`error occurred: ${error.message}`);
      };

      Parameters

      • error: LuaError

      Returns void

onFrameEnd?: (() => void)

Type declaration

    • (): void
    • Callback function is called when Frame Information Received

      // Javascript Example
      obniz.plugin.onFrameEnd = length => {
      console.log(`frame ended`);
      };

      Returns void

onFrameStart?: ((frame_id, length) => void)

Type declaration

    • (frame_id, length): void
    • Callback function is called when Frame Information Received

      // Javascript Example
      obniz.plugin.onFrameStart = (frame_id, length) => {
      console.log(`${length} bytes will be start`);
      };

      Parameters

      • frame_id: number
      • length: number

      Returns void

onreceive?: PluginReceiveCallbackFunction

Callback function is called when Plugin is received.

// Javascript Example
obniz.plugin.onreceive = data => {
console.log(data);
};

Methods

  • Executing Lua on target device and wait for its returned value.

    The Lua script is run inside a coroutine on the device. Whatever the script returns (as a string) is resolved here. If the script raises an error, the returned Promise is rejected with that error message.

    The Lua side may itself call cloud.transactionWait(...) while running, which is delivered to onCloudTransaction.

    // Javascript Example
    const result = await obniz.plugin.callWait(`return "hello from lua"`);
    console.log(result); // "hello from lua"

    Parameters

    • lua_script: string

      Lua script to be run on target device

    • timeout: number = ...

      timeout in milliseconds (default 30000)

    Returns Promise<string>

  • Executing Lua on target device instantly. Lua script never be saved on a device.

    // Javascript Example
    obniz.plugin.execLua("duration = 60")

    Parameters

    • lua_script: string

    Returns void

  • Executing Lua on target device and save to it's flash memory.

    // Javascript Example
    obniz.storage.savePluginLua(`os.log("Hello World")`);
    obniz.plugin.reloadLua();

    Returns void

  • Scan WiFi

    // Javascript Example
    obniz.plugin.send("obniz.js send data")

    obniz.plugin.send([0x00, 0x01, 0x02])

    Parameters

    • data: string | number | number[] | Buffer

    Returns void

Generated using TypeDoc