Matthias Nott
2026-03-22 28fe0bf975a47e009232b56dd10b6944cde70064
lib/services/mqtt_service.dart
....@@ -95,6 +95,7 @@
9595
9696 final clientId = await _getClientId();
9797 final hosts = _getHosts();
98
+ _mqttLog('MQTT: hosts=${hosts.join(", ")} port=${config.port}');
9899
99100 for (final host in hosts) {
100101 if (_intentionalClose) return;
....@@ -162,8 +163,14 @@
162163 // Set _client BEFORE connect() so _onConnected can subscribe
163164 _client = client;
164165
165
- _mqttLog('MQTT: connecting to $host:${config.port} as $clientId');
166
- final result = await client.connect();
166
+ _mqttLog('MQTT: connecting to $host:${config.port} as $clientId (timeout=${timeout}ms)');
167
+ final result = await client.connect().timeout(
168
+ Duration(milliseconds: timeout + 1000),
169
+ onTimeout: () {
170
+ _mqttLog('MQTT: connect timed out for $host');
171
+ return null;
172
+ },
173
+ );
167174 _mqttLog('MQTT: connect result=${result?.state}');
168175 if (result?.state == MqttConnectionState.connected) {
169176 client.autoReconnect = true; // Now enable auto-reconnect for the live connection