공장 데이터 작업
지원 에디션EdgeCloudEnterprise
MQTT와 API를 통해 UNS 데이터를 조작할 수 있습니다.
MQTT
섹션 제목: “MQTT”Tier0에서 생성한 자격 증명으로 MQTT 클라이언트를 UNS broker에 연결할 수 있습니다.
MQTT 자격 증명 생성
섹션 제목: “MQTT 자격 증명 생성”Connect > Source > MQTT Device에서 MQTT 자격 증명을 생성하고 기록합니다.
MQTT 클라이언트 연결
섹션 제목: “MQTT 클라이언트 연결”- MQTTX를 설치하고 실행합니다.
- UNS broker 정보와 생성한 자격 증명으로 연결을 추가합니다.
Terminal window {"Host": "mqtt.tier0.dev","Port": 1883,"Client ID": "<generated client ID>","Username": "<generated username>","Password": "<generated password>"}
- MQTT Explorer를 설치하고 실행합니다.
- UNS broker 정보와 생성한 자격 증명으로 새 연결을 추가합니다.
Terminal window {"Protocol": "mqtt://","Host": "mqtt.tier0.dev","Port": 1883,"Username": "<generated username>","Password": "<generated password>"} - 연결하기 전에 ADVANCED에서 Client ID를 자격 증명 ID로 변경합니다.
- Event Flow 사용: Tier0의 Node-RED 기반 데이터 처리 모듈.
- Flows에서 Event Flow를 만들고
mqtt in노드로 시작합니다. - 노드의 Server로 UNS broker(Flow와 이름이 같음)를 선택하고 Topic을 UNS 모델로 설정합니다.
- 독립 Node-RED 인스턴스 사용
- Node-RED 인스턴스를 설치하고 실행합니다.
mqtt in노드에 다음 정보로 서버를 추가합니다.Terminal window {{/* under Connection */}"Server": "mqtt://mqtt.tier0.dev","Port": 1883,"Client ID": "<generated clientId>",{/* under Security */}"Username": "<generated username>","Password": "<generated password>"}
연결 테스트
섹션 제목: “연결 테스트”- 클라이언트 상태가 정상인지 확인합니다.
- UNS 모델 Topic을 복사하고 클라이언트에서 메시지를 게시합니다.
API
섹션 제목: “API”기본 정보
섹션 제목: “기본 정보”- 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);Terminal window import requestsresponse = requests.post("https://your-tier0-host/openapi/v2/uns/metadata:find",headers={"x-api-key": "your-api-key"},json={"kind": "collection", "filter": {}, "page": {"mode": "offset", "page": 1, "size": 20}},timeout=30,)response.raise_for_status()result = response.json()if result["code"] != 0:raise RuntimeError(result.get("error", result.get("msg")))print(result["data"]["items"])Terminal window curl --fail-with-body -X POST "https://your-tier0-host/openapi/v2/uns/metadata:find" \-H "content-type: application/json" \-H "x-api-key: your-api-key" \-d '{"kind": "collection", "filter": {}, "page": {"mode": "offset", "page": 1, "size": 20}}' -
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);Terminal window import requestsresponse = requests.post("https://your-tier0-host/openapi/v2/uns/collections/your-collection-id/records:find",headers={"x-api-key": "your-api-key"},json={"limit": 20},timeout=30,)response.raise_for_status()result = response.json()if result["code"] != 0:raise RuntimeError(result.get("error", result.get("msg")))print(result["data"])Terminal window curl --fail-with-body -X POST "https://your-tier0-host/openapi/v2/uns/collections/your-collection-id/records:find" \-H "content-type: application/json" \-H "x-api-key: your-api-key" \-d '{"limit": 20}' -
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);Terminal window import requestsresponse = requests.post("https://your-tier0-host/openapi/v2/uns/collections/your-collection-id/samples:latest",headers={"x-api-key": "your-api-key"},json={"recordIds": ["record_123"]},timeout=30,)response.raise_for_status()result = response.json()if result["code"] != 0:raise RuntimeError(result.get("error", result.get("msg")))print(result["data"])Terminal window curl --fail-with-body -X POST "https://your-tier0-host/openapi/v2/uns/collections/your-collection-id/samples:latest" \-H "content-type: application/json" \-H "x-api-key: your-api-key" \-d '{"recordIds": ["record_123"]}' -
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);Terminal window import requestsresponse = requests.post("https://your-tier0-host/openapi/v2/uns/collections/your-collection-id/samples:find",headers={"x-api-key": "your-api-key"},json={"recordIds": ["record_123"], "from": 1792454400000, "to": 1792540800000, "filter": {"temperature": {"$gt": 20}}, "limit": 20},timeout=30,)response.raise_for_status()result = response.json()if result["code"] != 0:raise RuntimeError(result.get("error", result.get("msg")))print(result["data"])Terminal window curl --fail-with-body -X POST "https://your-tier0-host/openapi/v2/uns/collections/your-collection-id/samples:find" \-H "content-type: application/json" \-H "x-api-key: your-api-key" \-d '{"recordIds": ["record_123"], "from": 1792454400000, "to": 1792540800000, "filter": {"temperature": {"$gt": 20}}, "limit": 20}'