Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickRitchie committed Dec 11, 2023
1 parent eeaa9e2 commit 23436ef
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
5 changes: 2 additions & 3 deletions adapter/Modules/MTConnect.NET-AdapterModule-MQTT/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ private async Task Worker()
// Add Client Certificate & Private Key
if (!string.IsNullOrEmpty(_configuration.PemCertificate) && !string.IsNullOrEmpty(_configuration.PemPrivateKey))
{

#if NET5_0_OR_GREATER
certificates.Add(new X509Certificate2(X509Certificate2.CreateFromPemFile(GetFilePath(_configuration.PemCertificate), GetFilePath(_configuration.PemPrivateKey)).Export(X509ContentType.Pfx)));
#else
throw new Exception("PEM Certificates Not Supported in .NET Framework 4.8 or older");
throw new Exception("PEM Certificates Not Supported in .NET Framework 4.8 or older");
#endif

clientOptionsBuilder.WithTls(new MqttClientOptionsBuilderTlsParameters()
Expand Down Expand Up @@ -114,7 +113,7 @@ private async Task Worker()
var clientOptions = clientOptionsBuilder.Build();

// Connect to the MQTT Client
_mqttClient.ConnectAsync(clientOptions).Wait();
await _mqttClient.ConnectAsync(clientOptions);

Log(MTConnectLogLevel.Information, "MQTT Client Connected");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ModuleConfiguration

public int QoS { get; set; }


public string CertificateAuthority { get; set; }

public string PemCertificate { get; set; }
Expand All @@ -27,10 +28,12 @@ public class ModuleConfiguration

public bool UseTls { get; set; }


public int ConnectionTimeout { get; set; }

public int ReconnectInterval { get; set; }


public string Topic { get; set; }

public string DeviceKey { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion agent/MTConnect.NET-Agent/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Program
{
// This is the Application Name shown in the Console header information
// If you are implementing this into your own application, you can change this to be more specific (ex. Fanuc MTConnect Agent, Mazak MTConnect Agent, etc.)
private const string ApplicationName = "MTConnect Agent";
private const string ApplicationName = "MTConnect.NET Agent";

// Copyright statement for the application. If you are implementing this into your own application, you can change this to your own copyright.
// This is just what is shown in the console header. If you want to show support for the MTConnect.NET project, you can reference it using the links in the default header
Expand Down
10 changes: 7 additions & 3 deletions agent/Modules/MTConnect.NET-AgentModule-MqttRelay/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ private async Task Worker()
try
{
// Declare new MQTT Client Options with Tcp Server
var clientOptionsBuilder = new MqttClientOptionsBuilder().WithTcpServer(_configuration.Server, _configuration.Port);
var clientOptionsBuilder = new MqttClientOptionsBuilder();

// Add TCP Server
clientOptionsBuilder.WithTcpServer(_configuration.Server, _configuration.Port);

// Publish Only so use Clean Session = true
clientOptionsBuilder.WithCleanSession();

// Set Client ID
if (!string.IsNullOrEmpty(_configuration.ClientId))
Expand All @@ -99,14 +105,12 @@ private async Task Worker()
// Add Client Certificate & Private Key
if (!string.IsNullOrEmpty(_configuration.PemCertificate) && !string.IsNullOrEmpty(_configuration.PemPrivateKey))
{

#if NET5_0_OR_GREATER
certificates.Add(new X509Certificate2(X509Certificate2.CreateFromPemFile(GetFilePath(_configuration.PemCertificate), GetFilePath(_configuration.PemPrivateKey)).Export(X509ContentType.Pfx)));
#else
throw new Exception("PEM Certificates Not Supported in .NET Framework 4.8 or older");
#endif

clientOptionsBuilder.WithCleanSession();
clientOptionsBuilder.WithTls(new MqttClientOptionsBuilderTlsParameters()
{
UseTls = true,
Expand Down

0 comments on commit 23436ef

Please sign in to comment.