Working with UNS Data
Available inEdgeCloudEnterprise
Tier0 allows you to operate on the UNS through MQTT and APIs.
Tier0 enables MQTT clients to connect to the internal MQTT broker and operate on the UNS.
Generating MQTT Credentials
Section titled “Generating MQTT Credentials”- Log in to Tier0, select Edge.
- Click New Credentials on the right side.
- Enter the Name and Description, and click Create.
Connecting MQTT Clients
Section titled “Connecting MQTT Clients”- Install an MQTT client, such as MQTTX, MQTT Explorer and others.
- Use the credentials from Tier0 to connect the client.
Install and open MQTTX.
-
Click the + button at the upper-left corner to add a connection.
-
Enter the broker information and the generated credentials.
Terminal window {"Host": "mqtt.tier0.dev","Port": 8883,"Client ID": "<generated client ID>","Username": "<generated username>","Password": "<generated password>"} -
Click Connect.
- Install and open MQTT Explorer.
- Click Connections at the upper-left corner to add a new connection.
- Enter the broker information and the generated credentials.
Terminal window {"Protocol": "mqtt://","Host": "mqtt.tier0.dev","Port": 8883,"Username": "<generated username>","Password": "<generated password>"} - Click ADVANCED, change the client ID to the generated one.
- Click BACK and then CONNECT.
- Install and open your Node-RED instance, add a new flow.
- Drag in an
mqtt innode and double-click to set its properties under the Connection tab. - Add an MQTT broker, enter
mqtt://mqtt.tier0.devas the Server and1883as the Port. - Enter the the generated ID next to Client ID.
- Switch to Security tab, enter the generated Username and Password.
- Click Done.
Testing Connections
Section titled “Testing Connections”- Log in to Tier0, and go to Edge.
- Click the Clients tab and check the status of each client.
- Copy the topic of the data model under UNS, and publish a message to it through the client.
- Go back to UNS, check the data under the target topic.
Use RestAPI to operate on UNS data, flows and authentication.
-
/flow/createCreate a SourceFlow or EventFlow.
flowNameandflowTypeare required.Terminal window const BASE_URL = process.env.TIER0_BASE_URL;const API_KEY = process.env.TIER0_API_KEY;const response = await fetch(`${BASE_URL}/flow/create`, {method: 'POST',headers: {'content-type': 'application/json','x-api-key': API_KEY,},body: JSON.stringify({flowName: 'Manufacturing source flow',flowType: 'SourceFlow',description: 'Collects UNS source data from the plant.',template: '{}',}),});const result = await response.json();console.log(result.data.id, result.data.brokerID);Terminal window import osimport requestsbase_url = os.environ["TIER0_BASE_URL"]api_key = os.environ["TIER0_API_KEY"]response = requests.post(f"{base_url}/flow/create",headers={"x-api-key": api_key},json={"flowName": "Manufacturing source flow","flowType": "SourceFlow","description": "Collects UNS source data from the plant.","template": "{}",},timeout=30,)response.raise_for_status()result = response.json()print(result["data"]["id"], result["data"]["brokerID"])Terminal window curl -X POST "$TIER0_BASE_URL/flow/create" \-H "content-type: application/json" \-H "x-api-key: $TIER0_API_KEY" \-d '{"flowName": "Manufacturing source flow","flowType": "SourceFlow","description": "Collects UNS source data from the plant.","template": "{}"}' -
/flow/listList flows and optionally filter by
flowTypeorkeyword. Use this to find the flowidbefore update or get operations.Terminal window const BASE_URL = process.env.TIER0_BASE_URL;const API_KEY = process.env.TIER0_API_KEY;const response = await fetch(`${BASE_URL}/flow/list`, {method: 'POST',headers: {'content-type': 'application/json','x-api-key': API_KEY,},body: JSON.stringify({flowType: 'SourceFlow',keyword: 'Manufacturing',}),});const result = await response.json();console.log(result.data.list);Terminal window import osimport requestsbase_url = os.environ["TIER0_BASE_URL"]api_key = os.environ["TIER0_API_KEY"]response = requests.post(f"{base_url}/flow/list",headers={"x-api-key": api_key},json={"flowType": "SourceFlow","keyword": "Manufacturing",},timeout=30,)response.raise_for_status()result = response.json()print(result["data"]["list"])Terminal window curl -X POST "$TIER0_BASE_URL/flow/list" \-H "content-type: application/json" \-H "x-api-key: $TIER0_API_KEY" \-d '{"flowType": "SourceFlow","keyword": "Manufacturing"}' -
/flow/updateUpdate a flow by
id. Send only the fields you want to change.Terminal window const BASE_URL = process.env.TIER0_BASE_URL;const API_KEY = process.env.TIER0_API_KEY;const flowId = 123;const response = await fetch(`${BASE_URL}/flow/update`, {method: 'POST',headers: {'content-type': 'application/json','x-api-key': API_KEY,},body: JSON.stringify({id: flowId,flowName: 'Manufacturing source flow v2',description: 'Updated source flow description.',isFavorite: 1,}),});const result = await response.json();console.log(result.data.success);Terminal window import osimport requestsbase_url = os.environ["TIER0_BASE_URL"]api_key = os.environ["TIER0_API_KEY"]flow_id = 123response = requests.post(f"{base_url}/flow/update",headers={"x-api-key": api_key},json={"id": flow_id,"flowName": "Manufacturing source flow v2","description": "Updated source flow description.","isFavorite": 1,},timeout=30,)response.raise_for_status()result = response.json()print(result["data"]["success"])Terminal window curl -X POST "$TIER0_BASE_URL/flow/update" \-H "content-type: application/json" \-H "x-api-key: $TIER0_API_KEY" \-d '{"id": 123,"flowName": "Manufacturing source flow v2","description": "Updated source flow description.","isFavorite": 1}' -
/flow/getGet one flow by
id.Terminal window const BASE_URL = process.env.TIER0_BASE_URL;const API_KEY = process.env.TIER0_API_KEY;const flowId = 123;const response = await fetch(`${BASE_URL}/flow/get`, {method: 'POST',headers: {'content-type': 'application/json','x-api-key': API_KEY,},body: JSON.stringify({ id: flowId }),});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"]flow_id = 123response = requests.post(f"{base_url}/flow/get",headers={"x-api-key": api_key},json={"id": flow_id},timeout=30,)response.raise_for_status()result = response.json()print(result["data"])Terminal window curl -X POST "$TIER0_BASE_URL/flow/get" \-H "content-type: application/json" \-H "x-api-key: $TIER0_API_KEY" \-d '{"id": 123}'
API reference
Section titled “API reference”- Build Apps on UNS — Build industrial applications with UNS data.
- Analyze UNS Data — Analyze UNS data with Marimo Notebook and Python.