use update_interval for sntp synchronization (#2563)

* use update_interval for sntp synchronization

* revert  override of default interval
This commit is contained in:
Martin 2021-10-28 20:57:39 +02:00 committed by GitHub
parent 73accf747f
commit 2350c5054c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,9 @@
#ifdef USE_ESP32
#include "lwip/apps/sntp.h"
#ifdef USE_ESP_IDF
#include "esp_sntp.h"
#endif
#endif
#ifdef USE_ESP8266
#include "sntp.h"
@ -37,6 +40,9 @@ void SNTPComponent::setup() {
if (!this->server_3_.empty()) {
sntp_setservername(2, strdup(this->server_3_.c_str()));
}
#ifdef USE_ESP_IDF
sntp_set_sync_interval(this->get_update_interval());
#endif
sntp_init();
}
@ -47,7 +53,16 @@ void SNTPComponent::dump_config() {
ESP_LOGCONFIG(TAG, " Server 3: '%s'", this->server_3_.c_str());
ESP_LOGCONFIG(TAG, " Timezone: '%s'", this->timezone_.c_str());
}
void SNTPComponent::update() {}
void SNTPComponent::update() {
#ifndef USE_ESP_IDF
// force resync
if (sntp_enabled()) {
sntp_stop();
this->has_time_ = false;
sntp_init();
}
#endif
}
void SNTPComponent::loop() {
if (this->has_time_)
return;
@ -56,7 +71,7 @@ void SNTPComponent::loop() {
if (!time.is_valid())
return;
ESP_LOGD(TAG, "Synchronized time: %d-%d-%d %d:%d:%d", time.year, time.month, time.day_of_month, time.hour,
ESP_LOGD(TAG, "Synchronized time: %d-%d-%d %d:%02d:%02d", time.year, time.month, time.day_of_month, time.hour,
time.minute, time.second);
this->time_sync_callback_.call();
this->has_time_ = true;