Trabajar con datos de fábrica
Disponible enEdgeCloudEnterprise
Puedes operar datos de UNS mediante MQTT y APIs.
Los MQTT clients pueden conectarse al broker UNS con credentials generadas en Tier0.
Generar MQTT Credentials
Sección titulada «Generar MQTT Credentials»En la pestaña Edge de Tier0, crea una nueva credential y guárdala.
Conectar MQTT Clients
Sección titulada «Conectar MQTT Clients»- Install and open MQTTX.
- Agrega una conexión con la información del broker UNS y las credentials generadas.
Terminal window {"Host": "mqtt.tier0.dev","Port": 8883,"Client ID": "<generated client ID>","Username": "<generated username>","Password": "<generated password>"}
- Install and open MQTT Explorer.
- Agrega una nueva conexión con la información del broker UNS y las credentials generadas.
Terminal window {"Protocol": "mqtt://","Host": "mqtt.tier0.dev","Port": 8883,"Username": "<generated username>","Password": "<generated password>"} - Change the client ID to the credential ID in ADVANCED before connecting.
- Usa Event Flow - módulo de procesamiento de datos en Tier0 basado en Node-RED.
- Crea un Event Flow en Flows y empieza con un node
mqtt in. - Select the UNS broker as Server (same name as the flow) and set Topic to a UNS model in the node.
- Crea un Event Flow en Flows y empieza con un node
- Usa una instancia independiente de Node-RED
- Instala y abre la instancia de Node-RED.
- Agrega un server en el node
mqtt incon la siguiente información.
Terminal window {{/* under Connection */}"Server": "mqtt://mqtt.tier0.dev","Port": 8883,"Client ID": "<generated clientId>",{/* under Security */}"Username": "<generated username>","Password": "<generated password>"}
Probar conexiones
Sección titulada «Probar conexiones»- Asegúrate de que el client status sea normal.
- Copia un topic de modelo UNS y publica un message en él mediante el client.
Usa la REST API para operar datos de UNS.
Obtener API Key
Sección titulada «Obtener API Key»Las API keys están en Settings > API Keys. Según el account type, los tipos de key permitidos son distintos.
- Service Key: Solo la pueden crear Admin y Owner.
- Personal Key: La puede crear cualquier persona, y su permission scope es el mismo que el de la cuenta.
Ejemplos
Sección titulada «Ejemplos»-
/uns/createCrea un path o topic de UNS. Usa
namespacepara definir el 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/readLee el valor más reciente y los metadatos de uno o varios 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/updateActualiza un UNS node por
path. UsaupdateMaskpara especificar qué campos deben cambiar.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/deleteElimina uno o varios UNS models. Usa
hard_delete: falsepara mover los models a la papelera.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}'
Referencia de API
Sección titulada «Referencia de API»Siguiente
Sección titulada «Siguiente»- Crear apps sobre UNS — Crea aplicaciones industriales con datos UNS.
- Analizar datos UNS — Analiza datos UNS con Marimo Notebook y Python.