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},