优化SNTP连接,支持直接获取结构体。方便其他程序读取
This commit is contained in:
@@ -17,23 +17,13 @@ static uint8_t wifi_tx_buffer[WIFI_TX_BUF_SIZE];
|
||||
static volatile uint8_t wifi_tx_busy = 0;
|
||||
|
||||
WIFI_HandleTypeDef wifi = {0};
|
||||
SNTP_Time_t sntp_time = {0};
|
||||
|
||||
/* MQTT 状态 */
|
||||
static volatile uint8_t mqtt_connected = 0;
|
||||
static MQTT_State_t mqtt_state = MQTT_STATE_IDLE;
|
||||
|
||||
// SNTP 时间结构体
|
||||
typedef struct {
|
||||
uint16_t year;
|
||||
uint8_t month;
|
||||
uint8_t day;
|
||||
uint8_t hour;
|
||||
uint8_t minute;
|
||||
uint8_t second;
|
||||
uint8_t valid; // 1表示有效,0表示无效
|
||||
} SNTP_Time_t;
|
||||
|
||||
static SNTP_Time_t sntp_time = {0};
|
||||
|
||||
static void Generate_Random_ClientID(char *out_id, uint16_t max_len) {
|
||||
// 获取系统运行时间
|
||||
@@ -482,6 +472,13 @@ void wifi_task_mqtt(void *argument) {
|
||||
// 连接MQTT服务器成功后,获取SNTP时间
|
||||
WIFI_Get_SNTP_Time();
|
||||
|
||||
// 获取SNTP时间
|
||||
elog_i(TAG, "获取SNTP时间...");
|
||||
WIFI_Get_Current_Time();
|
||||
elog_i(TAG, "当前SNTP时间为: %04d-%02d-%02d %02d:%02d:%02d",
|
||||
sntp_time.year, sntp_time.month, sntp_time.day,
|
||||
sntp_time.hour, sntp_time.minute, sntp_time.second);
|
||||
|
||||
elog_i(TAG, "进入MQTT消息处理循环");
|
||||
for (;;) {
|
||||
if (wifi.rx_flag) {
|
||||
|
||||
@@ -26,9 +26,25 @@ typedef struct {
|
||||
uint16_t payload_len;
|
||||
} MQTT_Message_t;
|
||||
|
||||
|
||||
// SNTP 时间结构体
|
||||
typedef struct {
|
||||
uint16_t year;
|
||||
uint8_t month;
|
||||
uint8_t day;
|
||||
uint8_t hour;
|
||||
uint8_t minute;
|
||||
uint8_t second;
|
||||
uint8_t valid; // 1表示有效,0表示无效
|
||||
} SNTP_Time_t;
|
||||
|
||||
extern SNTP_Time_t sntp_time;
|
||||
|
||||
|
||||
/* 解析函数 */
|
||||
uint8_t WIFI_Parse_MQTT_Message(char *input, MQTT_Message_t *msg);
|
||||
|
||||
|
||||
/* MQTT运行状态 */
|
||||
typedef enum {
|
||||
MQTT_STATE_IDLE = 0,
|
||||
@@ -62,6 +78,7 @@ uint8_t WIFI_MQTT_Publish_Status(const char *json);
|
||||
/* ================= SNTP函数声明 ================= */
|
||||
uint8_t WIFI_Enable_SNTP(void);
|
||||
uint8_t WIFI_Get_SNTP_Time(void);
|
||||
|
||||
SNTP_Time_t WIFI_Get_Current_Time(void);
|
||||
uint8_t WIFI_Is_Time_Valid(void);
|
||||
|
||||
#endif /* __DX_WF_24_H__ */
|
||||
|
||||
Reference in New Issue
Block a user