-
Notifications
You must be signed in to change notification settings - Fork 1
added core sample #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rido-min
wants to merge
3
commits into
wickste:master
Choose a base branch
from
rido-min:ridosdk
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Worker"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net6.0-windows10.0.17763.0</TargetFramework> | ||
| <Nullable>disable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <UserSecretsId>dotnet-AssetTrackerDevice-FE8FBA84-5816-4675-B918-12C1B9B0838C</UserSecretsId> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" /> | ||
| <PackageReference Include="Rido.IoTClient" Version="0.0.1-pre" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Compile Update="dtmi_assettrackerdemo_xfassettrackert0-1.g.cs"> | ||
| <DependentUpon>XFAssetTracker.json</DependentUpon> | ||
| </Compile> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| using dtmi_assettrackerdemo; | ||
| using Rido.IoTClient; | ||
| using Rido.IoTClient.AzIoTHub; | ||
|
|
||
| namespace AssetTrackerDevice | ||
| { | ||
| public class DeviceRunner : BackgroundService | ||
| { | ||
| private readonly ILogger<DeviceRunner> _logger; | ||
| private readonly IConfiguration _configuration; | ||
|
|
||
| public DeviceRunner(ILogger<DeviceRunner> logger, IConfiguration configuration) | ||
| { | ||
| _logger = logger; | ||
| _configuration = configuration; | ||
| } | ||
|
|
||
| const int default_interval = 5; | ||
|
|
||
| protected override async Task ExecuteAsync(CancellationToken stoppingToken) | ||
| { | ||
| var locator = new Windows.Devices.Geolocation.Geolocator(); | ||
| var client = await xfassettrackert0.CreateAsync(_configuration.GetConnectionString("cs"), stoppingToken); | ||
|
|
||
| client.Command_Reboot.OnCmdDelegate = async (cmd) => | ||
| { | ||
| _logger.LogInformation("Command Reboot received"); | ||
| return await Task.FromResult(new Rido.IoTClient.EmptyCommandResponse()); | ||
| }; | ||
|
|
||
| client.Property_Interval.OnProperty_Updated = async p => | ||
| { | ||
| _logger.LogInformation($"Property Desired Prop received: {p.Name}: {p.Value} v {p.Version}"); | ||
| var ack = new PropertyAck<int>(p.Name) | ||
| { | ||
| Value = p.Value, | ||
| Status = 200, | ||
| Version = p.Version, | ||
| Description = "property accepted" | ||
| }; | ||
| client.Property_Interval.PropertyValue.Value = p.Value; | ||
| return await Task.FromResult(ack); | ||
| }; | ||
|
|
||
| await client.Property_Interval.InitPropertyAsync(client.InitialState, default_interval, stoppingToken); | ||
|
|
||
| client.Property_FrameworkVersion.PropertyValue = Environment.Version.ToString(); | ||
| client.Property_Manufacturer.PropertyValue = "Contoso"; | ||
| client.Property_SDKVersion.PropertyValue = (typeof(IoTHubPnPClient).Assembly.GetName().Version.ToString()); | ||
|
|
||
| await client.ReportPropertyAsync(client.AllReadOnlyProperties, stoppingToken); | ||
|
|
||
| _logger.LogInformation("Loop started with interval: " + client.Property_Interval.PropertyValue.Value); | ||
| while (!stoppingToken.IsCancellationRequested) | ||
| { | ||
| var location = await locator.GetGeopositionAsync(); | ||
| await client.Telemetry_Location.SendTelemetryAsync(new Location | ||
| { | ||
| lat = location.Coordinate.Latitude, | ||
| lon = location.Coordinate.Longitude, | ||
| alt = location.Coordinate.Altitude.Value | ||
|
|
||
| }); | ||
| _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); | ||
| await Task.Delay(client.Property_Interval.PropertyValue.Value * 1000, stoppingToken); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| using AssetTrackerDevice; | ||
|
|
||
| IHost host = Host.CreateDefaultBuilder(args) | ||
| .ConfigureServices(services => | ||
| { | ||
| services.AddHostedService<DeviceRunner>(); | ||
| }) | ||
| .Build(); | ||
|
|
||
| await host.RunAsync(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "profiles": { | ||
| "AssetTrackerDevice": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "environmentVariables": { | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ConnectionStrings__cs": "IdScope=0ne0047D00B;DeviceId=rido-tracker-01;SharedAccessKey=81gPeOIot+L2cwwOwgnaRBuzqpzihpKurt2nGmp28YU=" | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| [ | ||
| { | ||
| "@id": "dtmi:assetTrackerDemo:XFAssetTrackert0;1", | ||
| "@type": "Interface", | ||
| "contents": [ | ||
| { | ||
| "@id": "dtmi:assetTrackerDemo:XFAssetTrackert0:Location;1", | ||
| "@type": [ | ||
| "Telemetry", | ||
| "Location" | ||
| ], | ||
| "displayName": { | ||
| "en": "Location" | ||
| }, | ||
| "name": "Location", | ||
| "schema": "geopoint" | ||
| }, | ||
| { | ||
| "@id": "dtmi:assetTrackerDemo:XFAssetTrackert0:Interval;1", | ||
| "@type": [ | ||
| "Property", | ||
| "TimeSpan" | ||
| ], | ||
| "displayName": { | ||
| "en": "Interval" | ||
| }, | ||
| "name": "Interval", | ||
| "schema": "integer", | ||
| "unit": "second", | ||
| "writable": true | ||
| }, | ||
| { | ||
| "@id": "dtmi:assetTrackerDemo:XFAssetTrackert0:Reboot;1", | ||
| "@type": "Command", | ||
| "commandType": "synchronous", | ||
| "displayName": { | ||
| "en": "Reboot" | ||
| }, | ||
| "name": "Reboot" | ||
| }, | ||
| { | ||
| "@id": "dtmi:assetTrackerDemo:XFAssetTrackert0:FrameworkVersion;1", | ||
| "@type": "Property", | ||
| "displayName": { | ||
| "en": "FrameworkVersion" | ||
| }, | ||
| "name": "FrameworkVersion", | ||
| "schema": "string", | ||
| "writable": false | ||
| }, | ||
| { | ||
| "@id": "dtmi:assetTrackerDemo:XFAssetTrackert0:SDKVersion;1", | ||
| "@type": "Property", | ||
| "displayName": { | ||
| "en": "SDKVersion" | ||
| }, | ||
| "name": "SDKVersion", | ||
| "schema": "string", | ||
| "writable": false | ||
| }, | ||
| { | ||
| "@id": "dtmi:assetTrackerDemo:XFAssetTrackert0:Manufacturer;1", | ||
| "@type": "Property", | ||
| "displayName": { | ||
| "en": "Manufacturer" | ||
| }, | ||
| "name": "Manufacturer", | ||
| "schema": "string", | ||
| "writable": false | ||
| } | ||
| ], | ||
| "displayName": { | ||
| "en": "XFAssetTracker" | ||
| }, | ||
| "@context": [ | ||
| "dtmi:iotcentral:context;2", | ||
| "dtmi:dtdl:context;2" | ||
| ] | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.Hosting.Lifetime": "Information" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.Hosting.Lifetime": "Information" | ||
| } | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
AssetTrackerDevice/dtmi_assettrackerdemo_xfassettrackert0-1.g.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // <auto-generated /> | ||
|
|
||
| using MQTTnet.Client; | ||
| using Rido.IoTClient; | ||
| using Rido.IoTClient.AzIoTHub; | ||
| using Rido.IoTClient.AzIoTHub.TopicBindings; | ||
| using System.Reflection.Metadata; | ||
|
|
||
| namespace dtmi_assettrackerdemo | ||
| { | ||
| public class xfassettrackert0 : IoTHubPnPClient | ||
| { | ||
| const string modelId = "dtmi:assetTrackerDemo:XFAssetTrackert0;1"; | ||
|
|
||
| public Telemetry<Location> Telemetry_Location; | ||
| public WritableProperty<int> Property_Interval; | ||
| public Command<EmptyCommandRequest, EmptyCommandResponse> Command_Reboot; | ||
| public ReadOnlyProperty<string> Property_FrameworkVersion; | ||
| public ReadOnlyProperty<string> Property_SDKVersion; | ||
| public ReadOnlyProperty<string> Property_Manufacturer; | ||
|
|
||
| public xfassettrackert0(IMqttClient c) : base(c) | ||
| { | ||
| Property_Interval = new WritableProperty<int>(c, "Interval"); | ||
| Telemetry_Location = new Telemetry<Location>(c, "Location"); | ||
| Command_Reboot = new Command<EmptyCommandRequest, EmptyCommandResponse>(c, "Reboot"); | ||
| Property_FrameworkVersion = new ReadOnlyProperty<string>(c, "FrameworkVersion"); | ||
| Property_SDKVersion = new ReadOnlyProperty<string>(c, "SDKVersion"); | ||
| Property_Manufacturer = new ReadOnlyProperty<string>(c, "Manufacturer"); | ||
| } | ||
|
|
||
| public static async Task<xfassettrackert0> CreateAsync(string connectionString, CancellationToken cancellationToken) | ||
| { | ||
| var cs = new ConnectionSettings(connectionString) { ModelId = modelId }; | ||
| var client = new xfassettrackert0(await IoTHubConnectionFactory.CreateAsync(cs, cancellationToken)) { ConnectionSettings = cs }; | ||
| client.InitialState = await client.GetTwinAsync(cancellationToken); | ||
| return client; | ||
| } | ||
|
|
||
| public Dictionary<string, object> AllReadOnlyProperties => new Dictionary<string, object>() | ||
| { | ||
| { Property_FrameworkVersion.Name, Property_FrameworkVersion.PropertyValue }, | ||
| { Property_SDKVersion.Name, Property_SDKVersion.PropertyValue }, | ||
| { Property_Manufacturer.Name, Property_Manufacturer.PropertyValue } | ||
| }; | ||
|
|
||
|
|
||
| } | ||
|
|
||
| public struct Location | ||
| { | ||
| public double lat { get; set; } | ||
| public double lon { get; set; } | ||
| public double alt { get; set; } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wickste would this work?
we might need a same approach to send multiple telemetries in one message