Skip to content

Commit

Permalink
test hive
Browse files Browse the repository at this point in the history
  • Loading branch information
rido-min committed Dec 17, 2021
1 parent 46cb0fe commit 47066a1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
8 changes: 0 additions & 8 deletions Rido.IoTClient/AzIoTHub/GenericPnPClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,5 @@ public GenericPnPClient(IMqttClient c) : base(c)
public Task<MqttClientPublishResult> SendTelemetryAsync(object payload, CancellationToken t = default) =>
Connection.PublishAsync($"devices/{Connection.Options.ClientId}/messages/events/", payload, t);

public static async Task<GenericPnPClient> 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;
}

}
}
2 changes: 1 addition & 1 deletion control-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {}

Expand Down
12 changes: 11 additions & 1 deletion pnp-generic-client/DeviceRunner.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,7 +25,13 @@ public DeviceRunner(ILogger<DeviceRunner> 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);

Expand Down Expand Up @@ -55,5 +63,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
await Task.Delay(5000, stoppingToken);
}
}


}
}
2 changes: 1 addition & 1 deletion pnp-memmon/DeviceRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Diagnostics;
using System.Text;

using dtmi_rido_pnp_IoTHubClassic;
using dtmi_rido_pnp_HiveBroker;

namespace pnp_memmon;

Expand Down

0 comments on commit 47066a1

Please sign in to comment.