Skip to content

Commit 243ecd7

Browse files
committed
Move mktime call to WiFiClass::getTime, to prevent linking all the time
1 parent bf430ae commit 243ecd7

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

src/WiFi.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,11 @@ static void wifi_cb(uint8_t u8MsgType, void *pvMsg)
164164

165165
case M2M_WIFI_RESP_GET_SYS_TIME:
166166
{
167-
struct tm tm;
168-
tstrSystemTime *pstrSystemTime = (tstrSystemTime *)pvMsg;
169-
170-
tm.tm_year = pstrSystemTime->u16Year - 1900;
171-
tm.tm_mon = pstrSystemTime->u8Month - 1;
172-
tm.tm_mday = pstrSystemTime->u8Day;
173-
tm.tm_hour = pstrSystemTime->u8Hour;
174-
tm.tm_min = pstrSystemTime->u8Minute;
175-
tm.tm_sec = pstrSystemTime->u8Second;
176-
tm.tm_isdst = -1;
177-
178-
WiFi._resolve = mktime(&tm);
167+
if (WiFi._resolve != 0) {
168+
memcpy((tstrSystemTime *)WiFi._resolve, pvMsg, sizeof(tstrSystemTime));
169+
}
170+
171+
WiFi._resolve = 0;
179172
}
180173
break;
181174

@@ -912,15 +905,33 @@ int WiFiClass::ping(IPAddress host, uint8_t ttl)
912905

913906
uint32_t WiFiClass::getTime()
914907
{
915-
_resolve = (uint32_t)-1;
908+
tstrSystemTime systemTime;
909+
910+
_resolve = (uint32_t)&systemTime;
916911

917912
m2m_wifi_get_sytem_time();
918913

919914
unsigned long start = millis();
920-
while (_resolve == ((uint32_t)-1) && millis() - start < 5000) {
915+
while (_resolve != 0 && millis() - start < 5000) {
921916
m2m_wifi_handle_events(NULL);
922917
}
923918

919+
if (_resolve == 0) {
920+
struct tm tm;
921+
922+
tm.tm_year = systemTime.u16Year - 1900;
923+
tm.tm_mon = systemTime.u8Month - 1;
924+
tm.tm_mday = systemTime.u8Day;
925+
tm.tm_hour = systemTime.u8Hour;
926+
tm.tm_min = systemTime.u8Minute;
927+
tm.tm_sec = systemTime.u8Second;
928+
tm.tm_isdst = -1;
929+
930+
_resolve = mktime(&tm);
931+
} else {
932+
_resolve = (uint32_t)-1;
933+
}
934+
924935
return _resolve;
925936
}
926937

0 commit comments

Comments
 (0)