Files

73 lines
1.4 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef SNTP_ESP_H
#define SNTP_ESP_H
#include <stdbool.h>
#include <time.h>
#include "esp_err.h"
/**
* @brief 初始化SNTP服务
*
* 初始化SNTP客户端配置NTP服务器和时区
* 必须在获得网络连接后调用
*
* @return ESP_OK 成功
* ESP_FAIL 失败
*/
esp_err_t sntp_esp_init(void);
/**
* @brief 设置时区
*
* 设置本地时区默认为北京时间CST-8
*
* @return ESP_OK 成功
*/
esp_err_t sntp_esp_set_timezone(void);
/**
* @brief 获取当前时间
*
* @return time_t 当前时间戳
*/
time_t sntp_esp_get_current_time(void);
/**
* @brief 打印当前时间
*
* 以格式化的方式打印当前时间到日志
*/
void sntp_esp_print_current_time(void);
/**
* @brief 获取格式化的时间字符串
*
* @param buffer 存储时间字符串的缓冲区
* @param size 缓冲区大小
* @param format 时间格式(如 "%Y-%m-%d %H:%M:%S"
* @return ESP_OK 成功
* ESP_FAIL 失败
*/
esp_err_t sntp_esp_get_formatted_time(char *buffer, size_t size, const char *format);
/**
* @brief 等待时间同步完成
*
* 等待SNTP时间同步完成
*
* @param max_wait_ms 最大等待时间(毫秒)
* @return true 同步成功
* false 超时
*/
bool sntp_esp_wait_sync(uint32_t max_wait_ms);
/**
* @brief 检查时间是否已同步
*
* @return true 已同步
* false 未同步
*/
bool sntp_esp_is_synced(void);
#endif // SNTP_ESP_H