azure-samples / digital-twins-samples Goto Github PK
View Code? Open in Web Editor NEWAzure Digital Twins building scenario sample code
License: MIT License
Azure Digital Twins building scenario sample code
License: MIT License
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
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);
the below function got an error when I try to build it.
[FunctionName("ProcessHubToDTEvents")]
public async void Run([EventGridTrigger]EventGridEvent eventGridEvent, ILogger log)
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.
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.
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
Please see my PR:
#85
I updated this method from client.UpdateDigitalTwinAsync to client.PublishTelemetryAsync as this is Telemetry data.
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
}
]
}
One important aspect of ADT is the integration with IoT devices.
I followed the e2e tutorial and I was expecting to see a DeviceSimulator using the same DTDL model, but seems the device is not using PnP at all, eg in the connection it's not sending the model id https://github.com/Azure-Samples/digital-twins-samples/blob/master/DeviceSimulator/DeviceSimulator/AzureIoTHub.cs#L45
/cc @drwill-ms
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?
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:
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.
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.
`
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)
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?
Method 'object convertStringToType(string schema, string val)' in CommandLoop.cs is missing case statement for schema type float, resulting in a server error
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"
}
}
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
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.