diff --git a/libraries/Common/board/ports/filesystem/mnt.c b/libraries/Common/board/ports/filesystem/mnt.c index 26860308..53e81bff 100644 --- a/libraries/Common/board/ports/filesystem/mnt.c +++ b/libraries/Common/board/ports/filesystem/mnt.c @@ -123,12 +123,16 @@ static void _fal_mount(void) { LOG_I("Block device created for filesystem"); + rt_thread_mdelay(200); + /* Try to mount filesystem */ if (dfs_mount("filesystem", "/flash", "lfs", 0, 0) != 0) { - LOG_W("Mount filesystem failed, try to mkfs"); + LOG_E("Mount filesystem failed, try to mkfs"); /* Format filesystem */ + rt_thread_mdelay(200); + if (dfs_mkfs("lfs", "filesystem") != 0) { LOG_E("mkfs failed"); diff --git a/projects/Edgi_Talk_M55_XiaoZhi/applications/xiaozhi/ui/xiaozhi_ui.c b/projects/Edgi_Talk_M55_XiaoZhi/applications/xiaozhi/ui/xiaozhi_ui.c index 9860a105..8f19c6f9 100644 --- a/projects/Edgi_Talk_M55_XiaoZhi/applications/xiaozhi/ui/xiaozhi_ui.c +++ b/projects/Edgi_Talk_M55_XiaoZhi/applications/xiaozhi/ui/xiaozhi_ui.c @@ -21,6 +21,8 @@ #define DBG_LVL DBG_INFO #include +#define AP_INFO_DEFAULT_TEXT "SSID: RT-Thread-AP 密码: 123456789 IP:192.168.169.1" + #define EMOJI_NUM 18 #define UI_MSG_DATA_SIZE 128 #define UI_MSG_POOL_SIZE 10 @@ -449,7 +451,7 @@ static void ui_process_message(const ui_msg_t *msg) case UI_CMD_SHOW_AP_INFO: if (s_label_status) lv_label_set_text(s_label_status, "连接中..."); if (s_label_info) lv_label_set_text(s_label_info, "使用手机或电脑连接热点"); - if (s_label_output) lv_label_set_text(s_label_output, "SSID: RT-Thread-AP 密码: 123456789 IP:192.168.169.1"); + if (s_label_output) lv_label_set_text(s_label_output, msg->data[0] ? msg->data : AP_INFO_DEFAULT_TEXT); break; case UI_CMD_SHOW_CONNECTING: @@ -654,9 +656,9 @@ void xiaozhi_ui_clear_info(void) ui_send_message(UI_CMD_CLEAR_INFO, RT_NULL, RT_NULL); } -void xiaozhi_ui_show_ap_config(void) +void xiaozhi_ui_show_ap_config(const char *ap_info) { - ui_send_message(UI_CMD_SHOW_AP_INFO, RT_NULL, RT_NULL); + ui_send_message(UI_CMD_SHOW_AP_INFO, ap_info, AP_INFO_DEFAULT_TEXT); } void xiaozhi_ui_show_connecting(void) diff --git a/projects/Edgi_Talk_M55_XiaoZhi/applications/xiaozhi/ui/xiaozhi_ui.h b/projects/Edgi_Talk_M55_XiaoZhi/applications/xiaozhi/ui/xiaozhi_ui.h index 9f14d33e..fab05200 100644 --- a/projects/Edgi_Talk_M55_XiaoZhi/applications/xiaozhi/ui/xiaozhi_ui.h +++ b/projects/Edgi_Talk_M55_XiaoZhi/applications/xiaozhi/ui/xiaozhi_ui.h @@ -73,8 +73,9 @@ void xiaozhi_ui_clear_info(void); /** * @brief Show AP config mode info on screen + * @param ap_info AP info text, e.g. "SSID: xxx 密码: xxx IP:192.168.169.1" */ -void xiaozhi_ui_show_ap_config(void); +void xiaozhi_ui_show_ap_config(const char *ap_info); /** * @brief Show connecting status (for auto-connect from saved config) diff --git a/projects/Edgi_Talk_M55_XiaoZhi/applications/xiaozhi/webnet/webnet_wifi.c b/projects/Edgi_Talk_M55_XiaoZhi/applications/xiaozhi/webnet/webnet_wifi.c index dd8a023c..eecb8d32 100644 --- a/projects/Edgi_Talk_M55_XiaoZhi/applications/xiaozhi/webnet/webnet_wifi.c +++ b/projects/Edgi_Talk_M55_XiaoZhi/applications/xiaozhi/webnet/webnet_wifi.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "wifi_manager.h" #include "xiaozhi_ui.h" @@ -42,6 +43,10 @@ extern int ws_xiaozhi_init(void); static char s_result_buffer[RESULT_BUF_SIZE]; static rt_bool_t s_sta_connected = RT_FALSE; +/* AP display and runtime config */ +static char s_ap_ssid[33] = WIFI_AP_SSID; +static char s_ap_info_text[128] = "SSID: " WIFI_AP_SSID " 密码: " WIFI_AP_PASSWORD " IP:192.168.169.1"; + /* Temporary storage for current WiFi credentials */ static char s_saved_ssid[64] = {0}; static char s_saved_password[64] = {0}; @@ -51,6 +56,17 @@ static struct rt_wlan_info s_scan_result[MAX_SCAN_RESULTS]; static int s_scan_cnt = 0; static struct rt_wlan_info *s_scan_filter = RT_NULL; +static void wifi_ap_build_runtime_config(void) +{ + uint64_t uid = Cy_SysLib_GetUniqueId(); + rt_snprintf(s_ap_ssid, sizeof(s_ap_ssid), "%s-%06X", WIFI_AP_SSID, (rt_uint32_t)(uid & 0xFFFFFFU)); + rt_snprintf(s_ap_info_text, + sizeof(s_ap_info_text), + "SSID: %s 密码: %s IP:192.168.169.1", + s_ap_ssid, + WIFI_AP_PASSWORD); +} + /***************************************************************************** * Private Functions - Configuration *****************************************************************************/ @@ -377,6 +393,8 @@ static void start_ap_config_mode(void) { rt_err_t ret; + wifi_ap_build_runtime_config(); + /* Wait for WLAN device ready */ LOG_I("Waiting for WLAN device ready..."); for (int i = 0; i < 20; i++) /* Wait up to 10 seconds */ @@ -396,13 +414,13 @@ static void start_ap_config_mode(void) } /* Start AP */ - ret = rt_wlan_start_ap("RT-Thread-AP", "123456789"); + ret = rt_wlan_start_ap(s_ap_ssid, WIFI_AP_PASSWORD); if (ret != RT_EOK) { LOG_E("Start AP failed: %d", ret); return; } - LOG_I("AP Started -> SSID: RT-Thread-AP Password: 123456789"); + LOG_I("AP Started -> SSID: %s Password: %s", s_ap_ssid, WIFI_AP_PASSWORD); /* Wait for AP network interface ready */ rt_thread_mdelay(1000); @@ -414,6 +432,8 @@ static void start_ap_config_mode(void) webnet_cgi_register("wifi_connect", cgi_wifi_connect); webnet_cgi_register("wifi_scan", cgi_wifi_scan); + xiaozhi_ui_show_ap_config(s_ap_info_text); + LOG_I("=== WiFi Config Portal Ready ==="); LOG_I("Open browser -> http://192.168.169.1"); } @@ -557,9 +577,6 @@ void wifi_manager_init(void) /* Connection failed or no config, start AP config mode */ LOG_I("Starting AP config mode..."); - /* Show AP config info on UI */ - xiaozhi_ui_show_ap_config(); - start_ap_config_mode(); } diff --git a/projects/Edgi_Talk_M55_XiaoZhi/rtconfig.h b/projects/Edgi_Talk_M55_XiaoZhi/rtconfig.h index bf4e9849..842a74a8 100644 --- a/projects/Edgi_Talk_M55_XiaoZhi/rtconfig.h +++ b/projects/Edgi_Talk_M55_XiaoZhi/rtconfig.h @@ -3,7 +3,7 @@ /* RT-Thread Kernel */ -#define RT_NAME_MAX 8 +#define RT_NAME_MAX 20 #define RT_ALIGN_SIZE 8 #define RT_THREAD_PRIORITY_32 #define RT_THREAD_PRIORITY_MAX 32