CCLK isn't local on BG96, use QLTS=2
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
This commit is contained in:
@@ -400,7 +400,66 @@ class TinyGsmBG96 : public TinyGsmModem<TinyGsmBG96>,
|
||||
* Time functions
|
||||
*/
|
||||
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
|
||||
|
@@ -59,6 +59,7 @@ class TinyGsmTime {
|
||||
break;
|
||||
case DATE_DATE: res = thisModem().stream.readStringUntil(','); break;
|
||||
}
|
||||
thisModem().waitResponse(); // Ends with OK
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user