-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* squash big refactor * clean TwinInitializer * review tests * add payload sample * add avro * add memmon proto * sync with ux * upd links for ux
- Loading branch information
Showing
189 changed files
with
3,427 additions
and
2,718 deletions.
There are no files selected for viewing
This file contains 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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,35 @@ | ||
using MQTTnet.Client; | ||
using MQTTnet.Extensions.MultiCloud; | ||
using MQTTnet.Extensions.MultiCloud.AzureIoTClient.TopicBindings; | ||
using MQTTnet.Extensions.MultiCloud.AzureIoTClient.Untyped; | ||
using MQTTnet.Extensions.MultiCloud.BrokerIoTClient.Telemetry; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace iot_device | ||
{ | ||
internal class ClientHub | ||
{ | ||
TwinRequestResponseBinder rr; | ||
|
||
public ITelemetry<double> Temperature; | ||
public IReadOnlyProperty<string> SdkInfo; | ||
public ICommand<string, string> Echo; | ||
public IWritableProperty<int> Interval; | ||
|
||
public ClientHub(IMqttClient c) | ||
{ | ||
rr = new TwinRequestResponseBinder(c); | ||
Temperature = new HubTelemetryUTF8Json<double>(c, "temp"); | ||
SdkInfo = new HubReadOnlyPropertyUTFJson<string>(c, "sdkInfo"); | ||
Echo = new HubCommandUTF8Json<string, string>(c, "echo"); | ||
Interval = new HubWritablePropertyUTFJson<int>(c, "interval"); | ||
} | ||
|
||
internal async Task<string> GetTwinAsync(CancellationToken cancellationToken = default) | ||
=> await rr.GetTwinAsync(cancellationToken); | ||
} | ||
} |
This file contains 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,21 @@ | ||
using MQTTnet.Client; | ||
using MQTTnet.Extensions.MultiCloud; | ||
using MQTTnet.Extensions.MultiCloud.BrokerIoTClient.Command; | ||
using MQTTnet.Extensions.MultiCloud.BrokerIoTClient.ReadOnlyProperty; | ||
using MQTTnet.Extensions.MultiCloud.BrokerIoTClient.Telemetry; | ||
|
||
namespace iot_device; | ||
|
||
internal class ClientMsgPack | ||
{ | ||
public ITelemetry<double> Temperature; | ||
public IReadOnlyProperty<string> SdkInfo; | ||
public ICommand<int, string> EchoRepeater; | ||
|
||
public ClientMsgPack(IMqttClient c) | ||
{ | ||
Temperature = new TelemetryMsgPack<double>(c, "temperature"); | ||
SdkInfo = new ReadOnlyPropertyMessagePack<string>(c, "sdkInfo"); | ||
EchoRepeater = new CommandMsgPack<int, string>(c, "echoRepeater"); | ||
} | ||
} |
This file contains 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,25 @@ | ||
using device_template_protos; | ||
using MQTTnet.Client; | ||
using MQTTnet.Extensions.MultiCloud; | ||
using MQTTnet.Extensions.MultiCloud.BrokerIoTClient.Command; | ||
using MQTTnet.Extensions.MultiCloud.BrokerIoTClient.ReadOnlyProperty; | ||
using MQTTnet.Extensions.MultiCloud.BrokerIoTClient.Telemetry; | ||
using MQTTnet.Extensions.MultiCloud.BrokerIoTClient.WritableProperty; | ||
|
||
namespace iot_device; | ||
|
||
internal class ClientProtobuff | ||
{ | ||
public ITelemetry<Telemetries> Temperature; | ||
public IReadOnlyProperty<Properties> SdkInfo; | ||
public ICommand<echoRequest, echoResponse> Echo; | ||
public IWritableProperty<Properties, ack> Interval; | ||
|
||
public ClientProtobuff(IMqttClient c) | ||
{ | ||
Temperature = new TelemetryProtobuff<Telemetries>(c, "temp"); | ||
SdkInfo = new ReadOnlyPropertyProtobuff<Properties>(c, "sdkInfo"); | ||
Echo = new CommandProtobuff<echoRequest, echoResponse>(c, "echo", echoRequest.Parser); | ||
Interval = new WritablePropertyProtobuff<Properties, ack>(c, "interval", Properties.Parser); | ||
} | ||
} |
This file contains 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,24 @@ | ||
using MQTTnet.Client; | ||
using MQTTnet.Extensions.MultiCloud; | ||
using MQTTnet.Extensions.MultiCloud.BrokerIoTClient.Command; | ||
using MQTTnet.Extensions.MultiCloud.BrokerIoTClient.ReadOnlyProperty; | ||
using MQTTnet.Extensions.MultiCloud.BrokerIoTClient.Telemetry; | ||
using MQTTnet.Extensions.MultiCloud.BrokerIoTClient.WritableProperty; | ||
|
||
namespace iot_device; | ||
|
||
internal class ClientUTF8Json | ||
{ | ||
public ITelemetry<double> Temperature; | ||
public IReadOnlyProperty<string> SdkInfo; | ||
public ICommand<string, string> Echo; | ||
public IWritableProperty<int> Interval; | ||
|
||
public ClientUTF8Json(IMqttClient c) | ||
{ | ||
Temperature = new TelemetryUTF8Json<double>(c, "temp"); | ||
SdkInfo = new ReadOnlyPropertyUTFJson<string>(c, "sdkInfo"); | ||
Echo = new CommandUTF8Json<string, string>(c, "echo"); | ||
Interval = new WritablePropertyUTFJson<int>(c, "interval"); | ||
} | ||
} |
This file contains 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,76 @@ | ||
using MQTTnet.Client; | ||
using MQTTnet.Extensions.MultiCloud.AzureIoTClient; | ||
using MQTTnet.Extensions.MultiCloud.Connections; | ||
|
||
using device_template_protos; | ||
using MQTTnet.Extensions.MultiCloud; | ||
using MQTTnet.Extensions.MultiCloud.BrokerIoTClient; | ||
|
||
namespace iot_device; | ||
|
||
public class DeviceUtf8 : BackgroundService | ||
{ | ||
private readonly ILogger<DeviceUtf8> _logger; | ||
private readonly IConfiguration _configuration; | ||
|
||
private IMqttClient? mqtt; | ||
|
||
public DeviceUtf8(ILogger<DeviceUtf8> logger, IConfiguration configuration) | ||
{ | ||
_logger = logger; | ||
_configuration = configuration; | ||
} | ||
|
||
|
||
protected override async Task ExecuteAsync(CancellationToken stoppingToken) | ||
{ | ||
ConnectionSettings cs = new(_configuration.GetConnectionString("cs") + ";ModelId=dtmi:com:example:DeviceTemplate;1"); | ||
mqtt = await BrokerClientFactory.CreateFromConnectionSettingsAsync(cs, true, stoppingToken); | ||
//mqtt = await HubDpsFactory.CreateFromConnectionSettingsAsync(cs, stoppingToken); | ||
_logger.LogInformation($"Connected {cs}"); | ||
var client = new ClientUTF8Json(mqtt!); | ||
|
||
client.Interval.Value = 5; | ||
await client!.SdkInfo.SendMessageAsync("my SDK testing hub"); | ||
|
||
client.Interval.OnMessage = async m => | ||
{ | ||
Ack<int> ack = new Ack<int>(); | ||
if (m > 0) | ||
{ | ||
client.Interval.Value = m; | ||
ack.Status = 200; | ||
ack.Description = "property accepted"; | ||
ack.Value = m; | ||
ack.Version = client.Interval.Version; | ||
} | ||
else | ||
{ | ||
ack.Status = 403; | ||
ack.Description = $"negative value ({m}) not accepted"; | ||
ack.Value = client.Interval.Value; | ||
ack.Version = client.Interval.Version; | ||
} | ||
return await Task.FromResult(ack); | ||
}; | ||
|
||
client.Echo.OnMessage = async m => | ||
{ | ||
string result = string.Empty; | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
result += m; | ||
} | ||
return await Task.FromResult(result); | ||
}; | ||
|
||
while (!stoppingToken.IsCancellationRequested) | ||
{ | ||
await client.Temperature.SendMessageAsync(32.1); | ||
_logger.LogInformation("Worker running at: {time}, enabled {enabled}", DateTimeOffset.Now, true); | ||
await Task.Delay(client.Interval.Value * 1000, stoppingToken); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains 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,73 @@ | ||
using MQTTnet.Client; | ||
|
||
using MQTTnet.Extensions.MultiCloud.Connections; | ||
|
||
using device_template_protos; | ||
using MQTTnet.Extensions.MultiCloud.BrokerIoTClient; | ||
|
||
namespace iot_device; | ||
|
||
public class DeviceprotoBuff : BackgroundService | ||
{ | ||
private readonly ILogger<DeviceprotoBuff> _logger; | ||
private readonly IConfiguration _configuration; | ||
|
||
private IMqttClient? mqtt; | ||
|
||
public DeviceprotoBuff(ILogger<DeviceprotoBuff> logger, IConfiguration configuration) | ||
{ | ||
_logger = logger; | ||
_configuration = configuration; | ||
} | ||
|
||
|
||
protected override async Task ExecuteAsync(CancellationToken stoppingToken) | ||
{ | ||
ConnectionSettings cs = new(_configuration.GetConnectionString("cs") + ";ModelId=device-template.proto"); | ||
mqtt = await BrokerClientFactory.CreateFromConnectionSettingsAsync(cs, true, stoppingToken); | ||
_logger.LogInformation($"Connected {cs}"); | ||
|
||
var client = new ClientProtobuff(mqtt!); | ||
|
||
client.Interval.Value = new Properties() { Interval = 5}; | ||
await client!.SdkInfo.SendMessageAsync(new Properties { SdkInfo = "my SDK"}); | ||
|
||
client.Interval.OnMessage = async m => | ||
{ | ||
ack ack = new ack(); //<int>(mqtt!, "interval"); | ||
if (m.Interval > 0) | ||
{ | ||
client.Interval.Value = m; | ||
ack.Status = 200; | ||
ack.Description = "property accepted"; | ||
ack.Value = Google.Protobuf.WellKnownTypes.Any.Pack(m); | ||
} | ||
else | ||
{ | ||
ack.Status = 403; | ||
ack.Description = $"negative value ({m}) not accepted"; | ||
ack.Value = Google.Protobuf.WellKnownTypes.Any.Pack(client.Interval.Value); | ||
} | ||
return await Task.FromResult(ack); | ||
}; | ||
|
||
client.Echo.OnMessage = async m => | ||
{ | ||
string result = "echo "; | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
result += m.InEcho; | ||
} | ||
return await Task.FromResult(new echoResponse { OutEcho = result}); | ||
}; | ||
|
||
while (!stoppingToken.IsCancellationRequested) | ||
{ | ||
|
||
await client.Temperature.SendMessageAsync(new Telemetries { Temp = 32.1}); | ||
|
||
_logger.LogInformation("Worker running at: {time}, enabled {enabled}", DateTimeOffset.Now, true); | ||
await Task.Delay(client.Interval.Value.Interval * 1000, stoppingToken); | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.