diff --git a/orchestrateur/sensors/gps.py b/orchestrateur/sensors/gps.py index 1390afd..a6c97ed 100644 --- a/orchestrateur/sensors/gps.py +++ b/orchestrateur/sensors/gps.py @@ -34,11 +34,13 @@ class GROVEGPS: self.longitude = -1.0 def read(self): - """Reads the latest GGA sentence from serial, thread-safely.""" + """Reads the freshest GGA sentence from serial, thread-safely.""" with serial_lock: - for _ in range(10): # Read pending lines from buffer - if self.ser.in_waiting == 0: - break + # 1. Flush accumulated stale buffer data + self.ser.reset_input_buffer() + + # 2. Read through the fresh incoming stream to find a complete GGA line + for _ in range(15): raw_bytes = self.ser.readline() try: line = raw_bytes.decode('utf-8', errors='ignore').strip()