Microsoft Docs – Azure IoT

Azure IoT Digital Twins

Azure IoT Digital Twins provides a live execution environment for modeling the relationships and interactions between people, places, and devices. Build rich, connected experiences by creating a digital replica of real-world environments.

Key Features

Getting Started

  1. Create a Digital Twins instance in the Azure portal.
  2. Define your model using Digital Twins Definition Language (DTDL).
  3. Upload the model to your instance.
  4. Connect devices and start sending telemetry.

Sample DTDL Model

{
  "@id": "dtmi:example:Room;1",
  "@type": "Interface",
  "displayName": "Room",
  "contents": [
    {
      "@type": "Property",
      "name": "temperature",
      "schema": "double",
      "unit": "degreeCelsius"
    },
    {
      "@type": "Telemetry",
      "name": "occupancy",
      "schema": "integer"
    },
    {
      "@type": "Component",
      "name": "hvac",
      "schema": "dtmi:example:HVAC;1"
    }
  ]
}

Code Sample – Create a Twin with Azure SDK for JavaScript

import { DigitalTwinsClient } from "@azure/digital-twins-core";
import { DefaultAzureCredential } from "@azure/identity";

const endpoint = "https://YOUR_TWIN_INSTANCE.api.wus2.digitaltwins.azure.net";
const credential = new DefaultAzureCredential();
const client = new DigitalTwinsClient(endpoint, credential);

async function createRoomTwin() {
    const twinId = "room-01";
    const twinData = {
        "$metadata": {
            "$model": "dtmi:example:Room;1"
        },
        "temperature": 22.5,
        "occupancy": 3
    };
    await client.createOrReplaceDigitalTwin(twinId, twinData);
    console.log(`Twin ${twinId} created`);
}

createRoomTwin().catch(console.error);

Related Articles