GPS: poll up to 5s for cold-start detection instead of a single 1s check

initBasicGPS() waited a fixed 1 second and then decided the GPS was
present only if NMEA data had already arrived. Cold-start GPS modules
often need 2-5 seconds before they emit their first sentence, so on a
cold boot detection frequently failed. A failed detection sets
gps_detected = false, which hides all GPS CLI settings and disables GPS
time sync until the next reboot - so the GPS appears permanently dead
even though the hardware is fine.

Poll for up to ~5 seconds (in 250ms steps) and return as soon as any
data appears. Fast modules are detected almost immediately and add no
boot delay; slow cold-start modules now get enough time. The
ENV_SKIP_GPS_DETECT bypass is unchanged.

Fixes #2258.
This commit is contained in:
Jody Bentley
2026-06-26 10:44:18 -04:00
parent 3d4eec4a6a
commit 27feb73d4e
@@ -748,14 +748,18 @@ void EnvironmentSensorManager::initBasicGPS() {
MESH_DEBUG_PRINTLN("No GPS wake/reset pin found for this board. Continuing on...");
#endif
// Give GPS a moment to power up and send data
delay(1000);
// We'll consider GPS detected if we see any data on Serial1
// Give the GPS time to power up and emit its first NMEA sentence. Cold-start
// modules can take several seconds, so poll for up to ~5s instead of checking
// once after a fixed 1s delay -- returning as soon as any data appears, so
// fast modules add no boot delay (issue #2258).
#ifdef ENV_SKIP_GPS_DETECT
gps_detected = true;
#else
gps_detected = (Serial1.available() > 0);
gps_detected = false;
for (int i = 0; i < 20 && !gps_detected; i++) {
delay(250);
gps_detected = (Serial1.available() > 0);
}
#endif
if (gps_detected) {