Skip to content

Commit bf430ae

Browse files
committed
Add getTime to retrieve system time from WINC
1 parent 735124b commit bf430ae

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ encryptionType KEYWORD2
4040
getResult KEYWORD2
4141
getSocket KEYWORD2
4242
poll KEYWORD2
43+
getTime KEYWORD2
4344
WiFiClient KEYWORD2
4445
WiFiServer KEYWORD2
4546
WiFiSSLClient KEYWORD2

src/WiFi.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
1919

20+
#include <time.h>
21+
2022
#include "WiFi101.h"
2123

2224
extern "C" {
@@ -160,6 +162,23 @@ static void wifi_cb(uint8_t u8MsgType, void *pvMsg)
160162
}
161163
break;
162164

165+
case M2M_WIFI_RESP_GET_SYS_TIME:
166+
{
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);
179+
}
180+
break;
181+
163182
default:
164183
break;
165184
}
@@ -891,4 +910,18 @@ int WiFiClass::ping(IPAddress host, uint8_t ttl)
891910
}
892911
}
893912

913+
uint32_t WiFiClass::getTime()
914+
{
915+
_resolve = (uint32_t)-1;
916+
917+
m2m_wifi_get_sytem_time();
918+
919+
unsigned long start = millis();
920+
while (_resolve == ((uint32_t)-1) && millis() - start < 5000) {
921+
m2m_wifi_handle_events(NULL);
922+
}
923+
924+
return _resolve;
925+
}
926+
894927
WiFiClass WiFi;

src/WiFi101.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ class WiFiClass
156156
int ping(const String &hostname, uint8_t ttl = 128);
157157
int ping(IPAddress host, uint8_t ttl = 128);
158158

159+
unsigned long getTime();
160+
159161
void refresh(void);
160162

161163
void lowPowerMode(void);

0 commit comments

Comments
 (0)