在 wifi-connect.c 中实现了新的 Wi-Fi 连接管理模块,负责配网、连接及状态上报。 添加了用于 Wi-Fi 配置和状态显示的 HTML 界面。 集成了 NVS 用于存储 Wi-Fi 凭证。 更新了 CMakeLists.txt 以包含新模块的依赖项。 修改了 main.c 以初始化 Wi-Fi 连接管理并等待连接成功。
26 lines
695 B
C
Executable File
26 lines
695 B
C
Executable File
#include <stdio.h>
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
|
|
#include "wifi-connect.h"
|
|
|
|
// 等待 Wi-Fi 连接成功,超时后返回当前连接状态
|
|
static bool wait_for_wifi_connected(TickType_t timeout_ticks)
|
|
{
|
|
const TickType_t start_ticks = xTaskGetTickCount();
|
|
while ((xTaskGetTickCount() - start_ticks) < timeout_ticks)
|
|
{
|
|
if (wifi_connect_get_status() == WIFI_CONNECT_STATUS_CONNECTED)
|
|
{
|
|
return true;
|
|
}
|
|
vTaskDelay(pdMS_TO_TICKS(200));
|
|
}
|
|
return wifi_connect_get_status() == WIFI_CONNECT_STATUS_CONNECTED;
|
|
}
|
|
|
|
void app_main(void)
|
|
{
|
|
ESP_ERROR_CHECK(wifi_connect_init()); // 初始化 Wi-Fi 配网模块
|
|
}
|