Giter Site home page Giter Site logo

digital-twins-samples's Introduction

page_type languages products name description urlFragment
sample
csharp
powershell
azure-digital-twins
Azure Digital Twins end-to-end samples
Contains end-to-end project samples for the latest version of Azure Digital Twins.
digital-twins-samples

End-to-end samples for Azure Digital Twins

Azure Digital Twins is a developer platform for next-generation IoT solutions that lets you create, run, and manage digital representations of your business environment, securely and efficiently in the cloud. With Azure Digital Twins, creating live operational state representations is quick and cost-effective, and digital representations stay current with real-time data from IoT and other data sources.

For more information about Azure Digital Twins and its key concepts, see the Azure Digital Twins documentation.

Purpose

This project contains 2 samples for working with Azure Digital Twins:

  • A building scenario sample written in .NET. Can be used to set up and simulate a full end-to-end scenario with Azure Digital Twins
  • A deployment script written in PowerShell. Can be used to deploy and set AAD permissions for an Azure Digital Twins instance

Setup

Get the samples by downloading this repository as a ZIP file to your machine.

Sample project contents

The sample repo contains:

File/folder Description
AdtSampleApp For the building scenario. Contains a sample client application built to interact with Azure Digital Twins, as well as an Azure Functions app with two functions (ProcessDTRoutedData and ProcessHubToDTEvents) that are used to route data between Azure Digital Twins and other external services.
DeviceSimulator For the building scenario. Simulator for a that generates telemetry events. The simulated device is a thermostat that sends temperature telemetry every ~5 seconds.
scripts For the deployment script. Contains deploy.ps1.

Prerequisites

For the building scenario:

These samples were developed and expected to run in Visual Studio 2019. Ensure you have installed Visual Studio 2019 version 16.5.1XXX or later on your development machine. If you have an older version installed already, you can open the Visual Studio Installer app on your machine and follow the prompts to update your installation.

For the deployment script:

None

Instructions

The instructions for working with these samples are included in the Azure Digital Twins documentation.

Building scenario:

There are two possible sets of instructions for working with this sample.

Deployment script:

Instructions for running the script, and manual description of the automated steps within the script, are found in How-to: Create an Azure Digital Twins instance.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

digital-twins-samples's People

Contributors

alexkarcher-msft avatar andyatwork avatar baanders avatar bikamani avatar cschormann avatar danhellem avatar deepikasadahiro avatar dimiboi avatar drwill-ms avatar jmayrbaeurl avatar microsoft-github-operations[bot] avatar microsoftopensource avatar montgomp avatar philmea avatar rinisbet avatar satya-kolluri avatar v-lakast avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

digital-twins-samples's Issues

The previously published function cannot be found

In the doc of Azure Digital Twin about "Tutorial: Build out an end-to-end solution", I have a problem while "Connect the IoT hub to the Azure function".In the window of "Select Azure Function", the previously published function cannot be found.
image

Twin Graph - Querying further than direct relationships (such as "grandchildren")

Hi,

In the context where you would be managing multiple buildings, with multiple floors (ideally with multiple zones) and then say desk and rooms, each with some sensors...
so
Buildings->Floors(->Zones?)->Desks or Rooms (aka Space?)->sensors

Is there a way to query for all Spaces in only that building with occupancy is true for example, or all Sensors with battery is less than 20% without having to query children, and then children of children?

While I get the idea of optimising the graph for querying, so that we only have 1 level of relationship to query (e.g. "any child of this parent" or "any with contains relationship for a given TwinId"), I don't suppose there should be additional relationships created just for that purpose or should there please? (i.e. so that a desk is a child of zone, floor and building)

Thank you for your recommendations

Temperature Update

After follow instruction on 'Tutorial: Connect an end-to-end solution', at last stage I run 'ObserveProperties thermostat67 Temperature room21 Temperature' but only get an update on thermostat67 only while room21 got 0 temperature. Base on my understanding, the temperature for room21 is will updated to match the updates to thermostat67. Can someone explains on this? below is my console result.

temperature

Setup (with SetupBuildingScenario) fails intermittently due to eventually consistency of datastore

Initializing a new ADT instance using SetupBuildingScenario can sometimes fail because of the eventual consistency in the backing datastore.

