Handle URC's related to automatic time updates

Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
This commit is contained in:
Sara Damiano
2020-02-18 15:54:13 -05:00
parent 669b88c9be
commit 6e7ea5aced
10 changed files with 80 additions and 25 deletions

View File

@@ -165,6 +165,10 @@ class TinyGsmBG96 : public TinyGsmModem<TinyGsmBG96>,
DBG(GF("### Modem:"), getModemName());
// Disable time and time zone URC's
sendAT(GF("+CTZR=0"));
if (waitResponse(10000L) != 1) { return false; }
// Enable automatic time zone update
sendAT(GF("+CTZU=1"));
if (waitResponse(10000L) != 1) { return false; }

View File

@@ -570,6 +570,10 @@ class TinyGsmM95 : public TinyGsmModem<TinyGsmM95>,
}
data = "";
DBG("### Closed: ", mux);
} else if (data.endsWith(GF("+QNITZ:" GSM_NL))) {
streamSkipUntil('\n'); // URC for time sync
data = "";
DBG("### Network time has been updated.");
}
}
} while (millis() - startMillis < timeout_ms);

View File

@@ -539,6 +539,10 @@ class TinyGsmMC60 : public TinyGsmModem<TinyGsmMC60>,
}
data = "";
DBG("### Closed: ", mux);
} else if (data.endsWith(GF("+QNITZ:" GSM_NL))) {
streamSkipUntil('\n'); // URC for time sync
DBG("### Network time has been updated.");
data = "";
}
}
} while (millis() - startMillis < timeout_ms);

View File

@@ -166,6 +166,10 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
DBG(GF("### Modem:"), getModemName());
// Disable time and time zone URC's
sendAT(GF("+CTZR=0"));
if (waitResponse(10000L) != 1) { return false; }
// Enable automatic time zome update
sendAT(GF("+CTZU=1"));
if (waitResponse(10000L) != 1) { return false; }

View File

@@ -686,6 +686,23 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000>,
}
data = "";
DBG("### Closed: ", mux);
} else if (data.endsWith(GF("*PSNWID:" GSM_NL))) {
streamSkipUntil('\n'); // Refresh network name by network
data = "";
DBG("### Network name has been updated.");
} else if (data.endsWith(GF("*PSUTTZ:" GSM_NL))) {
streamSkipUntil('\n'); // Refresh time and time zone by network
data = "";
DBG("### Network time and time zone have been updated.");
} else if (data.endsWith(GF("+CTZV:" GSM_NL))) {
streamSkipUntil('\n'); // Refresh network time zone by network
data = "";
DBG("### Network time zone has been updated.");
} else if (data.endsWith(GF("DST:" GSM_NL))) {
streamSkipUntil(
'\n'); // Refresh Network Daylight Saving Time by network
data = "";
DBG("### Daylight savings time state been updated.");
}
}
} while (millis() - startMillis < timeout_ms);

View File

@@ -170,6 +170,10 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
DBG(GF("### Modem:"), getModemName());
// Disable time and time zone URC's
sendAT(GF("+CTZR=0"));
if (waitResponse(10000L) != 1) { return false; }
// Enable automatic time zome update
sendAT(GF("+CTZU=1"));
if (waitResponse(10000L) != 1) { return false; }

View File

@@ -661,6 +661,23 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800>,
}
data = "";
DBG("### Closed: ", mux);
} else if (data.endsWith(GF("*PSNWID:" GSM_NL))) {
streamSkipUntil('\n'); // Refresh network name by network
data = "";
DBG("### Network name has been updated.");
} else if (data.endsWith(GF("*PSUTTZ:" GSM_NL))) {
streamSkipUntil('\n'); // Refresh time and time zone by network
data = "";
DBG("### Network time and time zone have been updated.");
} else if (data.endsWith(GF("+CTZV:" GSM_NL))) {
streamSkipUntil('\n'); // Refresh network time zone by network
data = "";
DBG("### Network time zone has been updated.");
} else if (data.endsWith(GF("DST:" GSM_NL))) {
streamSkipUntil(
'\n'); // Refresh Network Daylight Saving Time by network
data = "";
DBG("### Daylight savings time state been updated.");
}
}
} while (millis() - startMillis < timeout_ms);

View File

@@ -211,6 +211,10 @@ class TinyGsmSequansMonarch
sendAT(GF("+CFUN=1"));
waitResponse();
// Disable time and time zone URC's
sendAT(GF("+CTZR=0"));
if (waitResponse(10000L) != 1) { return false; }
// Enable automatic time zome update
sendAT(GF("+CTZU=1"));
if (waitResponse(10000L) != 1) { return false; }

View File

@@ -26,7 +26,8 @@ class TinyGsmTime {
}
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);
return thisModem().getNetworkTimeImpl(year, month, day, hour, minute,
second, timezone);
}
/*
@@ -61,12 +62,10 @@ class TinyGsmTime {
return res;
}
bool getNetworkTimeImpl(int* year, int* month, int* day, int* hour, int* minute,
int* second, float* timezone) {
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;
}
if (thisModem().waitResponse(2000L, GF("+CCLK: \"")) != 1) { return false; }
int iyear = 0;
int imonth = 0;
@@ -85,9 +84,7 @@ class TinyGsmTime {
isec = thisModem().streamGetIntLength(2);
char tzSign = thisModem().stream.read();
itimezone = thisModem().streamGetIntBefore('\n');
if (strcmp(tzSign, '-') == 0) {
itimezone = itimezone * -1;
}
if (strcmp(tzSign, '-') == 0) { itimezone = itimezone * -1; }
// Set pointers
if (iyear < 2000) iyear += 2000;
@@ -97,7 +94,7 @@ class TinyGsmTime {
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;
if (timezone != NULL) *timezone = static_cast<float>(itimezone) / 4.0;
// Final OK
thisModem().waitResponse();