Handle URC's related to automatic time updates
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
This commit is contained in:
@@ -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; }
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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; }
|
||||
|
@@ -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);
|
||||
|
@@ -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; }
|
||||
|
@@ -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);
|
||||
|
@@ -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; }
|
||||
|
@@ -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 { \
|
||||
|
@@ -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_
|
||||
|
Reference in New Issue
Block a user