Skip to content

Commit 5a2cf5c

Browse files
committed
Revert fix getTime management
1 parent 24a632d commit 5a2cf5c

File tree

5 files changed

+13
-20
lines changed

5 files changed

+13
-20
lines changed

src/ArduinoIoTCloud.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ const static int thingIdSlot = 12;
3333
static ConnectionManager *getTimeConnection = NULL;
3434

3535
static unsigned long getTime() {
36-
return getTimeConnection->getTime();
36+
if (!getTimeConnection) return 0;
37+
unsigned long time = getTimeConnection->getTime();
38+
if (!NTPUtils::isTimeValid(time)) {
39+
debugMessage("Bogus NTP time from API, fallback to UDP method", 0);
40+
time = NTPUtils(getTimeConnection->getUDP()).getTime();
41+
}
42+
return time;
3743
}
3844

3945
static unsigned long getTimestamp() {

src/ConnectionManager.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ class ConnectionManager {
3838
public:
3939
virtual void init() = 0;
4040
virtual void check() = 0;
41-
virtual unsigned long getTime();
41+
virtual unsigned long getTime() = 0;
4242
virtual Client &getClient();
43-
virtual UDP &getUDP() = 0;
43+
virtual UDP &getUDP();
4444

4545
virtual NetworkConnectionState getStatus() { return netConnectionState; }
4646

@@ -96,10 +96,6 @@ inline void debugMessage(char *_msg, int _debugLevel, bool _timestamp = true, bo
9696
}
9797
}
9898

99-
inline unsigned long ConnectionManager::getTime() {
100-
return NTPUtils(this->getUDP()).getTime();
101-
}
102-
10399
inline void setDebugMessageLevel(int _debugLevel){
104100
debugMessageLevel = _debugLevel;
105101
}

src/GSMConnectionManager.h

+2-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class GSMConnectionManager : public ConnectionManager {
3939
const int CHECK_INTERVAL_IDLE = 100;
4040
const int CHECK_INTERVAL_INIT = 100;
4141
const int CHECK_INTERVAL_CONNECTING = 500;
42-
const int CHECK_INTERVAL_GETTIME = 10;
42+
const int CHECK_INTERVAL_GETTIME = 666;
4343
const int CHECK_INTERVAL_CONNECTED = 10000;
4444
const int CHECK_INTERVAL_RETRYING = 5000;
4545
const int CHECK_INTERVAL_DISCONNECTED = 1000;
@@ -67,12 +67,7 @@ GSMConnectionManager::GSMConnectionManager(const char *pin, const char *apn, con
6767
}
6868

6969
unsigned long GSMConnectionManager::getTime() {
70-
unsigned long time = gsmAccess.getTime() {
71-
if (!NTPUtils::isTimeValid(time)) {
72-
debugMessage("Bogus NTP time from API, fallback to UDP method", 0);
73-
time = ConnectionManager::getTime();
74-
}
75-
return time;
70+
return gsmAccess.getTime();
7671
}
7772

7873
void GSMConnectionManager::init() {

src/WiFiConnectionManager.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,7 @@ WiFiConnectionManager::WiFiConnectionManager(const char *ssid, const char *pass)
6363
}
6464

6565
unsigned long WiFiConnectionManager::getTime() {
66-
unsigned long time = WiFi.getTime();
67-
if (!NTPUtils::isTimeValid(time)) {
68-
debugMessage("Bogus NTP time from API, fallback to UDP method", 0);
69-
time = ConnectionManager::getTime();
70-
}
71-
return time;
66+
return WiFi.getTime();
7267
}
7368

7469
void WiFiConnectionManager::init() {

src/utility/NTPUtils.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static time_t cvt_TIME(char const *time) {
2929
NTPUtils::NTPUtils(UDP& Udp) : Udp(Udp) {}
3030

3131
bool NTPUtils::isTimeValid(unsigned long time) {
32+
Serial.println("Compile time: " + String(cvt_TIME(__DATE__)));
3233
return (time > cvt_TIME(__DATE__));
3334
}
3435

0 commit comments

Comments
 (0)