콘텐츠로 이동

설명서 내보내기

공장 데이터 작업

지원 에디션EdgeCloudEnterprise

MQTT와 API를 통해 UNS 데이터를 조작할 수 있습니다.

Tier0에서 생성한 자격 증명으로 MQTT 클라이언트를 UNS broker에 연결할 수 있습니다.

Connect > Source > 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 키를 x-api-key 헤더에 넣습니다.
  • POST /uns/metadata:find — Collections 목록과 Collection 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);