Skip to content

Commit 8a008e3

Browse files
Improve disconnection and reconnection (#148)
***NO_CI***
1 parent 639439a commit 8a008e3

File tree

6 files changed

+15
-24
lines changed

6 files changed

+15
-24
lines changed

.runsettings

Lines changed: 0 additions & 15 deletions
This file was deleted.

Tests/Aws.IoTCore.Devices.UnitTests.nfproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
<RestoreLockedMode Condition="'$(TF_BUILD)' == 'True' or '$(ContinuousIntegrationBuild)' == 'True'">true</RestoreLockedMode>
2626
</PropertyGroup>
2727
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
28+
<PropertyGroup>
29+
<RunSettingsFilePath>$(MSBuildProjectDirectory)\nano.runsettings</RunSettingsFilePath>
30+
</PropertyGroup>
2831
<ItemGroup>
2932
<Compile Include="ShadowTests.cs" />
3033
<Compile Include="Properties\AssemblyInfo.cs" />

azure-pipelines.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ steps:
4949
- template: azure-pipelines-templates/class-lib-build.yml@templates
5050
parameters:
5151
sonarCloudProject: 'nanoFramework.Aws.IoTCore.Devices'
52+
runUnitTests: true
53+
unitTestRunsettings: '$(System.DefaultWorkingDirectory)/Tests/nano.runsettings'
5254

5355
# step from template @ nf-tools repo
5456
# report error

nanoFramework.Aws.IoTCore.Devices/MqttConnectionClient.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public enum QoSLevel
5151
private readonly X509Certificate2 _clientCert; //Combined ClientRsaSha256Crt and ClientRsaKey
5252
private readonly X509Certificate _awsRootCACert;
5353

54-
private M2Mqtt.MqttClient _mqttc;
54+
private M2Mqtt.MqttClient _mqttc = null;
5555
private readonly ConnectorState _mqttBrokerStatus = new ConnectorState();
5656
private readonly ArrayList _waitForConfirmation = new ArrayList();
5757
private readonly object _lock = new object();
@@ -243,18 +243,22 @@ private void TimerCallbackReconnect(object state)
243243
/// </summary>
244244
public void Close()
245245
{
246-
if (_mqttc.IsConnected)
246+
if (_mqttc != null)
247247
{
248-
_mqttc.Unsubscribe(new[] {
248+
if (_mqttc.IsConnected)
249+
{
250+
_mqttc.Unsubscribe(new[] {
249251
$"{_deviceMessageTopic}/#",
250252
$"{ _shadowTopic }/#",
251253
});
254+
}
252255
_mqttc.Disconnect();
256+
_mqttc.Close();
253257
// Make sure all get disconnected, cleared (TODO: 1 second arbitrary value specified)
254258
Thread.Sleep(1000);
255259
}
256260

257-
_timerTokenRenew.Dispose();
261+
_timerTokenRenew?.Dispose();
258262
}
259263

260264
/// <summary>

nanoFramework.Aws.IoTCore.Devices/nanoFramework.Aws.IoTCore.Devices.nfproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@
4646
<ItemGroup>
4747
<None Include="packages.config" />
4848
</ItemGroup>
49-
<ItemGroup>
50-
<None Include="packages.lock.json" />
51-
</ItemGroup>
5249
<ItemGroup>
5350
<Reference Include="mscorlib, Version=1.14.3.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
5451
<HintPath>..\packages\nanoFramework.CoreLibrary.1.14.2\lib\mscorlib.dll</HintPath>
@@ -92,7 +89,7 @@
9289
</Reference>
9390
</ItemGroup>
9491
<ItemGroup>
95-
<None Include="packages.config" />
92+
<Content Include="packages.lock.json" />
9693
</ItemGroup>
9794
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
9895
<ProjectExtensions>

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
33
"version": "1.1",
44
"assemblyVersion": {
5-
"precision": "minor"
5+
"precision": "revision"
66
},
77
"semVer1NumericIdentifierPadding": 3,
88
"nuGetPackageVersion": {

0 commit comments

Comments
 (0)