Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickRitchie committed Mar 11, 2023
2 parents 2326d56 + 9d1a297 commit 9b5bd4a
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 22 deletions.
52 changes: 52 additions & 0 deletions docs/MQTT-AWS-Greengrass-Moquette.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# AWS Greengrass Moquette Broker

## Overview
- AWS Greengrass Core Setup
- [Getting Started](https://docs.aws.amazon.com/greengrass/v1/developerguide/install-ggc.html)
- AWS Greengrass Moquette Setup
- [MQTT 3.1.1 broker (Moquette)](https://docs.aws.amazon.com/greengrass/v2/developerguide/mqtt-broker-moquette-component.html)

## AWS Greengrass Moquette Configuration
Under the Deployment configuration for the `aws.greengrass.clientdevices.mqtt.Moquette` component
```json
"moquette": {
"ssl_port": "8883"
}
```

## MTConnect Relay Agent
- [GitHub](https://github.com/TrakHound/MTConnect.NET/tree/master/applications/Agents/MTConnect-Agent-MQTT-Relay)
- [Release](https://github.com/TrakHound/MTConnect.NET/releases/latest)

### MTConnect Relay Agent Configuration
```yaml
...

# The hostname of the MQTT broker to publish messages to
server: localhost

# The port number of the MQTT broker to publish messages to
port: 8883

# The cerficates to use are for the AWS Thing that is configured for the AWS Core Device
certificateAuthority: C:\Users\patrick\Downloads\AmazonRootCA1.pem
pemCertificate: C:\Users\patrick\Downloads\2316549874654321654984984158961634984794-certificate.pem.crt
pemPrivateKey: C:\Users\patrick\Downloads\2316549874654321654984984158961634984794-private.pem.key

mqttFormat: Flat
retainMessage: true
allowUntrustedCertificates: true

# Set the ClientId to the AWS Thing ID
clientId: trakhound-test

...
```

## Screenshots

### AWS Thing
![Screenshot](../img/mqtt-aws-thing-certificates.png)

### AWS Core Device
![Screenshot](../img/mqtt-aws-greengrass-moquette-01.png)
26 changes: 26 additions & 0 deletions docs/MQTT-AWS-Greengrass-Mqtt-Bridge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# AWS Greengrass MQTT Bridge

## Overview
- AWS Greengrass Core Setup
- [Getting Started](https://docs.aws.amazon.com/greengrass/v1/developerguide/install-ggc.html)
- AWS Greengrass MQTT Bridge Setup
- [MQTT bridge](https://docs.aws.amazon.com/greengrass/v2/developerguide/mqtt-bridge-component.html)

## AWS Greengrass Moquette Configuration
Under the Deployment configuration for the `aws.greengrass.clientdevices.mqtt.Bridge` component
```json
"mqttTopicMapping": {
"MTConnectIotCoreMapping": {
"topic": "MTConnect/#",
"targetTopicPrefix": "trakhound-test/",
"source": "LocalMqtt",
"target": "IotCore"
}
}
```

## Setup AWS IoT Core
https://github.com/TrakHound/MTConnect.NET/blob/master/docs/MQTT-AWS-IoT.md

## Setup AWS Greengrass Moquette MQTT Broker
https://github.com/TrakHound/MTConnect.NET/blob/master/docs/MQTT-AWS-Greengrass-Moquette.md
Binary file added img/mqtt-aws-greengrass-moquette-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/mqtt-aws-thing-certificates.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Reflection;

[assembly: AssemblyVersion("5.2.0")]
[assembly: AssemblyFileVersion("5.2.0")]
[assembly: AssemblyVersion("5.3.0")]
[assembly: AssemblyFileVersion("5.3.0")]
[assembly: AssemblyCompany("TrakHound Inc.")]
[assembly: AssemblyCopyright("Copyright (c) 2023 TrakHound Inc., All Rights Reserved.")]
25 changes: 11 additions & 14 deletions src/MTConnect.NET-Common/Agents/MTConnectAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -745,30 +745,27 @@ private static bool FilterPeriod(IDataItem dataItem, long newTimestamp, long exi
{
if (dataItem != null)
{
if (newTimestamp > existingTimestamp)
if (!dataItem.Filters.IsNullOrEmpty())
{
if (!dataItem.Filters.IsNullOrEmpty())
foreach (var filter in dataItem.Filters)
{
foreach (var filter in dataItem.Filters)
if (filter.Type == DataItemFilterType.PERIOD)
{
if (filter.Type == DataItemFilterType.PERIOD)
if (filter.Value > 0)
{
if (filter.Value > 0)
{
// Get Period based on Seconds specified in Filter
var period = TimeSpan.FromSeconds(filter.Value);
// Get Period based on Seconds specified in Filter
var period = TimeSpan.FromSeconds(filter.Value);

// Get Duration between newTimestamp and existingTimestamp
var duration = TimeSpan.FromMilliseconds(newTimestamp - existingTimestamp);
// Get Duration between newTimestamp and existingTimestamp
var duration = TimeSpan.FromMilliseconds(newTimestamp - existingTimestamp);

return duration > period;
}
return duration > period;
}
}
}

return true;
}

return true;
}

return false;
Expand Down
12 changes: 7 additions & 5 deletions src/MTConnect.NET-MQTT/Clients/MTConnectMqttClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class MTConnectMqttClient : IDisposable
private readonly string _caCertPath;
private readonly string _pemClientCertPath;
private readonly string _pemPrivateKeyPath;
private readonly bool _allowUntrustedCertificates;
private readonly bool _useTls;
private readonly IEnumerable<string> _topics;

Expand Down Expand Up @@ -93,6 +94,7 @@ public MTConnectMqttClient(MTConnectMqttClientConfiguration configuration, IEnum
_caCertPath = configuration.CertificateAuthority;
_pemClientCertPath = configuration.PemCertificate;
_pemPrivateKeyPath = configuration.PemPrivateKey;
_allowUntrustedCertificates = configuration.AllowUntrustedCertificates;
_useTls = configuration.UseTls;
}

Expand Down Expand Up @@ -139,9 +141,9 @@ public async Task StartAsync()
{
UseTls = true,
SslProtocol = System.Security.Authentication.SslProtocols.Tls12,
IgnoreCertificateRevocationErrors = true,
IgnoreCertificateChainErrors = true,
AllowUntrustedCertificates = true,
IgnoreCertificateRevocationErrors = _allowUntrustedCertificates,
IgnoreCertificateChainErrors = _allowUntrustedCertificates,
AllowUntrustedCertificates = _allowUntrustedCertificates,
Certificates = certificates
});
}
Expand Down Expand Up @@ -187,7 +189,7 @@ public async Task StopAsync()
try
{
// Disconnect from the MQTT Client
if (_mqttClient != null) await _mqttClient.DisconnectAsync();
if (_mqttClient != null) await _mqttClient.DisconnectAsync(MqttClientDisconnectReason.NormalDisconnection);
}
catch { }
}
Expand Down Expand Up @@ -354,7 +356,7 @@ private void ProcessAsset(MqttApplicationMessage message)
}


private string GetFilePath(string path)
private static string GetFilePath(string path)
{
var x = path;
if (!Path.IsPathRooted(x))
Expand Down
5 changes: 4 additions & 1 deletion src/MTConnect.NET-MQTT/MTConnectMqttRelay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ public void Stop()

try
{
if (_mqttClient != null) _mqttClient.DisconnectAsync();
if (_mqttClient != null)
{
_mqttClient.DisconnectAsync(MqttClientDisconnectReason.NormalDisconnection);
}
}
catch { }
}
Expand Down
2 changes: 2 additions & 0 deletions src/MTConnect.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MTConnect.NET-Applications-
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{0957974A-CA4D-45DD-A0CB-2C4A9CD03350}"
ProjectSection(SolutionItems) = preProject
..\docs\MQTT-AWS-Greengrass-Mqtt-Bridge.md = ..\docs\MQTT-AWS-Greengrass-Mqtt-Bridge.md
..\docs\MQTT-AWS-IoT.md = ..\docs\MQTT-AWS-IoT.md
..\docs\MQTT-AWS-Greengrass-Moquette.md = ..\docs\MQTT-AWS-Greengrass-Moquette.md
..\docs\MQTT-HiveMQ.md = ..\docs\MQTT-HiveMQ.md
..\README.md = ..\README.md
EndProjectSection
Expand Down

0 comments on commit 9b5bd4a

Please sign in to comment.