Go Down

Topic: Bug? WiFi.getTime gives tomorrow (Read 295 times) previous topic - next topic

bcraigie

Apologies if this the wrong forum section.

On an MKR1000 and using the WifiRTC example with the only change to this script being the SSID and password...

It shows tomorrow's day.

It appears that the epoch returned from WiFi.getTime() is a day ahead in time.

Today is 13th January 2017, but the example shows it as being the 14th.
Every other aspect of the date and time is correct.  Just the day is wrong.


Simplified Sample code:

Code: [Select]

    unsigned long epoch;
    epoch = WiFi.getTime();
    Serial.print("Epoch received: ");
    Serial.println(epoch);
    rtc.setEpoch(epoch);

    Serial.println();

    Serial.print("Day is ");
    Serial.println(rtc.getDay());



Prints:

Code: [Select]
Epoch received: 1484395306

Day is 14


Anyone else seeing this problem?

bcraigie

Very strange.  In WiFi.cpp there is a line (1005) that says:

tm.tm_mday = systemTime.u8Day + 1;

This should not add 1, because the tm struct for mday is a number from 1 to 31.

Changing it to:
tm.tm_mday = systemTime.u8Day;

Fixes this problem.

el_supremo

There are reports on github of problems with the timestamp but they occurred when the wifi connection was first initiated. Nobody has reported problems with the date being out by one day and I would expect that it would have been noticed very quickly. I can't find a definition of the systemTime structure but I would have assumed that u8Day would indeed already be 1-31 rather than 0-30.
I haven't got a MKR1000 so I can't do any testing of my own.

Pete
Don't send me technical questions via Private Message.

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up