Skip to content

Commit 4d942f5

Browse files
committed
fix issue with lag in time checking and add timezone info
1 parent 69bcde0 commit 4d942f5

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

EmberIotUtil.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#ifndef FIREBASE_UTIL_H
3535
#define FIREBASE_UTIL_H
3636

37+
#include "EmberIotShared.h"
38+
3739
#ifdef ESP32
3840
#include <WiFi.h>
3941
#elif ESP8266
@@ -43,6 +45,12 @@ extern "C" {
4345
}
4446
#endif
4547

48+
namespace EmberIotShared
49+
{
50+
unsigned long timezoneOffsetSeconds = 0;
51+
unsigned long daylightSavingsOffsetSeconds = 0;
52+
}
53+
4654
namespace FirePropUtil {
4755
inline size_t countOccurrences(const char *str, const char *sub) {
4856
int count = 0;
@@ -123,19 +131,26 @@ namespace FirePropUtil {
123131
inline void initTime()
124132
{
125133
#ifdef ESP32
126-
configTime(0, 0, "pool.ntp.org");
134+
configTime(EmberIotShared::timezoneOffsetSeconds, EmberIotShared::daylightSavingsOffsetSeconds, "pool.ntp.org");
127135
#endif
128136
}
129137

138+
bool firstCheckTime = true;
139+
130140
inline bool isTimeInitialized()
131141
{
132-
// if (WiFi.status() != WL_CONNECTED)
133-
// {
134-
// return false;
135-
// }
142+
if (firstCheckTime)
143+
{
144+
tm time;
145+
bool success = getLocalTime(&time);
146+
if (success)
147+
{
148+
firstCheckTime = false;
149+
}
150+
return success;
151+
}
136152

137-
tm time;
138-
return getLocalTime(&time);
153+
return true;
139154
}
140155

141156

0 commit comments

Comments
 (0)