Skip to content

Commit 75ddfcc

Browse files
committed
Automatically handle getTime fallback in IoTCloud class
1 parent e0abeb8 commit 75ddfcc

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/ArduinoIoTCloud.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ static ConnectionManager *getTimeConnection = NULL;
2929

3030
static unsigned long getTime() {
3131
if (!getTimeConnection) return 0;
32-
return getTimeConnection->getTime();
32+
unsigned long time = getTimeConnection->getTime();
33+
if (!NTPUtils::isTimeValid(time)) {
34+
debugMessage("Bogus NTP time from API, fallback to UDP method", 0);
35+
time = NTPUtils(getTimeConnection->getUDP()).getTime();
36+
}
37+
return time;
3338
}
3439

3540
ArduinoIoTCloudClass::ArduinoIoTCloudClass() :

0 commit comments

Comments
 (0)