Skip to content

Commit

Permalink
Added Network Time Fetching for SimXXX
Browse files Browse the repository at this point in the history
  • Loading branch information
AnoxySoftware committed Apr 25, 2018
1 parent 0041755 commit 2dbfa16
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/AllFunctions/AllFunctions.ino
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ void loop() {
String gsmLoc = modem.getGsmLocation();
DBG("GSM location:", gsmLoc);

// This is only supported on SIMxxx series
String gsmTime = modem.getGSMDateTime(DATE_TIME);
DBG("GSM Time:", gsmTime);
String gsmDate = modem.getGSMDateTime(DATE_DATE);
DBG("GSM Date:", gsmDate);

String ussd_balance = modem.sendUSSD("*111#");
DBG("Balance (USSD):", ussd_balance);

Expand Down
3 changes: 3 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ factoryReset KEYWORD2
#######################################
# Literals (LITERAL1)
#######################################
DATE_FULL LITERAL1
DATE_TIME LITERAL1
DATE_DATE LITERAL1
38 changes: 38 additions & 0 deletions src/TinyGsmClientSIM800.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ enum RegStatus {
REG_UNKNOWN = 4,
};

enum DateTime {
DATE_FULL = 0,
DATE_TIME = 1,
DATE_DATE = 2
};

class TinyGsmSim800
{
Expand Down Expand Up @@ -307,6 +312,13 @@ class GsmClientSecure : public GsmClient
if (!testAT()) {
return false;
}
//Enable Local Time Stamp for getting network time
sendAT(GF("+CLTS=1"));
if (waitResponse(10000L) != 1) {
return false;
}
sendAT(GF("&W"));
waitResponse();
sendAT(GF("+CFUN=0"));
if (waitResponse(10000L) != 1) {
return false;
Expand Down Expand Up @@ -719,6 +731,32 @@ class GsmClientSecure : public GsmClient
return res;
}

/*
* Time functions
*/
String getGSMDateTime(DateTime format) {
sendAT(GF("+CCLK?"));
if (waitResponse(2000L, GF(GSM_NL "+CCLK: \"")) != 1) {
return "";
}

String res;

switch(format) {
case DATE_FULL:
res = stream.readStringUntil('"');
break;
case DATE_TIME:
streamSkipUntil(',');
res = stream.readStringUntil('"');
break;
case DATE_DATE:
res = stream.readStringUntil(',');
break;
}
return res;
}

/*
* Battery functions
*/
Expand Down

0 comments on commit 2dbfa16

Please sign in to comment.