Skip to content

Commit 992fd3d

Browse files
FrancMunozsandeepmistry
authored andcommitted
GSM::getLocalTime() (#47)
Added GSM::getLocalTime() function.
1 parent fd80015 commit 992fd3d

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ getvoiceCallStatus KEYWORD2
5555
hostByName KEYWORD2
5656
ping KEYWORD2
5757
getTime KEYWORD2
58+
getLocalTime KEYWORD2
5859
lowPowerMode KEYWORD2
5960
noLowPowerMode KEYWORD2
6061
peekDTMF KEYWORD2

src/GSM.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,25 @@ unsigned long GSM::getTime()
344344
return 0;
345345
}
346346

347+
unsigned long GSM::getLocalTime()
348+
{
349+
String response;
350+
351+
MODEM.send("AT+CCLK?");
352+
if (MODEM.waitForResponse(100, &response) != 1) {
353+
return 0;
354+
}
355+
356+
struct tm now;
357+
358+
if (strptime(response.c_str(), "+CCLK: \"%y/%m/%d,%H:%M:%S", &now) != NULL) {
359+
time_t result = mktime(&now);
360+
return result;
361+
}
362+
363+
return 0;
364+
}
365+
347366
int GSM::lowPowerMode()
348367
{
349368
return MODEM.lowPowerMode();

src/GSM.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class GSM {
6767
int ready();
6868

6969
unsigned long getTime();
70+
unsigned long getLocalTime();
7071

7172
int lowPowerMode();
7273
int noLowPowerMode();

0 commit comments

Comments
 (0)