From 4e829bc56ff9d92bab6e58954bd27df6beaa3e75 Mon Sep 17 00:00:00 2001 From: Wang Beihong Date: Tue, 21 Apr 2026 18:59:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=8B=AC=E7=AB=8B=E7=9A=84?= =?UTF-8?q?=20SNTP=20=E5=AF=B9=E6=97=B6=E4=BB=BB=E5=8A=A1=EF=BC=8C?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E5=9C=A8=E8=BF=9E=E6=8E=A5=20Wi-Fi=20?= =?UTF-8?q?=E5=90=8E=E5=90=8C=E6=AD=A5=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/main.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/main/main.cpp b/main/main.cpp index 66b66bf..2641153 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -17,6 +17,7 @@ #include "esp_system.h" #include "esp_efuse.h" #include "esp_efuse_table.h" +#include "sntp_time.h" #include "bh1750_use.h" #include "aht30.h" #include "MQ-2.h" @@ -129,6 +130,20 @@ static void status_task(void *arg) } } +static void sntp_task(void *arg) +{ + (void)arg; + + if (wait_for_wifi_connected(pdMS_TO_TICKS(15000))) { + esp_err_t sntp_ret = sntp_timp_sync_time(10000); + if (sntp_ret != ESP_OK) { + ESP_LOGW(TAG, "SNTP sync failed: %s", esp_err_to_name(sntp_ret)); + } + } + + vTaskDelete(NULL); +} + extern "C" void app_main(void) { vTaskDelay(pdMS_TO_TICKS(100)); @@ -154,6 +169,9 @@ extern "C" void app_main(void) set_var_system_ip(wifi_connect_get_ip()); } + // 4. 独立 SNTP 对时任务 + xTaskCreate(sntp_task, "sntp_task", 4096, NULL, 4, NULL); + // 初始化继电器 (独立配置每个通道) const relay_config_t relay_cfg[RELAY_CTRL_ID_MAX] = { {.pin = GPIO_NUM_9, .active_high = false},