aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Telemetry/Destinations
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.Telemetry/Destinations')
-rw-r--r--Software/Visual_Studio/Tango.Telemetry/Destinations/TelemetryAzureHubDestination.cs47
1 files changed, 33 insertions, 14 deletions
diff --git a/Software/Visual_Studio/Tango.Telemetry/Destinations/TelemetryAzureHubDestination.cs b/Software/Visual_Studio/Tango.Telemetry/Destinations/TelemetryAzureHubDestination.cs
index 94e949ba3..61a4bd880 100644
--- a/Software/Visual_Studio/Tango.Telemetry/Destinations/TelemetryAzureHubDestination.cs
+++ b/Software/Visual_Studio/Tango.Telemetry/Destinations/TelemetryAzureHubDestination.cs
@@ -7,6 +7,7 @@ using System.Text;
using System.Threading.Tasks;
using Tango.Core;
using Tango.Logging;
+using Tango.Telemetry.Helpers;
namespace Tango.Telemetry.Destinations
{
@@ -96,13 +97,21 @@ namespace Tango.Telemetry.Destinations
/// <returns>True if the destination is available; otherwise, false.</returns>
public Task<bool> IsAvailable()
{
- if (_hubClient == null)
+ //if (NetworkListManager.GetNetworks(NetworkConnectivityLevels.Connected).Any(x => x.IsConnectedToInternet))
+ if (InternetConnectivity.IsInternetAvailable())
{
- return Task.FromResult(true);
+ if (_hubClient == null)
+ {
+ return Task.FromResult(true);
+ }
+ else
+ {
+ return Task.FromResult(HubConnectionStatus == ConnectionStatus.Connected);
+ }
}
else
{
- return Task.FromResult(HubConnectionStatus == ConnectionStatus.Connected);
+ return Task.FromResult(false);
}
}
@@ -117,6 +126,7 @@ namespace Tango.Telemetry.Destinations
if (_hubClient == null)
{
_hubClient = DeviceClient.CreateFromConnectionString(ConnectionString, TransportType.Mqtt);
+ _hubClient.OperationTimeoutInMilliseconds = 2000;
_hubClient.SetConnectionStatusChangesHandler((status, reason) =>
{
HubConnectionStatus = status;
@@ -147,25 +157,34 @@ namespace Tango.Telemetry.Destinations
message.Properties.Add(prop.Key, prop.Value);
}
- if (BatchSize > 1)
+ try
{
- _batch.Add(message);
-
- if (_batch.Count >= BatchSize)
+ if (BatchSize > 1)
{
- LogManager.Log($"Sending telemetry batch of {_batch.Count} messages to Azure IoT Hub.", LogCategory.Debug);
- await _hubClient.SendEventBatchAsync(_batch.ToList());
- _batch.Clear();
+ _batch.Add(message);
+
+ if (_batch.Count >= BatchSize)
+ {
+ LogManager.Log($"Sending telemetry batch of {_batch.Count} messages to Azure IoT Hub.", LogCategory.Debug);
+ await _hubClient.SendEventBatchAsync(_batch.ToList());
+ _batch.Clear();
+ }
+ else
+ {
+ LogManager.Log($"Queued telemetry message for batching. {_batch.Count}/{BatchSize} currently queued.", LogCategory.Debug);
+ }
}
else
{
- LogManager.Log($"Queued telemetry message for batching. {_batch.Count}/{BatchSize} currently queued.", LogCategory.Debug);
+ LogManager.Log("Sending single telemetry message to Azure IoT Hub.", LogCategory.Debug);
+ await _hubClient.SendEventAsync(message);
}
}
- else
+ catch (Exception)
{
- LogManager.Log("Sending single telemetry message to Azure IoT Hub.", LogCategory.Debug);
- await _hubClient.SendEventAsync(message);
+ _hubClient?.Dispose();
+ _hubClient = null;
+ throw;
}
}