Skip to content

Commit 3f9b2e1

Browse files
committed
getTime() return UNIX epoch if not in sync with NTP
1 parent 1c562b1 commit 3f9b2e1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/ArduinoCellular.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@
66
#endif
77

88
unsigned long ArduinoCellular::getTime() {
9-
int year, month, day, hour, minute, second;
9+
int year = 1970;
10+
int month = 1;
11+
int day = 1;
12+
int hour = 0;
13+
int minute = 0;
14+
int second = 0;
1015
float tz;
11-
modem.getNetworkTime(&year, &month, &day, &hour, &minute, &second, &tz);
16+
if (syncNTPServer() == 0) {
17+
modem.getNetworkTime(&year, &month, &day, &hour, &minute, &second, &tz);
18+
}
1219
return Time(year, month, day, hour, minute, second).getUNIXTimestamp();
1320
}
1421

0 commit comments

Comments
 (0)