diff --git a/Rido.IoTClient/AzIoTHub/GenericPnPClient.cs b/Rido.IoTClient/AzIoTHub/GenericPnPClient.cs index 5237398..28a8772 100644 --- a/Rido.IoTClient/AzIoTHub/GenericPnPClient.cs +++ b/Rido.IoTClient/AzIoTHub/GenericPnPClient.cs @@ -19,13 +19,5 @@ public GenericPnPClient(IMqttClient c) : base(c) public Task SendTelemetryAsync(object payload, CancellationToken t = default) => Connection.PublishAsync($"devices/{Connection.Options.ClientId}/messages/events/", payload, t); - public static async Task CreateAsync(ConnectionSettings cs, CancellationToken token = default) - { - var connection = await IoTHubConnectionFactory.CreateAsync(cs, token); - var client = new GenericPnPClient(connection) { ConnectionSettings = cs }; - client.InitialState = await client.GetTwinAsync(token); - return client; - } - } } diff --git a/control-app/index.js b/control-app/index.js index 965b1db..0778611 100644 --- a/control-app/index.js +++ b/control-app/index.js @@ -5,7 +5,7 @@ const hivehost = 'f8826e3352314ca98102cfbde8aff20e.s2.eu.hivemq.cloud' const username = 'client1' const password = 'Myclientpwd.000' -const clientId = 'webApp' +const clientId = 'webApp' + Date.now() let onCommandResponse = resp => {} diff --git a/pnp-generic-client/DeviceRunner.cs b/pnp-generic-client/DeviceRunner.cs index 4fae556..8396881 100644 --- a/pnp-generic-client/DeviceRunner.cs +++ b/pnp-generic-client/DeviceRunner.cs @@ -1,6 +1,8 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using MQTTnet; +using MQTTnet.Client; using Rido.IoTClient; using Rido.IoTClient.AzIoTHub; using System; @@ -23,7 +25,13 @@ public DeviceRunner(ILogger logger, IConfiguration config) protected override async Task ExecuteAsync(CancellationToken stoppingToken) { - var client = await GenericPnPClient.CreateAsync(new ConnectionSettings(_configuration.GetConnectionString("cs")), stoppingToken); + var mqtt = new MqttFactory().CreateMqttClient(MqttNetTraceLogger.CreateTraceLogger()); + var cs = new ConnectionSettings(_configuration.GetConnectionString("cs")) { SasMinutes = 2, RetryInterval = 10 }; + + await mqtt.ConnectAsync(new MqttClientOptionsBuilder().WithAzureIoTHubCredentials(cs).Build(), stoppingToken); + var client = new GenericPnPClient(mqtt) { ConnectionSettings = cs }; + _logger.LogInformation($"Connected to {client.ConnectionSettings}"); + await client.ReportPropertyAsync(new { started = DateTime.Now }, stoppingToken); var twin = await client.GetTwinAsync(stoppingToken); @@ -55,5 +63,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) await Task.Delay(5000, stoppingToken); } } + + } } diff --git a/pnp-memmon/DeviceRunner.cs b/pnp-memmon/DeviceRunner.cs index 8bee04a..5f6d3d7 100644 --- a/pnp-memmon/DeviceRunner.cs +++ b/pnp-memmon/DeviceRunner.cs @@ -3,7 +3,7 @@ using System.Diagnostics; using System.Text; -using dtmi_rido_pnp_IoTHubClassic; +using dtmi_rido_pnp_HiveBroker; namespace pnp_memmon;