Improve MQTT subscriber resilience

- Remove max reconnect attempts limit (was 10)
- MQTT subscriber now retries indefinitely until connection succeeds
- Reduce log spam by logging only first 10 attempts, then every 10th
- Prevents permanent connection loss after temporary network issues

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-01 17:49:54 +00:00
parent e64a22dee5
commit 34f6181e41

View File

@@ -20,7 +20,6 @@ interface OwnTracksMessage {
class MQTTSubscriber { class MQTTSubscriber {
private client: mqtt.MqttClient | null = null; private client: mqtt.MqttClient | null = null;
private reconnectAttempts = 0; private reconnectAttempts = 0;
private maxReconnectAttempts = 10;
private isConnecting = false; private isConnecting = false;
constructor( constructor(
@@ -80,11 +79,9 @@ class MQTTSubscriber {
this.client.on('reconnect', () => { this.client.on('reconnect', () => {
this.reconnectAttempts++; this.reconnectAttempts++;
console.log(`Reconnecting to MQTT broker (attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts})`); // Log less frequently to avoid spam (every 10th attempt after attempt 10)
if (this.reconnectAttempts <= 10 || this.reconnectAttempts % 10 === 0) {
if (this.reconnectAttempts >= this.maxReconnectAttempts) { console.log(`Reconnecting to MQTT broker (attempt ${this.reconnectAttempts})`);
console.error('Max reconnect attempts reached, giving up');
this.client?.end();
} }
}); });