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;
|
||||
}
|
||||
|
||||
|
@@ -68,11 +68,22 @@ void loop() {
|
||||
// Test the GSM location functions
|
||||
#if defined(TINY_GSM_MODEM_HAS_GSM_LOCATION)
|
||||
modem.getGsmLocation();
|
||||
float glatitude = -9999;
|
||||
float glongitude = -9999;
|
||||
modem.getGsmLocation(&glatitude, &glongitude);
|
||||
#endif
|
||||
|
||||
// Test the Network time function
|
||||
#if defined(TINY_GSM_MODEM_HAS_TIME)
|
||||
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
|
||||
|
||||
// Test the GPS functions
|
||||
|
Reference in New Issue
Block a user