I tried a few times today and saw different errors at different points:

  1. sometimes, it claims that fields on the twin are not valid according to the model, despite the model having them (it seems the model was created, but not yet made available by backend yet so it thought the fields didn't exist)
  2. other times, the initial twin creation was successful but creating the relationships failed, claiming the twins did not exist yet (despite just having been created).

In either case, if I captured the net-traces using tools like mitmproxy, re-running the same REST call a few seconds later worked.

I suggest the sample introduce small delays between model creation, twin creation, and relationship creation to avoid this.

command need to be replaced

Hi , in Create Azure function step the command need to be replaced with this as the current command will fail

az functionapp create --consumption-plan-location eastus --name $twinupdatefunctionname --os-type Windows --resource-group adtholrg --runtime dotnet --functions-version 3 --storage-account adthol624storage

"Subdomain not found"

Hi everyone,

when running the SampleClientApp all I get is

Status: 404 (Not Found)

Content:
{ "statusCode": 404, "message": "Sub-domain not found." }

In fiddler I see the url called was
https://xyz.api.weu.digitaltwins.azure.net/models?api-version=2020-10-31

The azure digital twins explorer works fine with the same url. Any idea what is going on?

(NotFound) Error retrieving function. for az functionapp show

After seemingly successfull zip deployment of functions from local /publish.zip

az functionapp deployment source config-zip --resource-group MyResourceGroupName --name myfunctionappname --src "./publish.zip"
returning:

`Getting scm site credentials for zip deployment
Starting zip deployment. This operation can take a while to complete ...
Deployment endpoint responded with status code 202

{
"active": false,
"author": "N/A",
"author_email": "N/A",
"complete": true,
"deployer": "ZipDeploy",
"end_time": "2022-11-23T15:09:03.5679832Z",
"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"is_readonly": true,
"is_temp": false,
"last_success_end_time": "2022-11-23T15:09:03.5679832Z",
"log_url": "https://myfunctionappname.scm.azurewebsites.net/api/deployments/latest/log",
"message": "Created via a push deployment",
"progress": "",
"provisioningState": "Succeeded",
"received_time": "2022-11-23T15:08:54.3218891Z",
"site_name": "myfunctionappname",
"start_time": "2022-11-23T15:08:55.931373Z",
"status": 4,
"status_text": "",
"url": "https://myfunctionappname.scm.azurewebsites.net/api/deployments/latest"
}

I tried to run the commands to verify the success:

az functionapp function show --resource-group MyResourceGroupName --name myfunctionappname --function-name ProcessDTRoutedData

which is returning:

(NotFound) Error retrieving function. Code: NotFound Message: Error retrieving function.
I also tried to verify in the azure portal, but the functions are not listed there either. Not sure what to do next or how to debug.

`

Fail to deploy the published functions (zip file) to my Azure function app

Command:
az functionapp deployment source config-zip --resource-group myResourceGroup --name myFunctionApp --src "./publish.zip"

Error output:
Getting scm site credentials for zip deployment
The command failed with an unexpected error. Here is the traceback:
'str' object has no attribute 'value'
Traceback (most recent call last):
File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 231, in invoke
cmd_result = self.invocation.execute(args)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 657, in execute
raise ex
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 720, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 691, in _run_job
result = cmd_copy(params)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 328, in call
return self.handler(*args, **kwargs)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
return op(**command_args)
File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/appservice/custom.py", line 405, in enable_zip_deploy_functionapp
return enable_zip_deploy(cmd, resource_group_name, name, src, timeout, slot)
File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/appservice/custom.py", line 417, in enable_zip_deploy
scm_url = _get_scm_url(cmd, resource_group_name, name, slot)
File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/appservice/custom.py", line 1948, in _get_scm_url
webapp = show_webapp(cmd, resource_group_name, name, slot=slot)
File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/appservice/custom.py", line 607, in show_webapp
return _show_app(cmd, resource_group_name, name, "webapp", slot)
File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/appservice/custom.py", line 736, in _show_app
"Unable to find {} '{}', in RG '{}'".format(cmd_app_type.value, name, resource_group_name),
AttributeError: 'str' object has no attribute 'value'
To open an issue, please run: 'az feedback'

I didn't change any code in the AdtSampleApp\SampleFunctionsApp, how to fix this error? Thank you very much.

The JSON value could not be converted to System.DateTimeOffset. Path: $.lastUpdateTime

Following the tutorial https://docs.microsoft.com/en-us/azure/digital-twins/tutorial-end-to-end#get-started-with-the-building-scenario

I created the ADT instance, the AzFunction and configured the hub, I can see events flowing, but when I tried to query with the sample app I got the exception below:

System.Text.Json.JsonException
  HResult=0x80131500
  Message=The JSON value could not be converted to System.DateTimeOffset. Path: $.lastUpdateTime | LineNumber: 0 | BytePositionInLine: 39. Path: $.$metadata | LineNumber: 0 | BytePositionInLine: 287.
  Source=System.Text.Json
  StackTrace:
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& readStack, Utf8JsonReader& reader, Exception ex)
   at System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack)
   at System.Text.Json.JsonSerializer.ReadValueCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack)
   at System.Text.Json.JsonSerializer.ReadValueCore(Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](Utf8JsonReader& reader, JsonSerializerOptions options)
   at Azure.DigitalTwins.Core.DigitalTwinMetadataJsonConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.JsonPropertyInfoNotNullable`4.OnRead(ReadStack& state, Utf8JsonReader& reader)
   at System.Text.Json.JsonPropertyInfo.Read(JsonTokenType tokenType, ReadStack& state, Utf8JsonReader& reader)
   at System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack)
   at System.Text.Json.JsonSerializer.ReadCore(Type returnType, JsonSerializerOptions options, Utf8JsonReader& reader)
   at System.Text.Json.JsonSerializer.ParseCore(ReadOnlySpan`1 utf8Json, Type returnType, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.Deserialize(ReadOnlySpan`1 utf8Json, Type returnType, JsonSerializerOptions options)
   at Azure.Core.Serialization.JsonObjectSerializer.Deserialize(Stream stream, Type returnType, CancellationToken cancellationToken)
   at Azure.DigitalTwins.Core.DigitalTwinsClient.GetDigitalTwin[T](String digitalTwinId, CancellationToken cancellationToken)
   at SampleClientApp.CommandLoop.CheckState(Object state) in C:\code\digital-twins-samples\AdtSampleApp\SampleClientApp\CommandLoop.cs:line 1084

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
FormatException: The JSON value is not in a supported DateTimeOffset format.

When I inspected the twin I found there are two different dateformats.

{
  "result": [
    {
      "$dtId": "thermostat67",
      "$etag": "W/\"922ec797-c384-4e82-9d32-a9651874cca6\"",
      "$metadata": {
        "$model": "dtmi:contosocom:DigitalTwins:Thermostat;1",
        "ComfortIndex": {
          "lastUpdateTime": "11/24/2020 22:12:17"
        },
        "DisplayName": {
          "lastUpdateTime": "11/24/2020 22:12:17"
        },
        "FirmwareVersion": {
          "lastUpdateTime": "11/24/2020 22:12:17"
        },
        "Location": {
          "lastUpdateTime": "11/24/2020 22:12:17"
        },
        "Temperature": {
          "lastUpdateTime": "2020-11-25T01:15:17.4251003Z"
        }
      },
      "ComfortIndex": 0,
      "DisplayName": "Thermostat 67",
      "FirmwareVersion": "1.3.9",
      "Location": "Puget Sound",
      "Temperature": 69.3982215479008
    },
    {
      "$dtId": "floor1",
      "$etag": "W/\"2ec577ac-c3e5-43fa-93a0-a19305589b79\"",
      "$metadata": {
        "$model": "dtmi:contosocom:DigitalTwins:Space;1",
        "ComfortIndex": {
          "lastUpdateTime": "2020-11-24T22:12:16.6127404Z"
        },
        "DisplayName": {
          "lastUpdateTime": "2020-11-24T22:12:16.6127404Z"
        },
        "Location": {
          "lastUpdateTime": "2020-11-24T22:12:16.6127404Z"
        },
        "Temperature": {
          "lastUpdateTime": "2020-11-24T22:12:16.6127404Z"
        }
      },
      "ComfortIndex": 0,
      "DisplayName": "Floor 1",
      "Location": "Puget Sound",
      "Temperature": 0
    },
    {
      "$dtId": "room21",
      "$etag": "W/\"8cf788d9-b775-4912-8321-d7f671e3e1fa\"",
      "$metadata": {
        "$model": "dtmi:contosocom:DigitalTwins:Space;1",
        "ComfortIndex": {
          "lastUpdateTime": "2020-11-24T22:12:16.9040618Z"
        },
        "DisplayName": {
          "lastUpdateTime": "2020-11-24T22:12:16.9040618Z"
        },
        "Location": {
          "lastUpdateTime": "2020-11-24T22:12:16.9040618Z"
        },
        "Temperature": {
          "lastUpdateTime": "2020-11-24T22:12:16.9040618Z"
        }
      },
      "ComfortIndex": 0,
      "DisplayName": "Room 21",
      "Location": "Puget Sound",
      "Temperature": 0
    }
  ]
}

403 errors when authenticating with service principle with Azure Functions

Hi Team, I have a sample functions app (dotnet-isolated) and I am using an app (client id, client secret) to authenticate to a twin instance. When I run my function locally it works just fine but once deployed it just fails with a 403 error. I have verified that my client has the required access control as per this doc.

here is the sample code I use for authentication

string adtInstanceUrl = Environment.GetEnvironmentVariable("clientConfig:digitalTwins:instanceUrl");
string tenantId = Environment.GetEnvironmentVariable("clientConfig:servicePrinciple:tenantId");
string clientId = Environment.GetEnvironmentVariable("clientConfig.servicePrinciple.clientId");
string clientSecret = Environment.GetEnvironmentVariable("clientConfig:servicePrinciple:clientSecret");

Environment.SetEnvironmentVariable("AZURE_CLIENT_SECRET", clientSecret);
Environment.SetEnvironmentVariable("AZURE_CLIENT_ID", clientId);
Environment.SetEnvironmentVariable("AZURE_TENANT_ID", tenantId);

TokenCredential tokenCredential = new DefaultAzureCredential();

var client = new DigitalTwinsClient(new Uri(adtInstanceUrl),
                tokenCredential);

TwinsFunction name issue

Hi, all,
In the following command, use 'TwinsFunction' instead of 'twinsfunction', to make sure the function names are matched.
$function=$(az functionapp function show -n $telemetryfunctionname -g $rgname --function-name twinsfunction --query id -o tsv)

Error Creating Models From Directory

It seems to be currently impossible to easily upload all models from REC into an ADT resource instance while using the sample at https://github.com/Azure-Samples/digital-twins-samples/tree/master/AdtSampleApp/SampleClientApp.

First of all it seems impossible to upload everything at once due to data limits (which is fine). This is fixable by first uploading the role.json file and then every child directory of /Models/. However, this crashes on the directories /Capability, /Colletion and /Space (not sure why, the CLI says "Validated JSON for all files - now validating DTDL" but then it crashes with "Invalid command. Please type 'help' for more information".

I can then use the CreateModels command to create separate models from these directories, but it crashes when using the LoadModelsFromDirectory command.

Is there any way to overcome this, and if not; will it come in the future?

Error while creating the zip file to deploy onto Azure Functions

Hello,

I am currently trying to complete the tutorial and while trying to run the dotnet publish -c Release command it throws up an error saying the 'Microsoft.AspNetCore.Authentication.Abstractions.dll' cannot be found. I know this file exists because I can see it in the directory. I tried adding it into the .csproj file to see if it would help but it still gives me the same erorr. How would I go ahead and solve this error?

Thanks in advance!

PS: I have not changed any of the existing code

command 'az timeseriesinsights'= 'CommandNotFoundError: 'timeseriesinsights' is misspelled or not recognized by the system.'

On page: https://docs.microsoft.com/en-us/learn/modules/develop-with-azure-digital-twins/route-output-from-azure-digital-twins-to-downstream-services/6-exercise-visualize-data-time-series-insights

It has you run the command

$storage="adtholtsitorage"+(get-random -maximum 10000)
$tsiname=$random+"tsienv"
az storage account create -g $rgname -n $storage --https-only -l $location
$key=$(az storage account keys list -g $rgname -n $storage --query [0].value --output tsv)
az timeseriesinsights environment longterm create -g $rgname -n $tsiname --location $location --sku-name L1 --sku-capacity 1 --data-retention 7 --time-series-id-properties '$dtId' --storage-account-name $storage --storage-management-key $key -l $location

but az timeseriesinsights does not seem to work.

Strict Transport Security: REDACTED

After setting up an instance of Azure Digital Twins and an app registration, I then configured the SampleClientApp solution, built it, and ran it.

After running it I typed CreateModels Room Floor. The result was a service request failed with a 403 forbidden error (output shown below).

Please enter a command or 'help'. Commands are not case sensitive
CreateModels Room Floor
Reading from F:\dev\dt\Azure_Digital_Twins_samples\AdtSampleApp\SampleClientApp\bin\Debug\netcoreapp3.1\Models
Submitting models: Room.json, Floor.json...

Response 403: Service request failed.
Status: 403 (Forbidden)

Headers:
Strict-Transport-Security: REDACTED
Date: Mon, 06 Jul 2020 00:40:40 GMT
Content-Length: 0

The instructions I followed to get authentication setup are located at how to authenticate a client.

The output of az version is below:

{
  "azure-cli": "2.8.0",
  "azure-cli-command-modules-nspkg": "2.0.3",
  "azure-cli-core": "2.8.0",
  "azure-cli-nspkg": "3.0.4",
  "azure-cli-telemetry": "1.0.4",
  "extensions": {
    "azure-iot": "0.9.6"
  }
}

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.