|
@ -24,6 +24,10 @@ class TinyGsmTime { |
|
|
String getGSMDateTime(TinyGSMDateTimeFormat format) { |
|
|
String getGSMDateTime(TinyGSMDateTimeFormat format) { |
|
|
return thisModem().getGSMDateTimeImpl(format); |
|
|
return thisModem().getGSMDateTimeImpl(format); |
|
|
} |
|
|
} |
|
|
|
|
|
bool getNetworkTime(int* year, int* month, int* day, int* hour, int* minute, |
|
|
|
|
|
int* second, float* timezone) { |
|
|
|
|
|
return thisModem().getNetworkTimeImpl(year, month, day, hour, minute, second, timezone); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* CRTP Helper |
|
|
* CRTP Helper |
|
@ -56,6 +60,49 @@ class TinyGsmTime { |
|
|
} |
|
|
} |
|
|
return res; |
|
|
return res; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool getNetworkTimeImpl(int* year, int* month, int* day, int* hour, int* minute, |
|
|
|
|
|
int* second, float* timezone) { |
|
|
|
|
|
thisModem().sendAT(GF("+CCLK?")); |
|
|
|
|
|
if (thisModem().waitResponse(2000L, GF("+CCLK: \"")) != 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 = thisModem().streamGetIntBefore('/'); |
|
|
|
|
|
imonth = thisModem().streamGetIntBefore('/'); |
|
|
|
|
|
iday = thisModem().streamGetIntBefore(','); |
|
|
|
|
|
ihour = thisModem().streamGetIntBefore(':'); |
|
|
|
|
|
imin = thisModem().streamGetIntBefore(':'); |
|
|
|
|
|
isec = thisModem().streamGetIntLength(2); |
|
|
|
|
|
char tzSign = thisModem().stream.read(); |
|
|
|
|
|
itimezone = thisModem().streamGetIntBefore('\n'); |
|
|
|
|
|
if (strcmp(tzSign, '-') == 0) { |
|
|
|
|
|
itimezone = itimezone * -1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 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 |
|
|
|
|
|
thisModem().waitResponse(); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
#endif // SRC_TINYGSMTIME_H_ |
|
|
#endif // SRC_TINYGSMTIME_H_ |