TagoIO SDK for JavaScript and TypeScript
    Preparing search index...

    Class Device

    Device class for IoT device operations

    This class provides comprehensive functionality for managing IoT devices, including sending and retrieving data, streaming real-time data, and managing device configurations. Each device instance requires a valid device token for authentication.

    import { Device } from "@tago-io/sdk";

    const device = new Device({ token: "your-device-token" });

    // Send data to device
    await device.sendData({
    variable: "temperature",
    value: 25.6,
    unit: "°C",
    time: new Date()
    });

    // Get data from device
    const data = await device.getData({
    variables: ["temperature"],
    qty: 10
    });
    // Stream real-time data
    for await (const chunk of device.getDataStreaming({ variables: ["sensor1"] })) {
    console.log("New data:", chunk);
    }
    Index

    Constructors

    Methods

    • Delete data from device

      Parameters

      Returns Promise<string>

      const myDevice = new Device({ token: "my_device_token" });

      const result = await myDevice.deleteData({
      query: "last_item",
      variable: "humidity",
      value: 10
      });
    • Edit data in a Mutable-type device.

      Parameters

      • data: DataEdit | DataEdit[]

        Array or object with the data to be edited, each object with the data's ID.

      Returns Promise<string>

      Success message with the amount of data items updated.

      const myDevice = new Device({ token: "my_device_token" });

      const result = await myDevice.editData({
      id: "id_of_the_data_item",
      value: 123,
      time: "2022-04-01 12:34:56",
      location: { lat: 42.2974279, lng: -85.628292 },
      });
    • Get paronlyUnReameters from device

      Parameters

      • status: "all" | "onlyUnRead" | "onlyRead"

      Returns Promise<Required<ConfigurationParams>[]>

      const myDevice = new Device({ token: "my_device_token" });

      const result = await myDevice.getParameters();
    • Get information about the current device

      Returns Promise<DeviceItem>

      const myDevice = new Device({ token: "my_device_token" });

      const result = await myDevice.info();
    • Send data to device

      Parameters

      • data: DataCreate | DataCreate[]

        An array or one object with data to be send to TagoIO using device token

      Returns Promise<string>

      amount of data added

      const myDevice = new Device({ token: "my_device_token" });

      const result = await myDevice.sendData({
      variable: "temperature",
      unit: "F",
      value: 55,
      time: "2015-11-03 13:44:33",
      location: { lat: 42.2974279, lng: -85.628292 },
      });
    • Experimental

      Stream data to device

      Parameters

      • data: DataCreate[]

        An array or one object with data to be send to TagoIO using device token

      • options: Omit<OptionsStreaming, "neverStop">

        Stream options

      Returns Promise<string>

      const myDevice = new Device({ token: "my_device_token" });

      const data = [
      {
      variable: "temperature",
      unit: "F",
      value: 55,
      time: "2015-11-03 13:44:33",
      location: { lat: 42.2974279, lng: -85.628292 },
      },
      {
      variable: "temperature",
      unit: "F",
      value: 53,
      time: "2015-11-03 13:44:33",
      location: { lat: 43.2974279, lng: -86.628292 },
      },
      // ...
      ];

      const result = await myDevice.sendDataStreaming(data, {
      poolingRecordQty: 1000,
      poolingTime: 1000,
      });
    • Mark parameter as read

      Parameters

      • parameterID: string

        Parameter identification

      Returns Promise<string>

      const myDevice = new Device({ token: "my_device_token" });

      const result = await myDevice.setParameterAsRead("parameter_id");