aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Telemetry/Destinations/MqttTelemetryDestination.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.Telemetry/Destinations/MqttTelemetryDestination.cs')
-rw-r--r--Software/Visual_Studio/Tango.Telemetry/Destinations/MqttTelemetryDestination.cs36
1 files changed, 32 insertions, 4 deletions
diff --git a/Software/Visual_Studio/Tango.Telemetry/Destinations/MqttTelemetryDestination.cs b/Software/Visual_Studio/Tango.Telemetry/Destinations/MqttTelemetryDestination.cs
index b22849f3c..b5ff05c29 100644
--- a/Software/Visual_Studio/Tango.Telemetry/Destinations/MqttTelemetryDestination.cs
+++ b/Software/Visual_Studio/Tango.Telemetry/Destinations/MqttTelemetryDestination.cs
@@ -18,14 +18,15 @@ namespace Tango.Telemetry.Destinations
{
private IMqttClient _mqttClient;
private IMqttClientOptions _mqttOptions;
+ private DateTime _nextRealAvailabilityCheck;
- public string Name { get; private set; } = "MQTT";
+ public string Name { get; set; } = "MQTT";
public bool Enable { get; set; } = true;
public String Address { get; private set; }
public int Port { get; private set; }
public String Topic { get; private set; }
- public IReadOnlyList<TelemetrySource> SupportedSources { get; private set; }
+ public IReadOnlyList<TelemetrySourceTypes> SupportedSourceTypes { get; private set; }
/// <summary>
///
@@ -35,12 +36,34 @@ namespace Tango.Telemetry.Destinations
/// <param name="port">Default 1883</param>
public MqttTelemetryDestination(String topic, String address = "localhost", int port = 1883)
{
+ _nextRealAvailabilityCheck = DateTime.Now;
Topic = topic;
+ Address = address;
Port = port;
- SupportedSources = new List<TelemetrySource>() { TelemetrySource.Streaming };
+ SupportedSourceTypes = new List<TelemetrySourceTypes>() { TelemetrySourceTypes.Streaming };
}
- public async Task<bool> EnsureConnection()
+ public async Task<bool> IsAvailable()
+ {
+ if (_mqttClient == null)
+ {
+ return await EnsureConnection();
+ }
+ else
+ {
+ if (DateTime.Now > _nextRealAvailabilityCheck)
+ {
+ _nextRealAvailabilityCheck = DateTime.Now.AddMinutes(5);
+ return await EnsureConnection();
+ }
+ else
+ {
+ return _mqttClient.IsConnected;
+ }
+ }
+ }
+
+ private async Task<bool> EnsureConnection()
{
if (_mqttClient == null || !_mqttClient.IsConnected)
{
@@ -98,5 +121,10 @@ namespace Tango.Telemetry.Destinations
{
_mqttClient?.Dispose();
}
+
+ public override string ToString()
+ {
+ return $"{Name} -> {Address}:{Port}";
+ }
}
}