Azure Digital Twins demos
sequenceDiagram
Note right of On-premises App: See JSON<br/>payload below
On-premises App->>+Event Hub: Send event
Azure Functions-->>+Event Hub: Receive event
Note right of Azure Functions: Map fields from<br/>payload to digital<br/>twin model definitions
Azure Functions->>Azure Digital Twins: Update digital twin
You can find example models in car-demo folder for Car
and Tyre
.
Example payloads if ProcessingLogic
is set to ByID
:
{
"_id": "Matiz",
"carStatus": "Moving",
"speed": 121.8
}
{
"_id": "LeftFront",
"tyreStatus": "OK",
"pressure": 2.3
}
Note: _id
is identifier of the digital twin.
These payloads are picked by AzureDigitalTwinsUpdaterFunc which then processes mapping of incoming data to the target digital twin.
Note: Only Property
types in the model are updated by the updater.
You can send events to Event Hub using examples.ps1 script.
Example search in Azure Digital Twin Explorer to find all these twins:
SELECT * FROM digitaltwins WHERE STARTSWITH($metadata.$model, 'dtmi:com:janneexample')
You can find example models in ISA95 folder for OPCUANodeset
and OPCUANodeInteger
.
Using these models, you can create dynamic structure to represent values in child twins.
Example payloads if ProcessingLogic
is set to ByChild
:
{
"_id": "myeq123",
"MyValue1": 8,
"MyValue2": 12
}
SELECT T, CT FROM digitaltwins T JOIN CT RELATED T.contains WHERE T.$dtId = '50001'
Key deployment steps:
- Create Azure Digital Twin
- Load example models into it from car-demo
- Create Event Hub namespace
- Create
adt
Event Hub and copy connection string
- Create
- Create Azure Functions App
- App Settings to Function App
ADTOptions__ADTInstanceUrl
e.g.,https://<your-adt-instance>.api.neu.digitaltwins.azure.net/
ADTOptions__IDFieldName
e.g.,_id
ADTOptions__ProcessingLogic
eitherByID
orByChild
ByID
searches by digital twin id$dtId
. Found twin is directly updated.ByChild
searches parent digital twin byequipmentID
, finds all children twins byID
and updates child twinsOPCUANodeValue
property.
EventHubName
e.g.,adt
EventHubConnectionString
e.g.,Endpoint=sb://<your-eventhub-instance>.servicebus.windows.net/;SharedAccessKeyName=...
- Enable System Assigned Managed Identity
- App Settings to Function App
- Add Role Assignment:
Azure Digital Twins Data Owner
role to the managed identity of Azure Functions App - Deploy using Visual Studio to Azure Functions app
- Visual Studio will validate that settings in Azure Function App are correct e.g.,
FUNCTIONS_WORKER_RUNTIME=dotnet-isolated
andFUNCTIONS_EXTENSION_VERSION=~4
- Visual Studio will validate that settings in Azure Function App are correct e.g.,
Azure Digital Twins getting started samples
Azure Digital Twins APIs and SDKs
Learn about twin models and how to define them in Azure Digital Twins