Skip to content

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.

On the Edge tab in Tier0, create a new credential and make a note of it.

  1. Install and open MQTTX.
  2. 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>"
    }
  1. Make sure the client status is normal.
  2. Copy a UNS model topic and publish a message to it through the client.

Use the REST API to operate on UNS data.

API keys are from Settings > API Keys. Depend on different account type, allowed key types are different.

  • Service Key: Can only be created by Admin and Owner.
  • Personal Key: Can be created by anyone, and the permission scope is the same as that of the account.
  • /uns/create

    Create UNS path or topic. Use namespace to define the 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);
  • /uns/read

    Read the latest value and metadata for one or more 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);
  • /uns/update

    Update a UNS node by path. Use updateMask to specify which fields should change.

    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);
  • /uns/delete

    Delete one or more UNS models. Use hard_delete: false to move models to the recycle bin.

    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);