Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date.isValid and time.isValid are always true #107

Open
Jens869 opened this issue Oct 17, 2022 · 2 comments
Open

date.isValid and time.isValid are always true #107

Jens869 opened this issue Oct 17, 2022 · 2 comments

Comments

@Jens869
Copy link

Jens869 commented Oct 17, 2022

I'm currently working on a watch that uses GPS to tell the time.
But the error is also in the example DeviceExample.ino

`Serial.print(F(" Date/Time: "));
if (gps.date.isValid())
{
Serial.print(gps.date.month());
Serial.print(F("/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
}else
{
Serial.print(F("INVALID"));
}

if (gps.date.isValid()) {
// do something
} else
{
Serial.print(F("INVALID"));
}

`

if (gps.date.isValid()) is always TRUE, even if GPS fails.
gps.date.month() and gps.date.day() are 0.
Valid values ​​are month 1 to 12 - day 1 to 31.

if (gps.time.isValid()) is always TRUE, even if GPS fails.

Work around: check if the month or day is 0 Zerro

@Jens869
Copy link
Author

Jens869 commented Oct 17, 2022

Serial Monitor

reset
Location: INVALID Date/Time: INVALID INVALID gps.date.isValid()=0
Location: INVALID Date/Time: 0-0-2000 00:00:00 gps.date.isValid()=1
Location: INVALID Date/Time: 0-0-2000 00:00:00. gps.date.isValid()=1
Location: INVALID Date/Time: 0-0-2000 00:00:00. gps.date.isValid()=1

@mikalhart
Copy link
Owner

Hi @Jens869,

First of all, may I ask what watch you are playing with? We are enjoying working with the LilyGo T-Watch 2020 V2, which also has GPS. https://www.aliexpress.com/item/1005002264354524.html. Great fun!

It was arguably a weak naming choice, but isValid() == true means only "at least one properly formatted sentence containing this field has been received" and not "this field was populated with data that has been verified to be correct". I'm guessing that your GPS has sent a sentence which contains a blank date/time field--which is perfectly Valid, if not immediately useful.

Early on we decided that, in the interest of staying Tiny, the library would act strictly as a parser, and not a validator. Your sort of workaround is exactly what is needed. For example, one of the devices we sometimes deploy sends "January 1, 2080" as the date until it gets a fix. We have to check for this condition outside TinyGPS++.

Thanks for the comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants