Tier0 技术指导手册

快速开始

选择最合适的版本

Edge、Tier0 Cloud 或 Enterprise:通过定位、套餐和能力矩阵选择适合你的 Tier0 版本。

查看 这里 了解每个产品的详细功能,并选择最适合你的版本。

快速开始

安装

按版本安装 Tier0。

Tier0 提供三个版本:

  • Edge - 开源版,可通过 Docker 在本地运行。
  • Tier0 Cloud - 云端托管 SaaS。
  • Enterprise - 面向企业环境的私有化部署版本。

请参阅 选择最合适的版本 来判断哪个版本最符合用户需求。

在体验 Tier0 Cloud 之前,需要申请试用账号。

  1. 在 注册 Tier0 页面注册账号。
  2. 用发到邮箱的验证码进行验证后,使用注册账号登录。
  3. 创建一个工作空间并开始体验 Tier0.

选择最合适的版本 - 比较各个版本并选择最适合你的版本。

快速开始

用户旅程

开始使用 Tier0 的推荐步骤。

flowchart TD
  app["构建应用"]
  namespace["创建命名空间"]
  external["接入外部数据(可选)"]
  use["在应用中使用统一数据"]
  app --> namespace --> external --> use
  namespace -.->|"跳过可选步骤"| use
  classDef t0accent fill:#B2ED1D,stroke:#73B200,color:#171717
  class use t0accent
操作 执行者 版本 说明
构建应用 你 Cloud 与 Agent 对话,创建自定义应用。
创建命名空间 Agent Cloud 根据应用的业务逻辑创建命名空间和数据模型。
接入外部数据(可选) 你 Cloud、Enterprise 如有需要,提供现有业务系统或设备的信息,供 Agent 连接。
集成数据 Agent Cloud、Enterprise 将外部数据映射、转换并集成到应用现有的数据模型中。

使用 Tier0

准备数据基础

为应用连接外部数据,并在 Tier0 中建模与集成。

Tier0 为应用建立数据基础:

  • 接收应用业务数据
  • 连接现有系统和设备的数据源
  • 将数据集成到统一模型供应用使用。

所有数据都建模到 命名空间 下的 数据表里,并按数据类型组织。

  • 主要来自业务系统的关系数据存储在 Record 表中。
  • 主要来自设备的时序数据存储在 Sample 表中。
flowchart TB
  namespace["命名空间"] --> table["数据表"]
  table --> record["Record 表<br/>关系数据"]
  table --> sample["Sample 表<br/>时序数据"]
  classDef t0accent fill:#B2ED1D,stroke:#73B200,color:#171717
  class table t0accent

业务数据可来自应用操作或外部系统;时序数据主要来自已连接的设备。

flowchart LR
  app["应用"] -->|"业务数据"| record["Record"]
  stream["数据流"] -->|"设备数据"| sample["Sample"]
  classDef t0accent fill:#B2ED1D,stroke:#73B200,color:#171717
  class record,sample t0accent
  • 数据源:连接外部数据服务器,通常需要认证。
  • 数据流:从服务器采集数据,按需处理,并存入 命名空间 数据表。
flowchart LR
  source["数据源<br/>连接服务器"] --> stream["数据流<br/>采集并处理"]
  classDef t0accent fill:#B2ED1D,stroke:#73B200,color:#171717
  class source,stream t0accent
  1. 在 Builder 中构建应用,让 Agent 在 命名空间 中准备业务数据表。

  2. 在 数据连接 > 数据源 中连接所需数据源并配置认证。

  3. 让 Agent 创建数据流,从已连接的数据源采集和处理数据,写入应用生成的 命名空间 数据表。

使用 Tier0

操作工厂数据

通过 MQTT 和 API 操作 UNS 数据,并查看 API 参考。

你可以通过 MQTT 和 API 操作 UNS 数据。

Tier0 生成的凭据可用于让 MQTT 客户端连接 UNS broker。

