feat(S2-b): connect durable MQTT sync to capture workflow
This commit is contained in:
@@ -11,6 +11,12 @@ public sealed class SettingsService
|
||||
private const string RtkNameKey = "device.rtk.name";
|
||||
private const string ActiveJobKey = "job.active.id";
|
||||
private const string MapsApiKeyKey = "maps.apikey";
|
||||
private const string MqttEnabledKey = "mqtt.enabled";
|
||||
private const string MqttHostKey = "mqtt.host";
|
||||
private const string MqttPortKey = "mqtt.port";
|
||||
private const string MqttOrgIdKey = "mqtt.org.id";
|
||||
private const string MqttClientIdKey = "mqtt.client.id";
|
||||
private const string MqttPasswordKey = "mqtt.password";
|
||||
|
||||
public Guid? GetSavedDeviceId(DeviceKind kind)
|
||||
{
|
||||
@@ -53,6 +59,52 @@ public sealed class SettingsService
|
||||
set => Preferences.Default.Set(MapsApiKeyKey, value);
|
||||
}
|
||||
|
||||
public bool MqttEnabled
|
||||
{
|
||||
get => Preferences.Default.Get(MqttEnabledKey, false);
|
||||
set => Preferences.Default.Set(MqttEnabledKey, value);
|
||||
}
|
||||
|
||||
public string MqttHost
|
||||
{
|
||||
get => Preferences.Default.Get(MqttHostKey, "dev.hub.umagul.net");
|
||||
set => Preferences.Default.Set(MqttHostKey, value.Trim());
|
||||
}
|
||||
|
||||
public int MqttPort
|
||||
{
|
||||
get => Preferences.Default.Get(MqttPortKey, 8884);
|
||||
set => Preferences.Default.Set(MqttPortKey, value);
|
||||
}
|
||||
|
||||
/// <summary>The interim MQTT username is the organization id.</summary>
|
||||
public string MqttOrgId
|
||||
{
|
||||
get => Preferences.Default.Get(MqttOrgIdKey, string.Empty);
|
||||
set => Preferences.Default.Set(MqttOrgIdKey, value.Trim());
|
||||
}
|
||||
|
||||
public string MqttClientId
|
||||
{
|
||||
get
|
||||
{
|
||||
var existing = Preferences.Default.Get(MqttClientIdKey, string.Empty);
|
||||
if (!string.IsNullOrWhiteSpace(existing)) return existing;
|
||||
var created = $"fieldlogger-{Guid.NewGuid():N}";
|
||||
Preferences.Default.Set(MqttClientIdKey, created);
|
||||
return created;
|
||||
}
|
||||
}
|
||||
|
||||
public Task<string?> GetMqttPasswordAsync() => SecureStorage.Default.GetAsync(MqttPasswordKey);
|
||||
|
||||
public Task SetMqttPasswordAsync(string password) =>
|
||||
string.IsNullOrWhiteSpace(password)
|
||||
? throw new ArgumentException("MQTT password cannot be empty.", nameof(password))
|
||||
: SecureStorage.Default.SetAsync(MqttPasswordKey, password);
|
||||
|
||||
public void ClearMqttPassword() => SecureStorage.Default.Remove(MqttPasswordKey);
|
||||
|
||||
private static string IdKey(DeviceKind kind) => kind == DeviceKind.Locator ? LocatorIdKey : RtkIdKey;
|
||||
private static string NameKey(DeviceKind kind) => kind == DeviceKind.Locator ? LocatorNameKey : RtkNameKey;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user