mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	use update_interval for sntp synchronization (#2563)
* use update_interval for sntp synchronization * revert override of default interval
This commit is contained in:
		| @@ -3,6 +3,9 @@ | |||||||
|  |  | ||||||
| #ifdef USE_ESP32 | #ifdef USE_ESP32 | ||||||
| #include "lwip/apps/sntp.h" | #include "lwip/apps/sntp.h" | ||||||
|  | #ifdef USE_ESP_IDF | ||||||
|  | #include "esp_sntp.h" | ||||||
|  | #endif | ||||||
| #endif | #endif | ||||||
| #ifdef USE_ESP8266 | #ifdef USE_ESP8266 | ||||||
| #include "sntp.h" | #include "sntp.h" | ||||||
| @@ -37,6 +40,9 @@ void SNTPComponent::setup() { | |||||||
|   if (!this->server_3_.empty()) { |   if (!this->server_3_.empty()) { | ||||||
|     sntp_setservername(2, strdup(this->server_3_.c_str())); |     sntp_setservername(2, strdup(this->server_3_.c_str())); | ||||||
|   } |   } | ||||||
|  | #ifdef USE_ESP_IDF | ||||||
|  |   sntp_set_sync_interval(this->get_update_interval()); | ||||||
|  | #endif | ||||||
|  |  | ||||||
|   sntp_init(); |   sntp_init(); | ||||||
| } | } | ||||||
| @@ -47,7 +53,16 @@ void SNTPComponent::dump_config() { | |||||||
|   ESP_LOGCONFIG(TAG, "  Server 3: '%s'", this->server_3_.c_str()); |   ESP_LOGCONFIG(TAG, "  Server 3: '%s'", this->server_3_.c_str()); | ||||||
|   ESP_LOGCONFIG(TAG, "  Timezone: '%s'", this->timezone_.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() { | void SNTPComponent::loop() { | ||||||
|   if (this->has_time_) |   if (this->has_time_) | ||||||
|     return; |     return; | ||||||
| @@ -56,7 +71,7 @@ void SNTPComponent::loop() { | |||||||
|   if (!time.is_valid()) |   if (!time.is_valid()) | ||||||
|     return; |     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); |            time.minute, time.second); | ||||||
|   this->time_sync_callback_.call(); |   this->time_sync_callback_.call(); | ||||||
|   this->has_time_ = true; |   this->has_time_ = true; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user