From 2dbfa1621502038739b33bd379787063ee74f753 Mon Sep 17 00:00:00 2001 From: Lefteris Date: Wed, 25 Apr 2018 10:05:00 +0300 Subject: [PATCH] Added Network Time Fetching for SimXXX --- examples/AllFunctions/AllFunctions.ino | 6 ++++ keywords.txt | 3 ++ src/TinyGsmClientSIM800.h | 38 ++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/examples/AllFunctions/AllFunctions.ino b/examples/AllFunctions/AllFunctions.ino index 38cb365..d175ec2 100644 --- a/examples/AllFunctions/AllFunctions.ino +++ b/examples/AllFunctions/AllFunctions.ino @@ -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); diff --git a/keywords.txt b/keywords.txt index 33f98c4..b6b4b10 100644 --- a/keywords.txt +++ b/keywords.txt @@ -24,3 +24,6 @@ factoryReset KEYWORD2 ####################################### # Literals (LITERAL1) ####################################### +DATE_FULL LITERAL1 +DATE_TIME LITERAL1 +DATE_DATE LITERAL1 diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index 13a62a9..a841a66 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -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 */