9 #include "lwip/apps/sntp.h" 14 #define strdup(x) (const_cast<char *>(x)) 20 static const char *
const TAG =
"sntp";
23 ESP_LOGCONFIG(TAG,
"Setting up SNTP...");
24 #if defined(USE_ESP_IDF) 25 if (esp_sntp_enabled()) {
28 esp_sntp_setoperatingmode(ESP_SNTP_OPMODE_POLL);
31 sntp_setoperatingmode(SNTP_OPMODE_POLL);
34 sntp_setservername(0, strdup(this->
server_1_.c_str()));
36 sntp_setservername(1, strdup(this->
server_2_.c_str()));
39 sntp_setservername(2, strdup(this->
server_3_.c_str()));
48 ESP_LOGCONFIG(TAG,
"SNTP Time:");
49 ESP_LOGCONFIG(TAG,
" Server 1: '%s'", this->
server_1_.c_str());
50 ESP_LOGCONFIG(TAG,
" Server 2: '%s'", this->
server_2_.c_str());
51 ESP_LOGCONFIG(TAG,
" Server 3: '%s'", this->
server_3_.c_str());
52 ESP_LOGCONFIG(TAG,
" Timezone: '%s'", this->
timezone_.c_str());
55 #if !defined(USE_ESP_IDF) 68 auto time = this->
now();
72 ESP_LOGD(TAG,
"Synchronized time: %04d-%02d-%02d %02d:%02d:%02d", time.year, time.month, time.day_of_month, time.hour,
73 time.minute, time.second);
ESPTime now()
Get the time in the currently defined timezone.
CallbackManager< void()> time_sync_callback_
virtual uint32_t get_update_interval() const
Get the update interval in ms of this sensor.
Implementation of SPI Controller mode.
void dump_config() override