Skip to content

Commit 1c1e33d

Browse files
authored
Ensure that the returned time is at least the compile time of the sketch, otherwise we might have an error scenario where no connection is available which would lead to a timestamp of 0 which would lead to the certificate being declared 'expired' and the device will be unable to connect to the server (#160)
1 parent b9a6f88 commit 1c1e33d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/utility/time/TimeService.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ unsigned long TimeService::getTime()
9393

9494
unsigned long TimeService::getRemoteTime()
9595
{
96-
if(_con_hdl == nullptr) return 0;
96+
if(_con_hdl == nullptr)
97+
return EPOCH_AT_COMPILE_TIME;
9798

9899
/* At first try to see if a valid time can be obtained
99100
* using the network time available via the connection
@@ -112,7 +113,12 @@ unsigned long TimeService::getRemoteTime()
112113
return ntp_time;
113114
}
114115

115-
return 0;
116+
/* Return the epoch timestamp at compile time as a last
117+
* line of defense. Otherwise the certificate expiration
118+
* date is wrong and we'll be unable to establish a connection
119+
* to the server.
120+
*/
121+
return EPOCH_AT_COMPILE_TIME;
116122
}
117123

118124
bool TimeService::isTimeValid(unsigned long const time)

0 commit comments

Comments
 (0)