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
- Graph‑based models: Define entities (digital twins) and their relationships.
- Live state sync: Real‑time telemetry updates from devices.
- Query language (DTDL): Query and manipulate twin data using a JSON‑based definition.
- Webhooks & APIs: Integrate with Azure Functions, Logic Apps, and custom services.
Getting Started
- Create a Digital Twins instance in the Azure portal.
- Define your model using Digital Twins Definition Language (DTDL).
- Upload the model to your instance.
- 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);