Public API ERa hỗ trợ

Ghi chú

1. Hướng dẫn lấy Token

Bước 1: Đăng nhập app.e-ra.io

Bước 2: Chọn profile

Bước 3: Copy Auth Token

2. Danh sách API:

2.1. API lấy unit của user:

{
  id: unit_id,
  name: "Unit Name",
  stations: [
    {
      id: subunit_id,
      name: "Sub-unit Name",
      devices: [
        {
          id: end_device_id,
          name: "end device led 1",
        },
      ],
    },
  ],
}

--> Lấy end_device_id

2.2. API lấy widget dựa vào end device id

{
  Items: [
    {
      id: widget_id,
      order: 0,
      template: "action",
      type: "action",
      configuration: {
        id: action_display_id,
        template: "on_off_button_action_template",
        title: "",
        configuration: {
          action_on: "key_on",
          action_off: "key_off",
          text_on: "ON",
          text_off: "OFF",
        },
      },
    },
  ];
}

--> Lấy action_on hoặc action off

2.3. API điều khiển thiết bị dựa vào action key

{
"key": "key_on",
"source": "internet"
}
  • HEADERS: {Authorization: Token}

  • RESPONS_STATUS_CODE: 200

  • RESPONSE_DATA:

{
  result: "ok",
};

2.4. API Lấy giá trị của datastream

{
  current_value_only: 0,
};

3. Ví dụ

Bước 1: Gọi api lấy unit của user:

{
  id: 1,
  name: "Unit Name",
  stations: [
    {
      id: 2,
      name: "Sub-unit Name",
      devices: [
        {
          id: 3,
          name: "end device led 1",
        },
      ],
    },
  ],
};

--> end_device_id là 3

Bước 2: Gọi api lấy widget của end device 3:

{
  items: [
    {
      id: 1,
      order: 0,
      template: "action",
      type: "action",
      configuration: {
        id: 103,
        template: "on_off_button_action_template",
        title: "",
        configuration: {
          action_on: "c163e4a9-79a6-4ae5-9dd9-c5cf8377d3e3",
          action_off: "dbd5b4d7-8c5c-485f-8aca-90474ffe9d84",
          icon_on: "PoweroffOutlined",
          icon_off: "PoweroffOutlined",
          config: 163,
          text_on: "ON",
          text_off: "OFF",
        },
      },
    },
  ],
};

--> action_on key là c163e4a9-79a6-4ae5-9dd9-c5cf8377d3e3

--> action_off key là dbd5b4d7-8c5c-485f-8aca-90474ffe9d84

Bước 3: Gọi api điều khiển thiết bị và api lấy giá trị của datastream

- Gọi api điều khiển thiết bị

{
key:  "c163e4a9-79a6-4ae5-9dd9-c5cf8377d3e3",
source: "internet"
}  
  • RESPONSE_DATA:

{
  result: "ok",
};

- API Lấy giá trị của datastream

{
  current_value_only: 1,
};

Last updated