Skip to content

Commit

Permalink
[ESP32] Fix sntp initialization (project-chip#32781)
Browse files Browse the repository at this point in the history
  • Loading branch information
jadhavrohit924 authored Apr 1, 2024
1 parent 401fbf0 commit 6268fbb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions examples/platform/esp32/time/TimeSync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <lib/support/logging/CHIPLogging.h>

static constexpr time_t kMinValidTimeStampEpoch = 1704067200; // 1 Jan 2019
static constexpr uint32_t kSecondsInADay = 24 * 60 * 60;
static constexpr uint32_t kMilliSecondsInADay = 24 * 60 * 60 * 1000;

namespace {
const uint8_t kMaxNtpServerStringSize = 128;
Expand Down Expand Up @@ -86,6 +86,11 @@ namespace chip {
namespace Esp32TimeSync {
void Init(const char * aSntpServerName, const uint16_t aSyncSntpIntervalDay)
{
if (!aSyncSntpIntervalDay)
{
ChipLogError(DeviceLayer, "Invalid SNTP synchronization time interval.");
return;
}
chip::Platform::CopyString(sSntpServerName, aSntpServerName);
if (esp_sntp_enabled())
{
Expand All @@ -94,9 +99,9 @@ void Init(const char * aSntpServerName, const uint16_t aSyncSntpIntervalDay)
ChipLogProgress(DeviceLayer, "Initializing SNTP. Using the SNTP server: %s", sSntpServerName);
esp_sntp_setoperatingmode(SNTP_OPMODE_POLL);
esp_sntp_setservername(0, sSntpServerName);
esp_sntp_set_sync_interval(kSecondsInADay * aSyncSntpIntervalDay);
esp_sntp_init();
esp_sntp_set_sync_interval(kMilliSecondsInADay * aSyncSntpIntervalDay);
sntp_set_time_sync_notification_cb(TimeSyncCallback);
esp_sntp_init();
}
} // namespace Esp32TimeSync
} // namespace chip

0 comments on commit 6268fbb

Please sign in to comment.