From ac2bf9372a88a5c865667a026d87db6574544847 Mon Sep 17 00:00:00 2001 From: Olexandr Tyshchenko Date: Thu, 12 Nov 2026 10:48:10 +0200 Subject: [PATCH] Limit the first periodic GPS acquisition after boot Before the first fix since boot, a periodic acquisition had no timeout. If no fix is accepted (no sky view, no antenna, or a guard rejecting spoofed fixes), the receiver then stayed on until a fix was accepted. Give that window its own limit, GPS_FIRST_FIX_TIMEOUT_MS (15 min by default, enough for a full almanac; 0 keeps the old behaviour). It counts as a miss and the next acquisition starts after the configured period. --- docs/cli_commands.md | 2 +- src/helpers/sensors/MicroNMEALocationProvider.h | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/cli_commands.md b/docs/cli_commands.md index bc30adbd48..f6c56ee363 100644 --- a/docs/cli_commands.md +++ b/docs/cli_commands.md @@ -1026,7 +1026,7 @@ region save **Parameters:** - `value`: `0` for continuous tracking, or a period. The value can be postfixed with `s`, `m`, `h` or `d` to specify the unit (seconds by default). -**Note:** A periodic acquisition stops after receiving a valid fix, then resumes after the configured period. +**Note:** A periodic acquisition stops after receiving a valid fix, then resumes after the configured period. Without a fix it stops after 5 minutes, or after 15 minutes until the first fix since boot (`GPS_PERIODIC_ACQUISITION_TIMEOUT_MS`, `GPS_FIRST_FIX_TIMEOUT_MS`). --- diff --git a/src/helpers/sensors/MicroNMEALocationProvider.h b/src/helpers/sensors/MicroNMEALocationProvider.h index 09b4d95546..c44e1c47cc 100644 --- a/src/helpers/sensors/MicroNMEALocationProvider.h +++ b/src/helpers/sensors/MicroNMEALocationProvider.h @@ -12,6 +12,11 @@ #ifndef GPS_PERIODIC_ACQUISITION_TIMEOUT_MS #define GPS_PERIODIC_ACQUISITION_TIMEOUT_MS 300000UL #endif +// limit for the periodic window before the first fix since boot (cold start can be long, +// a full almanac takes 12.5 min); 0 = keep searching until a fix +#ifndef GPS_FIRST_FIX_TIMEOUT_MS + #define GPS_FIRST_FIX_TIMEOUT_MS 900000UL +#endif // in periodic mode, keep reading after the first valid fix until enough satellites // are used or the settle time has elapsed @@ -363,10 +368,13 @@ class MicroNMEALocationProvider : public LocationProvider { } } - // no timeout until a first fix has been obtained (cold start can be long) - if (_acquiringPeriodically && _lastFix.valid && - (uint32_t)(millis() - _acquisitionStarted) >= GPS_PERIODIC_ACQUISITION_TIMEOUT_MS) { - finishPeriodicAcquisition(); + // a longer limit until a first fix has been obtained (cold start can be long) + if (_acquiringPeriodically) { + const uint32_t limit = _lastFix.valid ? GPS_PERIODIC_ACQUISITION_TIMEOUT_MS + : GPS_FIRST_FIX_TIMEOUT_MS; + if (limit > 0 && (uint32_t)(millis() - _acquisitionStarted) >= limit) { + finishPeriodicAcquisition(); + } } updateTime();