Browse Source

Merge pull request #159 from AnoxySoftware/Sim8XXNetworkTime

Added Network Time Fetching for SimXXX
v_master
Volodymyr Shymanskyy 6 years ago
committed by GitHub
parent
commit
9154aaa670
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 0 deletions
  1. +6
    -0
      examples/AllFunctions/AllFunctions.ino
  2. +3
    -0
      keywords.txt
  3. +38
    -0
      src/TinyGsmClientSIM800.h

+ 6
- 0
examples/AllFunctions/AllFunctions.ino View File

@ -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);


+ 3
- 0
keywords.txt View File

@ -24,3 +24,6 @@ factoryReset KEYWORD2
#######################################
# Literals (LITERAL1)
#######################################
DATE_FULL LITERAL1
DATE_TIME LITERAL1
DATE_DATE LITERAL1

+ 38
- 0
src/TinyGsmClientSIM800.h View File

@ -39,6 +39,11 @@ enum RegStatus {
REG_UNKNOWN = 4,
};
enum DateTime {
DATE_FULL = 0,
DATE_TIME = 1,
DATE_DATE = 2
};
class TinyGsmSim800
{
@ -307,6 +312,13 @@ public:
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;
@ -719,6 +731,32 @@ public:
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
*/


Loading…
Cancel
Save