|
|
@ -34,12 +34,12 @@ namespace hass_workstation_service.Data
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!File.Exists(Path.Combine(path, "mqttbroker.json")))
|
|
|
|
if (!File.Exists(Path.Combine(path, "mqttbroker.json")))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
File.Create(Path.Combine(path, "mqttbroker.json"));
|
|
|
|
File.Create(Path.Combine(path, "mqttbroker.json")).Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(Path.Combine(path, "configured-sensors.json")))
|
|
|
|
if (!File.Exists(Path.Combine(path, "configured-sensors.json")))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
File.Create(Path.Combine(path, "configured-sensors.json"));
|
|
|
|
File.Create(Path.Combine(path, "configured-sensors.json")).Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ConfiguredSensors = new List<AbstractSensor>();
|
|
|
|
ConfiguredSensors = new List<AbstractSensor>();
|
|
|
@ -123,8 +123,12 @@ namespace hass_workstation_service.Data
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
var mqttClientOptions = new MqttClientOptionsBuilder()
|
|
|
|
var mqttClientOptions = new MqttClientOptionsBuilder()
|
|
|
|
.WithTcpServer(configuredBroker.Host)
|
|
|
|
.WithTcpServer(configuredBroker.Host, configuredBroker.Port)
|
|
|
|
// .WithTls()
|
|
|
|
.WithTls(new MqttClientOptionsBuilderTlsParameters()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
UseTls = configuredBroker.UseTLS,
|
|
|
|
|
|
|
|
AllowUntrustedCertificates = true
|
|
|
|
|
|
|
|
})
|
|
|
|
.WithCredentials(configuredBroker.Username, configuredBroker.Password.ToString())
|
|
|
|
.WithCredentials(configuredBroker.Username, configuredBroker.Password.ToString())
|
|
|
|
.Build();
|
|
|
|
.Build();
|
|
|
|
return mqttClientOptions;
|
|
|
|
return mqttClientOptions;
|
|
|
@ -248,7 +252,9 @@ namespace hass_workstation_service.Data
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Host = settings.Host,
|
|
|
|
Host = settings.Host,
|
|
|
|
Username = settings.Username,
|
|
|
|
Username = settings.Username,
|
|
|
|
Password = settings.Password ?? ""
|
|
|
|
Password = settings.Password ?? "",
|
|
|
|
|
|
|
|
Port = settings.Port ?? 1883,
|
|
|
|
|
|
|
|
UseTLS = settings.UseTLS
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
await JsonSerializer.SerializeAsync(stream, configuredBroker);
|
|
|
|
await JsonSerializer.SerializeAsync(stream, configuredBroker);
|
|
|
@ -265,7 +271,9 @@ namespace hass_workstation_service.Data
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Host = broker?.Host,
|
|
|
|
Host = broker?.Host,
|
|
|
|
Username = broker?.Username,
|
|
|
|
Username = broker?.Username,
|
|
|
|
Password = broker?.Password
|
|
|
|
Password = broker?.Password,
|
|
|
|
|
|
|
|
Port = broker?.Port,
|
|
|
|
|
|
|
|
UseTLS = broker?.UseTLS ?? false
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|