Working with Factory Data
Available inEdgeCloudEnterprise
Data in Tier0 unified namespace can be altered and managed through MQTT and APIs with authorization.
MQTT clients can connect to the UNS broker with credentials generated on Tier0.
Generating MQTT Credentials
Section titled “Generating MQTT Credentials”Generate MQTT credentials in Connect > Source > MQTT Device and make a note of it.
Connecting MQTT Clients
Section titled “Connecting MQTT Clients”- Install and open MQTTX.
- Add a connection with the information of the UNS broker and the generated credentials.
Terminal window {"Host": "mqtt.tier0.dev","Port": 1883,"Client ID": "<generated client ID>","Username": "<generated username>","Password": "<generated password>"}
- Install and open MQTT Explorer.
- Add a new connection with the UNS broker information and the generated credentials.
Terminal window {"Protocol": "mqtt://","Host": "mqtt.tier0.dev","Port": 1883,"Username": "<generated username>","Password": "<generated password>"} - Change the client ID to the credential ID in ADVANCED before connecting.
-
Use Event Flow - Data processing module in Tier0 based on Node-RED.
- Create an Event Flow in Flows, and start it with an
mqtt innode. - Select the UNS broker as Server (same name as the flow) and set Topic to a UNS model in the node.
- Create an Event Flow in Flows, and start it with an
-
Use Independent Node-RED Instance
- Install and open the Node-RED instance.
- Add a server in the
mqtt innode with the following information.
Terminal window {{/* under Connection */}"Server": "mqtt://mqtt.tier0.dev","Port": 1883,"Client ID": "<generated clientId>",{/* under Security */}"Username": "<generated username>","Password": "<generated password>"}
Testing Connections
Section titled “Testing Connections”- Make sure the client status is normal.
- Copy a UNS model topic and publish a message to it through the client.
Basic Information
Section titled “Basic Information”- Base URL:
https://<your-tier0-host>/openapi/v2 - Authentication: Send the API key obtained from Tier0 in the
x-api-keyheader.
Request Examples
Section titled “Request Examples”-
POST /uns/metadata:find— List collections and get the collection IDTerminal 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— List records and get the record IDTerminal 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— Get the latest sample for a recordTerminal 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— Get samples in a time rangeTerminal 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}'