diff --git a/API/MqttService.cs b/API/MqttService.cs
index 38da3b0..7c99211 100644
--- a/API/MqttService.cs
+++ b/API/MqttService.cs
@@ -101,7 +101,11 @@ private MqttService()
_mqttClient.DisconnectedAsync += async e =>
{
- Log.Information("Disconnected from MQTT broker.");
+ Log.Information($"Disconnected from MQTT broker. Reason: {e.Reason} | Exception: {e.Exception?.Message}");
+ if (e.Exception != null)
+ {
+ Log.Error($"Exception during disconnect: {e.Exception}");
+ }
_mqttClient.ApplicationMessageReceivedAsync -= OnMessageReceivedAsync;
await Task.CompletedTask;
@@ -246,10 +250,10 @@ public async Task ConnectAsync(AppSettings settings)
await _mqttClient.StopAsync();
Log.Information("Existing MQTT client stopped successfully.");
}
-
+ string uniqueClientId = $"TEAMS2HA_{Environment.MachineName}";
var mqttClientOptionsBuilder = new MqttClientOptionsBuilder()
- .WithClientId("TEAMS2HA")
- .WithKeepAlivePeriod(TimeSpan.FromSeconds(30))
+ .WithClientId(uniqueClientId)
+ .WithKeepAlivePeriod(TimeSpan.FromSeconds(60))
.WithCleanSession(true)
.WithCredentials(settings.MqttUsername, settings.MqttPassword);
if (settings.UseWebsockets && !settings.UseTLS)
diff --git a/TEAMS2HA.csproj b/TEAMS2HA.csproj
index 16e79fd..0d79a4b 100644
--- a/TEAMS2HA.csproj
+++ b/TEAMS2HA.csproj
@@ -5,8 +5,8 @@