Hi everyone!
First things first, great Mikal and other contributors!!!
I was running examples/Beacon/Beacon.ino
I noticed Line 64: tinygps.encode(GPSSerial.read()); runs only once a there we will always have the same tinygps.time.second(),
Here is what I think it is happening (if I am not wrong)
while ((!tinygps.location.isValid() || !tinygps.date.isValid()) &&
millis() - loopStartTime < 7UL * 60UL * 1000UL)
{
if (GPSSerial.available())
tinygps.encode(GPSSerial.read());
}
Of course. Here is the explanation and the corrected code written in English.
First Execution (t=0):
The if (millis() - lastTransmissionTime ...) condition is met.
The code enters the while ((!tinygps.location.isValid() ...)) loop.
This loop runs, calling tinygps.encode(GPSSerial.read()) repeatedly until the GPS gets a valid fix.
Once tinygps.location.isValid() becomes true, the loop terminates.
The program uses that data (for example, with the time 16:19:17), sends it, and updates lastTransmissionTime. So far, so good!
Second Execution (t=1):
The code reaches the while ((!tinygps.location.isValid() ...)) loop again.
Here is the problem: Since you already got a fix during the first run, the !tinygps.location.isValid() condition is now false.
Because of this, the while loop does not execute even once.
The result is that tinygps.encode() is never called again, and your program keeps using the old, stale data from the first and only fix it ever processed.
What do you think?
Hi everyone!
First things first, great Mikal and other contributors!!!
I was running examples/Beacon/Beacon.ino
I noticed Line 64: tinygps.encode(GPSSerial.read()); runs only once a there we will always have the same tinygps.time.second(),
Here is what I think it is happening (if I am not wrong)
Of course. Here is the explanation and the corrected code written in English.
First Execution (t=0):
The if (millis() - lastTransmissionTime ...) condition is met.
The code enters the while ((!tinygps.location.isValid() ...)) loop.
This loop runs, calling tinygps.encode(GPSSerial.read()) repeatedly until the GPS gets a valid fix.
Once tinygps.location.isValid() becomes true, the loop terminates.
The program uses that data (for example, with the time 16:19:17), sends it, and updates lastTransmissionTime. So far, so good!
Second Execution (t=1):
The code reaches the while ((!tinygps.location.isValid() ...)) loop again.
Here is the problem: Since you already got a fix during the first run, the !tinygps.location.isValid() condition is now false.
Because of this, the while loop does not execute even once.
The result is that tinygps.encode() is never called again, and your program keeps using the old, stale data from the first and only fix it ever processed.
What do you think?