Coder Social home page Coder Social logo

azure-digital-twins-demos's Introduction

Azure Digital Twins demos

Azure Digital Twins demos

Updates From Event Hub to Azure Digital Twins

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

Using static structure

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

Azure Digital Twin Explorer showing these twins

Using dynamic structure

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'

Azure Digital Twin Explorer showing these generic twins

Deployment to Azure

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 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 either ByID or ByChild
        • ByID searches by digital twin id $dtId. Found twin is directly updated.
        • ByChild searches parent digital twin by equipmentID, finds all children twins by ID and updates child twins OPCUANodeValue property.
      • EventHubName e.g., adt
      • EventHubConnectionString e.g., Endpoint=sb://<your-eventhub-instance>.servicebus.windows.net/;SharedAccessKeyName=...
    • Enable System Assigned Managed Identity
  • 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 and FUNCTIONS_EXTENSION_VERSION=~4

Links

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

azure-digital-twins-demos's People

Contributors

jannemattila avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.