Is it possible to automatically get the time zone with this command to use within firmware?
Yes, but AT+CCLK only returns the timezone on the SARA-R4, not on the SARA-U used on all of the other devices. That being the case, I would just use Cellular.command to make the AT+CCLK command if you want the timezone.
It could be added to system firmware in the future, but it should be easy enough to use use Cellular.command.
I’ve got it working, but the time zone is -24 when it should be -6 im in central Minnesota.
Anyone have any ideas why it would show as -24?
int8_t isTZset = -1;
int callbacktzs(int type, const char* buf, int len, char* timezoneSetting) {
sscanf(buf, "\r\n+CTZU: %d", &isTZset);
sscanf(buf, "\r\n+CTZU: %d", timezoneSetting);
return WAIT;
}
char timezoneSetting[5] = "";
if (RESP_OK == Cellular.command(callbacktzs, timezoneSetting, 10000, "AT+CTZU?\r\n")) {
Serial.printlnf("timezone setting = %s", timezoneSetting);
Serial.printlnf("isTZset = %d", isTZset);
if (isTZset == 0) {
if (RESP_OK == Cellular.command(10000, "AT+CTZU=1\r\n")) {
Serial.println("tzupdated");
} else {
Serial.println("error1");
}
}
} else {
Serial.println("error");
}
Output (Time should be -6 hours 18/11/10,06:51:07)
Reading timezone:
timezone setting = .
isTZset = 1
Reading Clock:
clockResponse:"18/11/11,00:51:07-24"
time zone uses 15 minute steps.
Ahh,
But then why is the time wrong on the module?
Do you know the correct way to extract the timezone from the buf an a int8_t?
Would it be something like below?
format when the clock is read: +CCLK: “18/11/11,00:51:07-24”
sscanf(buf, "\r\n+CCLK: %*d/%*d/%*d,%*d:%*d:%*d%d", automaticTimeZone);
The tricky part is how the buf inculdes " and the begining and end of the time format
Embedded double quotes can be written in the format string as \"
sscanf(buf, "\r\n+CCLK: \"%*d/%*d/%*d,%*d:%*d:%*d%d\"", automaticTimeZone);
Here’s a basic imiplementation of setting the automatic timezone and then getting it back as a integer.
int8_t isTZset = -1; //used to determine if cellular module is set to get automatic timezone
int8_t automaticTimeZone = -100; //used to see if automatic timezone gets updated from -100;
int callbackClock(int type, const char* buf, int len, char* clockResponse) {
// buf format:+CCLK: "18/11/11,00:51:07-24"
sscanf(buf, "\r\n+CCLK: \"%*d/%*d/%*d,%*d:%*d:%*d%d\"", &automaticTimeZone);
return WAIT;
}
int callbackTZS(int type, const char* buf, int len, char* timezoneSetting) {
sscanf(buf, "\r\n+CTZU: %d", &isTZset);
return WAIT;
}
if (Cellular.ready()) {
Serial.println("Reading timezone: ");
char clockResponse[30] = "";
if (RESP_OK == Cellular.command(callbackClock, clockResponse, 10000, "AT+CCLK?\r\n")) {
if (automaticTimeZone == -100) { //timezone was not updated
//do nothing
} else automaticTimeZone = automaticTimeZone/4;
Serial.printlnf("Clock: %s", clockResponse);
Serial.printlnf("automaticTimeZone: %d", automaticTimeZone);
} else {
Serial.println("error");
}
}
if (Cellular.ready()) {
Serial.println("Reading automatic timezone setting: ");
char timezoneSetting[10] = "";
if (RESP_OK == Cellular.command(callbackTZS, timezoneSetting, 10000, "AT+CTZU?\r\n")) {
//Serial.printlnf("timezone setting = %s", timezoneSetting);
Serial.printlnf("isTZset = %d", isTZset);
if (isTZset == 0) {
if (RESP_OK == Cellular.command(10000, "AT+CTZU=1\r\n")) {
Serial.println("automatic timezone setting was updated");
} else {
Serial.println("error1");
}
}
} else {
Serial.println("error");
}
}
@ScruffR Do you think the automatic timezone will return with DST adjustments?
Example: Timezone = CST and it is summer
Will the cellular automatic time zone return CST (-6) or CDT (-5) ?
I think this is up to the provider. But I’d assume most do adjust.
Mine does do DST adjustment, but my old phone did also switch, without option to disable that, which was rather annoying