From 6e7ea5aced498fba1de9db6c6440d7167eae078d Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Tue, 18 Feb 2020 15:54:13 -0500 Subject: [PATCH] Handle URC's related to automatic time updates Signed-off-by: Sara Damiano --- src/TinyGsmClientBG96.h | 4 +++ src/TinyGsmClientM95.h | 4 +++ src/TinyGsmClientMC60.h | 4 +++ src/TinyGsmClientSIM5360.h | 4 +++ src/TinyGsmClientSIM7000.h | 17 ++++++++++++ src/TinyGsmClientSIM7600.h | 4 +++ src/TinyGsmClientSIM800.h | 17 ++++++++++++ src/TinyGsmClientSequansMonarch.h | 4 +++ src/TinyGsmTCP.tpp | 2 +- src/TinyGsmTime.tpp | 45 +++++++++++++++---------------- 10 files changed, 80 insertions(+), 25 deletions(-) diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 4d39b22..ca391c8 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -165,6 +165,10 @@ class TinyGsmBG96 : public TinyGsmModem, 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; } diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 122771f..f85e4b0 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -570,6 +570,10 @@ class TinyGsmM95 : public TinyGsmModem, } 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); diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 78a062c..851cbbc 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -539,6 +539,10 @@ class TinyGsmMC60 : public TinyGsmModem, } 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); diff --git a/src/TinyGsmClientSIM5360.h b/src/TinyGsmClientSIM5360.h index b0992d5..6a8d17f 100644 --- a/src/TinyGsmClientSIM5360.h +++ b/src/TinyGsmClientSIM5360.h @@ -166,6 +166,10 @@ class TinyGsmSim5360 : public TinyGsmModem, 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; } diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index ddd7ec7..8c66e6c 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -686,6 +686,23 @@ class TinyGsmSim7000 : public TinyGsmModem, } 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); diff --git a/src/TinyGsmClientSIM7600.h b/src/TinyGsmClientSIM7600.h index e6a9eed..e4103ee 100644 --- a/src/TinyGsmClientSIM7600.h +++ b/src/TinyGsmClientSIM7600.h @@ -170,6 +170,10 @@ class TinyGsmSim7600 : public TinyGsmModem, 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; } diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index 83d19f2..7c7b35a 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -661,6 +661,23 @@ class TinyGsmSim800 : public TinyGsmModem, } 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); diff --git a/src/TinyGsmClientSequansMonarch.h b/src/TinyGsmClientSequansMonarch.h index 377d8c6..891e0de 100644 --- a/src/TinyGsmClientSequansMonarch.h +++ b/src/TinyGsmClientSequansMonarch.h @@ -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; } diff --git a/src/TinyGsmTCP.tpp b/src/TinyGsmTCP.tpp index e2cc313..4dfa659 100644 --- a/src/TinyGsmTCP.tpp +++ b/src/TinyGsmTCP.tpp @@ -22,7 +22,7 @@ // Because of the ordering of resolution of overrides in templates, these need // to be written out every time. This macro is to shorten that. #define TINY_GSM_CLIENT_CONNECT_OVERRIDES \ - int connect(IPAddress ip, uint16_t port, int timeout_s) { \ + int connect(IPAddress ip, uint16_t port, int timeout_s) { \ return connect(TinyGsmStringFromIp(ip).c_str(), port, timeout_s); \ } \ int connect(const char* host, uint16_t port) override { \ diff --git a/src/TinyGsmTime.tpp b/src/TinyGsmTime.tpp index 259f0da..3972e61 100644 --- a/src/TinyGsmTime.tpp +++ b/src/TinyGsmTime.tpp @@ -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,33 +62,29 @@ 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; - int iday = 0; - int ihour = 0; - int imin = 0; - int isec = 0; + 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); + 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; - } + itimezone = thisModem().streamGetIntBefore('\n'); + if (strcmp(tzSign, '-') == 0) { itimezone = itimezone * -1; } // Set pointers if (iyear < 2000) iyear += 2000; @@ -97,12 +94,12 @@ class TinyGsmTime { if (hour != NULL) *hour = ihour; if (minute != NULL) *minute = imin; if (second != NULL) *second = isec; - if (timezone != NULL) *timezone = static_cast(itimezone)/ 4.0; + if (timezone != NULL) *timezone = static_cast(itimezone) / 4.0; // Final OK thisModem().waitResponse(); return true; - } + } }; #endif // SRC_TINYGSMTIME_H_