在 数据连接 > 数据源 > MQTT Device 中生成 MQTT 凭据并记录。

  1. 安装并打开 MQTTX。
  2. 使用 UNS broker 信息和生成的凭据添加连接。
    Terminal window
    {
    "Host": "mqtt.tier0.dev",
    "Port": 1883,
    "Client ID": "<generated client ID>",
    "Username": "<generated username>",
    "Password": "<generated password>"
    }
  1. 确认客户端状态正常。
  2. 复制 UNS 模型 Topic,通过客户端向其发布一条消息。
  • Base URL: https://<your-tier0-host>/openapi/v2
  • Authentication: 将从 Tier0 获取的 API Key 放在 x-api-key 请求头中。
  • POST /uns/metadata:find — 列出数据表并获取数据表 ID

    Terminal window
    const base = "https://your-tier0-host/openapi/v2";
    const response = await fetch(`${base}/uns/metadata:find`, {
    method: "POST",
    headers: { "content-type": "application/json", "x-api-key": "your-api-key" },
    body: JSON.stringify({"kind": "collection", "filter": {}, "page": {"mode": "offset", "page": 1, "size": 20}}),
    });
    const result = await response.json();
    if (!response.ok || result.code !== 0) throw new Error(result.error?.code || result.msg);
    console.log(result.data.items);
  • POST /uns/collections/{collectionId}/records:find — 列出 Records 并获取 Record ID

    Terminal window
    const base = "https://your-tier0-host/openapi/v2";
    const collectionId = "your-collection-id";
    const response = await fetch(`${base}/uns/collections/${encodeURIComponent(collectionId)}/records:find`, {
    method: "POST",
    headers: { "content-type": "application/json", "x-api-key": "your-api-key" },
    body: JSON.stringify({"limit": 20}),
    });
    const result = await response.json();
    if (!response.ok || result.code !== 0) throw new Error(result.error?.code || result.msg);
    console.log(result.data);
  • POST /uns/collections/{collectionId}/samples:latest — 获取 Record 的最新 Sample

    Terminal window
    const base = "https://your-tier0-host/openapi/v2";
    const collectionId = "your-collection-id";
    const response = await fetch(`${base}/uns/collections/${encodeURIComponent(collectionId)}/samples:latest`, {
    method: "POST",
    headers: { "content-type": "application/json", "x-api-key": "your-api-key" },
    body: JSON.stringify({"recordIds": ["record_123"]}),
    });
    const result = await response.json();
    if (!response.ok || result.code !== 0) throw new Error(result.error?.code || result.msg);
    console.log(result.data);
  • POST /uns/collections/{collectionId}/samples:find — 获取指定时间范围内的 Samples

    Terminal window
    const base = "https://your-tier0-host/openapi/v2";
    const collectionId = "your-collection-id";
    const response = await fetch(`${base}/uns/collections/${encodeURIComponent(collectionId)}/samples:find`, {
    method: "POST",
    headers: { "content-type": "application/json", "x-api-key": "your-api-key" },
    body: JSON.stringify({"recordIds": ["record_123"], "from": 1792454400000, "to": 1792540800000, "filter": {"temperature": {"$gt": 20}}, "limit": 20}),
    });
    const result = await response.json();
    if (!response.ok || result.code !== 0) throw new Error(result.error?.code || result.msg);
    console.log(result.data);
使用 Tier0

使用 Agent 操作 Tier0

通过 MCP 将 AI Agent 连接到 Tier0。

通过 MCP 将 AI Agent 连接到 Tier0。Agent 可以在你授予的权限范围内查找并调用平台 API,使用平台功能。

Work on Tier0 with your preferred AI agent.
Claude Code
Codex
Gemini CLI
Cursor
GitHub Copilot
WorkBuddy
  1. 在 设置 > 插件 > MCP 中添加 MCP 服务器,填写从 Tier0 获取的 URL。
  2. 在 Tier0 的 设置 > API Keys > Personal Keys 中创建具有所需权限的个人 API Key。
  3. 将个人 API Key 添加到 Codex 中的 MCP 服务器:
    Terminal window
    { "Authorization": "Bearer <your-personal-api-key>" }
  4. 让 Agent 调用 whoami,检查连接。
