mikalhart / TinyGPSPlus

A new, customizable Arduino NMEA parsing library
http://arduiniana.org
1.11k stars 494 forks source link

Wrong in date #101

Open Firered97 opened 2 years ago

Firered97 commented 2 years ago

Hey, I need help regarding date from the GPS. Right now my GPS is function as I can get my coordinate and time function also functioning as well but there is a problem with the date as it display not according to current date as shown on the image below. Im using Neo-6m ttgo t-beam(t22_v1.1 (20210222))

oled display

` void displayInfo() { // get time from GPS module if (gps.time.isValid()) { Minute = gps.time.minute(); Second = gps.time.second(); Hour = gps.time.hour(); }

  // get date drom GPS module
  if (gps.date.isValid())
  {
    Day   = gps.date.day();
    Month = gps.date.month();
    Year  = gps.date.year();
  }

  if(last_second != gps.time.second())  // if time has changed
  {
    last_second = gps.time.second();

    // set current UTC time
    setTime(Hour, Minute, Second, Day, Month, Year);
    // add the offset to get local time
    adjustTime(time_offset);

    // update time array
    Time[12] = second() / 10 + '0';
    Time[13] = second() % 10 + '0';
    Time[9]  = minute() / 10 + '0';
    Time[10] = minute() % 10 + '0';
    Time[6]  = hour()   / 10 + '0';
    Time[7]  = hour()   % 10 + '0';

    // update date array
    Date[6]  =  day()   / 10 + '0';
    Date[7]  =  day()   % 10 + '0';
    Date[9]  =  month() / 10 + '0';
    Date[10] =  month() % 10 + '0';
    Date[14] = (year()  / 10) % 10 + '0';
    Date[15] =  year()  % 10 + '0';
  }

display.setFont(ArialMT_Plain_10); display.flipScreenVertically(); if(gps.location.isValid() || gps.time.isValid() || gps.date.isValid()){ display.clear(); display.drawString(0,0, "Location: " + String(gps.location.lat(), 4) +"," + String(gps.location.lng(), 4)); display.drawString(0,10, String(Date)); display.drawString(0,20, String(Time)); //display.drawString(0,30, "Battery: " + String(axp.getBattPercentage()) + "%"); display.drawString(0,30, "BattVoltage: " + String(axp.getBattVoltage()/1000) + "V"); display.drawString(0,40, "Satellite: " + String(gps.satellites.value())); display.display(); }`

those are the example code that I use and change according to my need and I'm not sure where is my mistake to begin with, hope you guys can help me to solve this problem, I try to solve this problem for over a week now but still cant get any solution .

p/s: ignore the coordinate as I'm indoor right now so there will be no coordinate

TD-er commented 2 years ago

About the code formatting. You should use 3 backticks at begin and end (on a separate line) and if you like to have syntax highlighting, you can add "c++" right after the first 3 backticks.

About the wrong date, are you sure you have a fix?

Firered97 commented 2 years ago

Sorry bout the format coz its my first time put the code here

Regarding the date, as you can see from the pic i put there, i have try like a few example code but only the time is working for me but not the date, and im not sure whats wrong with the code because i follow exactly from the code, i just changed it a bit becoz im displaying it to oled display, thats all

cyberman54 commented 2 years ago

It looks like your gps has no fix, thus it may have a time but no date information. Go outdoor and assure you have gps fix.

This surely not an issue of this lib, so can be closed.

TD-er commented 2 years ago

When displaying the time/date, you don't check if the date is valid in your code. If your GPS module doesn't have a fix, the date can be just about anything. I have seen it reporting even dates in 2040.

Firered97 commented 2 years ago

do you have any suggestion about how can I get the GPS module to have it fix?

Firered97 commented 2 years ago

@cyberman54 how many hour do i have to leave it outdoor? because before this i have try it but still dont change the date

cyberman54 commented 2 years ago

depends on your gps chipset & antenna & if it is a cold or hot start. If cold start, and weak signal, it can take hours.

Firered97 commented 2 years ago

i see, i will give it a try

Firered97 commented 2 years ago

@cyberman54 is there anyway other from just let the module sit outdoor for hours? because I put mine from yesterday until now so almost 9 hour but still the date wont change

Jens869 commented 2 years ago

if (gps.date.isValid()) is always TRUE ! if (gps.time.isValid()) is always TRUE !

check if month > 0 if (gps.date.day() > 0) { then Date and Time are valid }