diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index c6550885..fc44fd2f 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -886,7 +886,7 @@ void MyMesh::sendSelfAdvertisement(int delay_millis) { void MyMesh::updateAdvertTimer() { if (_prefs.advert_interval > 0) { // schedule local advert timer - next_local_advert = futureMillis(((uint32_t)_prefs.advert_interval) * 2 * 60 * 1000); + next_local_advert = futureMillis((int)((uint32_t)_prefs.advert_interval * 2 * 60 * 1000)); } else { next_local_advert = 0; // stop the timer } diff --git a/examples/simple_room_server/MyMesh.cpp b/examples/simple_room_server/MyMesh.cpp index 011032b9..25ff7e10 100644 --- a/examples/simple_room_server/MyMesh.cpp +++ b/examples/simple_room_server/MyMesh.cpp @@ -774,7 +774,7 @@ void MyMesh::sendSelfAdvertisement(int delay_millis) { void MyMesh::updateAdvertTimer() { if (_prefs.advert_interval > 0) { // schedule local advert timer - next_local_advert = futureMillis((uint32_t)_prefs.advert_interval * 2 * 60 * 1000); + next_local_advert = futureMillis((int)((uint32_t)_prefs.advert_interval * 2 * 60 * 1000)); } else { next_local_advert = 0; // stop the timer } diff --git a/examples/simple_sensor/SensorMesh.cpp b/examples/simple_sensor/SensorMesh.cpp index 4995c55f..b30273a8 100644 --- a/examples/simple_sensor/SensorMesh.cpp +++ b/examples/simple_sensor/SensorMesh.cpp @@ -799,7 +799,7 @@ void SensorMesh::sendSelfAdvertisement(int delay_millis) { void SensorMesh::updateAdvertTimer() { if (_prefs.advert_interval > 0) { // schedule local advert timer - next_local_advert = futureMillis( ((uint32_t)_prefs.advert_interval) * 2 * 60 * 1000); + next_local_advert = futureMillis((int)((uint32_t)_prefs.advert_interval * 2 * 60 * 1000)); } else { next_local_advert = 0; // stop the timer } diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index 2410b9f1..c8e4a905 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -422,9 +422,14 @@ void CommonCLI::syncNodePrefsToMQTTPrefs() { #define MIN_LOCAL_ADVERT_INTERVAL 60 void CommonCLI::savePrefs() { + uint8_t old_advert_interval = _prefs->advert_interval; if (_prefs->advert_interval * 2 < MIN_LOCAL_ADVERT_INTERVAL) { _prefs->advert_interval = 0; // turn it off, now that device has been manually configured } + // If advert_interval was changed, update the timer to reflect the change + if (old_advert_interval != _prefs->advert_interval) { + _callbacks->updateAdvertTimer(); + } _callbacks->savePrefs(); } diff --git a/src/helpers/bridges/MQTTBridge.cpp b/src/helpers/bridges/MQTTBridge.cpp index 32685ca3..95eedfc1 100644 --- a/src/helpers/bridges/MQTTBridge.cpp +++ b/src/helpers/bridges/MQTTBridge.cpp @@ -639,37 +639,16 @@ void MQTTBridge::connectToBrokers() { // Maintain connection and check for stale connections if (_brokers[i].connected) { - // Check actual connection state - if it's stale, force reconnection - // This prevents accumulation of stale connections that appear connected but aren't responsive + // Check actual connection state - if it's stale, mark as disconnected + // PsychicMqttClient handles automatic reconnection internally, so we don't need + // to force periodic reconnections. Only mark as disconnected if actually disconnected. if (!_mqtt_client->connected()) { _brokers[i].connected = false; _active_brokers--; - } else { - // Periodic health check: Force reconnection every 4 hours to prevent stale connections - static unsigned long last_health_check = 0; - const unsigned long HEALTH_CHECK_INTERVAL = 14400000; // 4 hours - unsigned long now = millis(); - - unsigned long elapsed = (now >= last_health_check) ? - (now - last_health_check) : - (ULONG_MAX - last_health_check + now + 1); - - if (elapsed >= HEALTH_CHECK_INTERVAL) { - last_health_check = now; - _mqtt_client->disconnect(); - - char broker_uri[128]; - snprintf(broker_uri, sizeof(broker_uri), "mqtt://%s:%d", _brokers[i].host, _brokers[i].port); - _mqtt_client->setServer(broker_uri); - if (strlen(_brokers[i].username) > 0) { - _mqtt_client->setCredentials(_brokers[i].username, _brokers[i].password); - } - _mqtt_client->connect(); - _brokers[i].last_attempt = now; - _brokers[i].connected = false; - _active_brokers--; - } } + // Removed aggressive 4-hour health check that was causing connection instability. + // The MQTT client library handles connection health internally, and forcing + // disconnections on healthy connections was causing hours of downtime. } } }