Skip to content

Commit 6268fbb

Browse files
[ESP32] Fix sntp initialization (project-chip#32781)
1 parent 401fbf0 commit 6268fbb

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

examples/platform/esp32/time/TimeSync.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <lib/support/logging/CHIPLogging.h>
2323

2424
static constexpr time_t kMinValidTimeStampEpoch = 1704067200; // 1 Jan 2019
25-
static constexpr uint32_t kSecondsInADay = 24 * 60 * 60;
25+
static constexpr uint32_t kMilliSecondsInADay = 24 * 60 * 60 * 1000;
2626

2727
namespace {
2828
const uint8_t kMaxNtpServerStringSize = 128;
@@ -86,6 +86,11 @@ namespace chip {
8686
namespace Esp32TimeSync {
8787
void Init(const char * aSntpServerName, const uint16_t aSyncSntpIntervalDay)
8888
{
89+
if (!aSyncSntpIntervalDay)
90+
{
91+
ChipLogError(DeviceLayer, "Invalid SNTP synchronization time interval.");
92+
return;
93+
}
8994
chip::Platform::CopyString(sSntpServerName, aSntpServerName);
9095
if (esp_sntp_enabled())
9196
{
@@ -94,9 +99,9 @@ void Init(const char * aSntpServerName, const uint16_t aSyncSntpIntervalDay)
9499
ChipLogProgress(DeviceLayer, "Initializing SNTP. Using the SNTP server: %s", sSntpServerName);
95100
esp_sntp_setoperatingmode(SNTP_OPMODE_POLL);
96101
esp_sntp_setservername(0, sSntpServerName);
97-
esp_sntp_set_sync_interval(kSecondsInADay * aSyncSntpIntervalDay);
98-
esp_sntp_init();
102+
esp_sntp_set_sync_interval(kMilliSecondsInADay * aSyncSntpIntervalDay);
99103
sntp_set_time_sync_notification_cb(TimeSyncCallback);
104+
esp_sntp_init();
100105
}
101106
} // namespace Esp32TimeSync
102107
} // namespace chip

0 commit comments

Comments
 (0)