MCP 工具 用途
whoami 检查身份和权限。
docs 阅读 API 文档。
search 查找 API 操作。
execute 调用 API 操作。

先让 Agent 使用 docs 和 search 找到所需操作,再使用 execute 调用。例如:

Terminal window
读取我的工作空间中 `Plant/Line1/Metric/Temperature` 的当前值。

操作工厂数据 — 了解 Tier0 如何组织和提供工厂数据。

最佳实践

连接数据源

Tier0 支持连接多种工业协议,包括 OPC UA、Modbus、MQTT 等。

  • 输入服务器地址后,系统会自动从服务器获取安全配置。
  • 支持用户名和密码或证书身份验证。
Terminal window
{
"name": "ua",
"description": "",
"protocol": "opcua",
"endpoint": "opc.tcp://220.184.175.73:4841/demo/",
"runtimeLocation": "local",
"opcua": {
"securityMode": "None",
"securityPolicy": "None"
}
}

只需提供服务器地址和单元 ID。

Terminal window
{
"name": "modbus",
"description": "",
"protocol": "modbus-tcp",
"endpoint": "tcp://220.184.175.73:1502",
"runtimeLocation": "local",
"modbus": {
"unitId": 1
}
}

Tier0 既可以作为 MQTT Broker 接收设备数据,也可以作为客户端连接外部 MQTT Broker。

  • 作为 Broker:

    1. 连接 MQTT Device 时,系统会生成客户端 ID、用户名和密码等连接凭据。
    2. 第三方客户端必须使用连接面板中显示的发布主题来发布消息。
    3. 让 Agent 创建以发布主题为输入的数据流,将数据发送到指定的命名空间。
  • 作为客户端:连接第三方 Broker。

    Terminal window
    {
    "name": "111",
    "description": "",
    "protocol": "mqtt",
    "endpoint": "mqtt://220.184.175.73:1883",
    "runtimeLocation": "local",
    "mqtt": {
    "clientId": "tier0UxxxxxxxxuwQVfi"
    }
    }

Tier0 既可以作为 HTTP 服务器供第三方访问,也可以作为客户端调用其他 HTTP 服务器的 API。

  • 作为服务器:

    1. 在 Tier0 中添加 HTTP 服务器,并从信息面板获取完整地址。
    2. 让 Agent 创建数据流,定义数据和后续路由,共同构成 API。
    3. 第三方使用该地址和设定的路由调用 API 并获取数据。
  • 作为客户端:连接第三方 HTTP 服务器。

Terminal window
{
"name": "222",
"description": "",
"protocol": "http-api",
"endpoint": "http://220.184.175.73:8088/api/telemetry",
"runtimeLocation": "local",
"role": "client",
"http": {
"authentication": "none"
}
}
  • 数据库地址必须同时包含端口和数据库名。
  • 需要提供初始查询命令。
  • 如果数据库允许匿名连接,可以跳过身份验证。
Terminal window
{
"name": "eee",
"description": "",
"protocol": "edge-sql",
"endpoint": "mysql://hzoffice.tier0.dev:3307/demo_factory",
"runtimeLocation": "local",
"sql": {
"queries": {
"query1": "SELECT * FROM telemetry ORDER BY id DESC LIMIT 5"
},
"tlsMode": "verify-full"
},
"credentialRef": "ref_9ce47b8778xxxxxxxx7dad49a86dbad"
}
  1. 通过 OAuth 连接 Tier0 Github。
  2. 在数据源信息面板中查找该组织的资源。
  3. 让 Agent 创建数据流以获取所需数据。
  1. 让 Agent 创建数据流,从已连接的数据源获取数据。
  2. 在提示词中提供必要信息,例如 Modbus 寄存器、数据库查询语句、UA 命名空间 URI 和 MQTT 主题。