공장 데이터 작업
지원 에디션EdgeCloudEnterprise
MQTT와 API를 통해 UNS 데이터를 조작할 수 있습니다.
MQTT
섹션 제목: “MQTT”MQTT client는 Tier0에서 생성한 credential로 UNS broker에 연결할 수 있습니다.
MQTT Credential 생성
섹션 제목: “MQTT Credential 생성”Tier0의 Edge 탭에서 새 credential을 만들고 기록해 둡니다.
MQTT Client 연결
섹션 제목: “MQTT Client 연결”- MQTTX를 설치하고 엽니다.
- Tier0 UNS broker 정보와 생성된 credential로 connection을 추가합니다.
Terminal window {"Host": "mqtt.tier0.dev","Port": 1883,"Client ID": "<generated client ID>","Username": "<generated username>","Password": "<generated password>"}
- MQTT Explorer를 설치하고 엽니다.
- broker 정보와 생성된 credential로 새 connection을 추가합니다.
Terminal window {"Protocol": "mqtt://","Host": "mqtt.tier0.dev","Port": 1883,"Username": "<generated username>","Password": "<generated password>"} - 연결하기 전에 ADVANCED에서 client ID를 credential ID로 변경합니다.
- Event Flow 사용 - Tier0 안의 Node-RED 기반 data processing module입니다.
- Event Flow에서 flow를 만들고
mqtt innode로 시작합니다. - node에서 Server를 UNS broker(flow와 같은 이름)로 선택하고 Topic을 UNS model로 설정합니다.
- Event Flow에서 flow를 만들고
- 독립 Node-RED Instance 사용
- Node-RED instance를 설치하고 엽니다.
mqtt innode에서 아래 정보로 server를 추가합니다.
Terminal window {{/* under Connection */}"Server": "mqtt://mqtt.tier0.dev","Port": 1883,"Client ID": "<generated clientId>",{/* under Security */}"Username": "<generated username>","Password": "<generated password>"}
Connection 테스트
섹션 제목: “Connection 테스트”- client status가 정상인지 확인합니다.
- UNS model topic을 복사하고 client를 통해 message를 publish합니다.
API
섹션 제목: “API”REST API를 사용해 UNS 데이터를 조작합니다.
API Key 가져오기
섹션 제목: “API Key 가져오기”API keys는 Settings > API Keys에 있습니다. account type에 따라 허용되는 key type이 다릅니다.
- Service Key: Admin과 Owner만 만들 수 있습니다.
- Personal Key: 누구나 만들 수 있으며 permission scope는 account와 같습니다.
-
/uns/createUNS path 또는 topic을 생성합니다.
namespace를 사용해 node tree를 정의합니다.Terminal window const BASE_URL = process.env.TIER0_BASE_URL;const API_KEY = process.env.TIER0_API_KEY;const response = await fetch(`${BASE_URL}/uns/create`, {method: 'POST',headers: {'content-type': 'application/json','x-api-key': API_KEY,},body: JSON.stringify({namespace: [{name: 'DemoFactory',type: 'PATH',children: [{name: 'Site_01',type: 'PATH',children: [{name: 'Production',type: 'PATH',children: [{name: 'Produced_Qty',type: 'TOPIC',topicType: 'METRIC',displayName: 'Produced Quantity',description: 'Produced quantity from the production line.',enableHistory: true,fields: [{ name: 'value', type: 'DOUBLE', unit: 'pcs' },],},],},],},],},],}),});const result = await response.json();console.log(result.data.results);Terminal window import osimport requestsbase_url = os.environ["TIER0_BASE_URL"]api_key = os.environ["TIER0_API_KEY"]response = requests.post(f"{base_url}/uns/create",headers={"x-api-key": api_key},json={"namespace": [{"name": "DemoFactory","type": "PATH","children": [{"name": "Site_01","type": "PATH","children": [{"name": "Production","type": "PATH","children": [{"name": "Produced_Qty","type": "TOPIC","topicType": "METRIC","displayName": "Produced Quantity","description": "Produced quantity from the production line.","enableHistory": True,"fields": [{"name": "value", "type": "DOUBLE", "unit": "pcs"},],},],},],},],},],},timeout=30,)response.raise_for_status()result = response.json()print(result["data"]["results"])Terminal window curl -X POST "$TIER0_BASE_URL/uns/create" \-H "content-type: application/json" \-H "x-api-key: $TIER0_API_KEY" \-d '{"namespace": [{"name": "DemoFactory","type": "PATH","children": [{"name": "Site_01","type": "PATH","children": [{"name": "Production","type": "PATH","children": [{"name": "Produced_Qty","type": "TOPIC","topicType": "METRIC","displayName": "Produced Quantity","description": "Produced quantity from the production line.","enableHistory": true,"fields": [{ "name": "value", "type": "DOUBLE", "unit": "pcs" }]}]}]}]}]}' -
/uns/read하나 이상의 UNS topics에 대해 최신 값과 메타데이터를 읽습니다.
Terminal window const BASE_URL = process.env.TIER0_BASE_URL;const API_KEY = process.env.TIER0_API_KEY;const response = await fetch(`${BASE_URL}/uns/read`, {method: 'POST',headers: {'content-type': 'application/json','x-api-key': API_KEY,},body: JSON.stringify({topics: ['DemoFactory/Site_01/Production/Produced_Qty',],include_leaf_value: true,include_metadata: true,}),});const result = await response.json();console.log(result.data.results);Terminal window import osimport requestsbase_url = os.environ["TIER0_BASE_URL"]api_key = os.environ["TIER0_API_KEY"]response = requests.post(f"{base_url}/uns/read",headers={"x-api-key": api_key},json={"topics": ["DemoFactory/Site_01/Production/Produced_Qty",],"include_leaf_value": True,"include_metadata": True,},timeout=30,)response.raise_for_status()result = response.json()print(result["data"]["results"])Terminal window curl -X POST "$TIER0_BASE_URL/uns/read" \-H "content-type: application/json" \-H "x-api-key: $TIER0_API_KEY" \-d '{"topics": ["DemoFactory/Site_01/Production/Produced_Qty"],"include_leaf_value": true,"include_metadata": true}' -
/uns/updatepath로 UNS node를 업데이트합니다.updateMask를 사용해 변경할 필드를 지정합니다.Terminal window const BASE_URL = process.env.TIER0_BASE_URL;const API_KEY = process.env.TIER0_API_KEY;const response = await fetch(`${BASE_URL}/uns/update`, {method: 'POST',headers: {'content-type': 'application/json','x-api-key': API_KEY,},body: JSON.stringify({path: 'DemoFactory/Site_01/Production/Produced_Qty',displayName: 'Produced Quantity',description: 'Updated production output quantity.',updateMask: ['displayName', 'description'],}),});const result = await response.json();console.log(result.data);Terminal window import osimport requestsbase_url = os.environ["TIER0_BASE_URL"]api_key = os.environ["TIER0_API_KEY"]response = requests.post(f"{base_url}/uns/update",headers={"x-api-key": api_key},json={"path": "DemoFactory/Site_01/Production/Produced_Qty","displayName": "Produced Quantity","description": "Updated production output quantity.","updateMask": ["displayName", "description"],},timeout=30,)response.raise_for_status()result = response.json()print(result["data"])Terminal window curl -X POST "$TIER0_BASE_URL/uns/update" \-H "content-type: application/json" \-H "x-api-key: $TIER0_API_KEY" \-d '{"path": "DemoFactory/Site_01/Production/Produced_Qty","displayName": "Produced Quantity","description": "Updated production output quantity.","updateMask": ["displayName", "description"]}' -
/uns/delete하나 이상의 UNS models를 삭제합니다.
hard_delete: false를 사용하면 models를 휴지통으로 이동합니다.Terminal window const BASE_URL = process.env.TIER0_BASE_URL;const API_KEY = process.env.TIER0_API_KEY;const response = await fetch(`${BASE_URL}/uns/delete`, {method: 'POST',headers: {'content-type': 'application/json','x-api-key': API_KEY,},body: JSON.stringify({topics: ['DemoFactory/Site_01/Production/Produced_Qty',],hard_delete: false,}),});const result = await response.json();console.log(result.data);Terminal window import osimport requestsbase_url = os.environ["TIER0_BASE_URL"]api_key = os.environ["TIER0_API_KEY"]response = requests.post(f"{base_url}/uns/delete",headers={"x-api-key": api_key},json={"topics": ["DemoFactory/Site_01/Production/Produced_Qty",],"hard_delete": False,},timeout=30,)response.raise_for_status()result = response.json()print(result["data"])Terminal window curl -X POST "$TIER0_BASE_URL/uns/delete" \-H "content-type: application/json" \-H "x-api-key: $TIER0_API_KEY" \-d '{"topics": ["DemoFactory/Site_01/Production/Produced_Qty"],"hard_delete": false}'
API 참조
섹션 제목: “API 참조”다음 단계
섹션 제목: “다음 단계”- UNS에서 앱 구축 - UNS 데이터로 산업 애플리케이션을 구축합니다.
- UNS 데이터 분석 - Marimo Notebook과 Python으로 UNS 데이터를 분석합니다.