Browse Source

CCLK isn't local on BG96, use QLTS=2

Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
v_master
Sara Damiano 5 years ago
parent
commit
811105f968
3 changed files with 72 additions and 1 deletions
  1. +60
    -1
      src/TinyGsmClientBG96.h
  2. +1
    -0
      src/TinyGsmTime.tpp
  3. +11
    -0
      tools/test_build/test_build.ino

+ 60
- 1
src/TinyGsmClientBG96.h View File

@ -400,7 +400,66 @@ class TinyGsmBG96 : public TinyGsmModem<TinyGsmBG96>,
* Time functions * Time functions
*/ */
protected: protected:
// Can follow the standard CCLK function in the template
String getGSMDateTimeImpl(TinyGSMDateTimeFormat format) {
sendAT(GF("+QLTS=2"));
if (waitResponse(2000L, GF("+QLTS: \"")) != 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;
}
waitResponse(); // Ends with OK
return res;
}
// The BG96 returns UTC time instead of local time as other modules do in
// response to CCLK, so we're using QLTS where we can specifically request
// local time.
bool getNetworkTimeImpl(int* year, int* month, int* day, int* hour,
int* minute, int* second, float* timezone) {
sendAT(GF("+QLTS=2"));
if (waitResponse(2000L, GF("+QLTS: \"")) != 1) { return false; }
int iyear = 0;
int imonth = 0;
int iday = 0;
int ihour = 0;
int imin = 0;
int isec = 0;
int itimezone = 0;
// Date & Time
iyear = streamGetIntBefore('/');
imonth = streamGetIntBefore('/');
iday = streamGetIntBefore(',');
ihour = streamGetIntBefore(':');
imin = streamGetIntBefore(':');
isec = streamGetIntLength(2);
char tzSign = stream.read();
itimezone = streamGetIntBefore(',');
if (tzSign == '-') { itimezone = itimezone * -1; }
streamSkipUntil('\n'); // DST flag
// Set pointers
if (iyear < 2000) iyear += 2000;
if (year != NULL) *year = iyear;
if (month != NULL) *month = imonth;
if (day != NULL) *day = iday;
if (hour != NULL) *hour = ihour;
if (minute != NULL) *minute = imin;
if (second != NULL) *second = isec;
if (timezone != NULL) *timezone = static_cast<float>(itimezone) / 4.0;
// Final OK
waitResponse(); // Ends with OK
return true;
}
/* /*
* Battery functions * Battery functions


+ 1
- 0
src/TinyGsmTime.tpp View File

@ -59,6 +59,7 @@ class TinyGsmTime {
break; break;
case DATE_DATE: res = thisModem().stream.readStringUntil(','); break; case DATE_DATE: res = thisModem().stream.readStringUntil(','); break;
} }
thisModem().waitResponse(); // Ends with OK
return res; return res;
} }


+ 11
- 0
tools/test_build/test_build.ino View File

@ -68,11 +68,22 @@ void loop() {
// Test the GSM location functions // Test the GSM location functions
#if defined(TINY_GSM_MODEM_HAS_GSM_LOCATION) #if defined(TINY_GSM_MODEM_HAS_GSM_LOCATION)
modem.getGsmLocation(); modem.getGsmLocation();
float glatitude = -9999;
float glongitude = -9999;
modem.getGsmLocation(&glatitude, &glongitude);
#endif #endif
// Test the Network time function // Test the Network time function
#if defined(TINY_GSM_MODEM_HAS_TIME) #if defined(TINY_GSM_MODEM_HAS_TIME)
modem.getGSMDateTime(DATE_FULL); modem.getGSMDateTime(DATE_FULL);
int year3 = 0;
int month3 = 0;
int day3 = 0;
int hour3 = 0;
int min3 = 0;
int sec3 = 0;
float timezone = 0;
modem.getNetworkTime(&year3, &month3, &day3, &hour3, &min3, &sec3, &timezone);
#endif #endif
// Test the GPS functions // Test the GPS functions


Loading…
Cancel
Save