1717#include <fcntl.h>
1818#include <sys/stat.h>
1919#include <cJSON.h>
20+ #include <cy_syslib.h>
2021#include "wifi_manager.h"
2122#include "xiaozhi_ui.h"
2223
@@ -42,6 +43,10 @@ extern int ws_xiaozhi_init(void);
4243static char s_result_buffer [RESULT_BUF_SIZE ];
4344static rt_bool_t s_sta_connected = RT_FALSE ;
4445
46+ /* AP display and runtime config */
47+ static char s_ap_ssid [33 ] = WIFI_AP_SSID ;
48+ static char s_ap_info_text [128 ] = "SSID: " WIFI_AP_SSID " 密码: " WIFI_AP_PASSWORD " IP:192.168.169.1" ;
49+
4550/* Temporary storage for current WiFi credentials */
4651static char s_saved_ssid [64 ] = {0 };
4752static char s_saved_password [64 ] = {0 };
@@ -51,6 +56,17 @@ static struct rt_wlan_info s_scan_result[MAX_SCAN_RESULTS];
5156static int s_scan_cnt = 0 ;
5257static struct rt_wlan_info * s_scan_filter = RT_NULL ;
5358
59+ static void wifi_ap_build_runtime_config (void )
60+ {
61+ uint64_t uid = Cy_SysLib_GetUniqueId ();
62+ rt_snprintf (s_ap_ssid , sizeof (s_ap_ssid ), "%s-%06X" , WIFI_AP_SSID , (rt_uint32_t )(uid & 0xFFFFFFU ));
63+ rt_snprintf (s_ap_info_text ,
64+ sizeof (s_ap_info_text ),
65+ "SSID: %s 密码: %s IP:192.168.169.1" ,
66+ s_ap_ssid ,
67+ WIFI_AP_PASSWORD );
68+ }
69+
5470/*****************************************************************************
5571 * Private Functions - Configuration
5672 *****************************************************************************/
@@ -377,6 +393,8 @@ static void start_ap_config_mode(void)
377393{
378394 rt_err_t ret ;
379395
396+ wifi_ap_build_runtime_config ();
397+
380398 /* Wait for WLAN device ready */
381399 LOG_I ("Waiting for WLAN device ready..." );
382400 for (int i = 0 ; i < 20 ; i ++ ) /* Wait up to 10 seconds */
@@ -396,13 +414,13 @@ static void start_ap_config_mode(void)
396414 }
397415
398416 /* Start AP */
399- ret = rt_wlan_start_ap ("RT-Thread-AP" , "123456789" );
417+ ret = rt_wlan_start_ap (s_ap_ssid , WIFI_AP_PASSWORD );
400418 if (ret != RT_EOK )
401419 {
402420 LOG_E ("Start AP failed: %d" , ret );
403421 return ;
404422 }
405- LOG_I ("AP Started -> SSID: RT-Thread-AP Password: 123456789" );
423+ LOG_I ("AP Started -> SSID: %s Password: %s" , s_ap_ssid , WIFI_AP_PASSWORD );
406424
407425 /* Wait for AP network interface ready */
408426 rt_thread_mdelay (1000 );
@@ -414,6 +432,8 @@ static void start_ap_config_mode(void)
414432 webnet_cgi_register ("wifi_connect" , cgi_wifi_connect );
415433 webnet_cgi_register ("wifi_scan" , cgi_wifi_scan );
416434
435+ xiaozhi_ui_show_ap_config (s_ap_info_text );
436+
417437 LOG_I ("=== WiFi Config Portal Ready ===" );
418438 LOG_I ("Open browser -> http://192.168.169.1" );
419439}
@@ -557,9 +577,6 @@ void wifi_manager_init(void)
557577 /* Connection failed or no config, start AP config mode */
558578 LOG_I ("Starting AP config mode..." );
559579
560- /* Show AP config info on UI */
561- xiaozhi_ui_show_ap_config ();
562-
563580 start_ap_config_mode ();
564581}
565582
0 commit comments