Skip to content

Commit b503ff6

Browse files
committed
芯片唯一ID拼接动态AP名称 + LVGL同步显示实际热点信息
1 parent 084ee4e commit b503ff6

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

projects/Edgi_Talk_M55_XiaoZhi/applications/xiaozhi/ui/xiaozhi_ui.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#define DBG_LVL DBG_INFO
2222
#include <rtdbg.h>
2323

24+
#define AP_INFO_DEFAULT_TEXT "SSID: RT-Thread-AP 密码: 123456789 IP:192.168.169.1"
25+
2426
#define EMOJI_NUM 18
2527
#define UI_MSG_DATA_SIZE 128
2628
#define UI_MSG_POOL_SIZE 10
@@ -449,7 +451,7 @@ static void ui_process_message(const ui_msg_t *msg)
449451
case UI_CMD_SHOW_AP_INFO:
450452
if (s_label_status) lv_label_set_text(s_label_status, "连接中...");
451453
if (s_label_info) lv_label_set_text(s_label_info, "使用手机或电脑连接热点");
452-
if (s_label_output) lv_label_set_text(s_label_output, "SSID: RT-Thread-AP 密码: 123456789 IP:192.168.169.1");
454+
if (s_label_output) lv_label_set_text(s_label_output, msg->data[0] ? msg->data : AP_INFO_DEFAULT_TEXT);
453455
break;
454456

455457
case UI_CMD_SHOW_CONNECTING:
@@ -654,9 +656,9 @@ void xiaozhi_ui_clear_info(void)
654656
ui_send_message(UI_CMD_CLEAR_INFO, RT_NULL, RT_NULL);
655657
}
656658

657-
void xiaozhi_ui_show_ap_config(void)
659+
void xiaozhi_ui_show_ap_config(const char *ap_info)
658660
{
659-
ui_send_message(UI_CMD_SHOW_AP_INFO, RT_NULL, RT_NULL);
661+
ui_send_message(UI_CMD_SHOW_AP_INFO, ap_info, AP_INFO_DEFAULT_TEXT);
660662
}
661663

662664
void xiaozhi_ui_show_connecting(void)

projects/Edgi_Talk_M55_XiaoZhi/applications/xiaozhi/ui/xiaozhi_ui.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ void xiaozhi_ui_clear_info(void);
7373

7474
/**
7575
* @brief Show AP config mode info on screen
76+
* @param ap_info AP info text, e.g. "SSID: xxx 密码: xxx IP:192.168.169.1"
7677
*/
77-
void xiaozhi_ui_show_ap_config(void);
78+
void xiaozhi_ui_show_ap_config(const char *ap_info);
7879

7980
/**
8081
* @brief Show connecting status (for auto-connect from saved config)

projects/Edgi_Talk_M55_XiaoZhi/applications/xiaozhi/webnet/webnet_wifi.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
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);
4243
static char s_result_buffer[RESULT_BUF_SIZE];
4344
static 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 */
4651
static char s_saved_ssid[64] = {0};
4752
static char s_saved_password[64] = {0};
@@ -51,6 +56,17 @@ static struct rt_wlan_info s_scan_result[MAX_SCAN_RESULTS];
5156
static int s_scan_cnt = 0;
5257
static 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

Comments
 (0)