Browse Source

Handle URC's related to automatic time updates

Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
v_master
Sara Damiano 5 years ago
parent
commit
6e7ea5aced
10 changed files with 80 additions and 25 deletions
  1. +4
    -0
      src/TinyGsmClientBG96.h
  2. +4
    -0
      src/TinyGsmClientM95.h
  3. +4
    -0
      src/TinyGsmClientMC60.h
  4. +4
    -0
      src/TinyGsmClientSIM5360.h
  5. +17
    -0
      src/TinyGsmClientSIM7000.h
  6. +4
    -0
      src/TinyGsmClientSIM7600.h
  7. +17
    -0
      src/TinyGsmClientSIM800.h
  8. +4
    -0
      src/TinyGsmClientSequansMonarch.h
  9. +1
    -1
      src/TinyGsmTCP.tpp
  10. +21
    -24
      src/TinyGsmTime.tpp

+ 4
- 0
src/TinyGsmClientBG96.h 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; }


+ 4
- 0
src/TinyGsmClientM95.h 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);


+ 4
- 0
src/TinyGsmClientMC60.h 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);


+ 4
- 0
src/TinyGsmClientSIM5360.h 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; }


+ 17
- 0
src/TinyGsmClientSIM7000.h 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);


+ 4
- 0
src/TinyGsmClientSIM7600.h 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; }


+ 17
- 0
src/TinyGsmClientSIM800.h 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);


+ 4
- 0
src/TinyGsmClientSequansMonarch.h 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; }


+ 1
- 1
src/TinyGsmTCP.tpp View File

@ -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 { \


+ 21
- 24
src/TinyGsmTime.tpp 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,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<float>(itimezone)/ 4.0;
if (timezone != NULL) *timezone = static_cast<float>(itimezone) / 4.0;
// Final OK
thisModem().waitResponse();
return true;
}
}
};
#endif // SRC_TINYGSMTIME_H_

Loading…
Cancel
Save