使用ESP32-C3的SoftAP模式创建web服务器中的问题

renbingcheng
Posts: 11
Joined: Fri May 12, 2023 7:12 am

使用ESP32-C3的SoftAP模式创建web服务器中的问题

Postby renbingcheng » Tue Sep 05, 2023 1:41 am

我正在使用ESP32-C3的SoftAP模式创建web服务器,并使用手机连接到该热点。当手机连接成功并熄屏一段时间后,我发现手机可以连接上热点,但无法访问页面web页面。在此期间,ESP32-C3不输出任何日志,并且无法响应。问题只能通过重新启动ESP32-C3来解决。我使用的ESP-IDF版本是v4.4.3,手机是华为p30,系统hormany os 2.0.0.268。

现象细节:
手机成功连接到ESP32-C3的热点后熄屏。
一段时间后,手机可以连接上热点,但无法访问页面web页面。
ESP32-C3在此期间没有任何日志输出,表现为无响应。
问题只能通过重新启动ESP32-C3解决,重连热点无效。

我已附上了部分相关的代码和日志,并正在寻求任何可能的解决方案或建议。有没有人遇到过类似的问题?非常感谢大家的支持和帮助!

我的web server代码使用例程中的http_server->file_serving框架,相关代码如下:

Code: Select all

/* Send HTTP response with a run-time generated html consisting of
 * a list of all files and folders under the requested path.
 * In case of SPIFFS this returns empty list when path is any
 * string other than '/', since SPIFFS doesn't support directories */
static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath)
{
    char entrypath[FILE_PATH_MAX];
    char entrysize[16];
    const char *entrytype;

    struct dirent *entry;
    struct stat entry_stat;

    extern const unsigned char upload_script_en_start[] asm("_binary_page_en_html_start");
    extern const unsigned char upload_script_en_end[]   asm("_binary_page_en_html_end");
    extern const unsigned char upload_script_start[] asm("_binary_page_cn_html_start");
    extern const unsigned char upload_script_end[]   asm("_binary_page_cn_html_end");        

    const unsigned char *chosen_script_start;
    const unsigned char *chosen_script_end;

    if (english_model) {
        chosen_script_start = upload_script_en_start;
        chosen_script_end = upload_script_en_end;
    } else {
        chosen_script_start = upload_script_start;
        chosen_script_end = upload_script_end;        
    }

    const size_t upload_script_size = (chosen_script_end - chosen_script_start);

    /* Add file upload form and script which on execution sends a POST request to /upload */
    httpd_resp_send(req, (const char *)chosen_script_start, upload_script_size);

    return ESP_OK;
}
/* Handler to download a file kept on the server */
static esp_err_t download_get_handler(httpd_req_t *req)
{
    char filepath[FILE_PATH_MAX];
    FILE *fd = NULL;
    struct stat file_stat;

    const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path,
                                             req->uri, sizeof(filepath));
    if (!filename) {
        ESP_LOGE(TAG, "Filename is too long");
        /* Respond with 500 Inter
以下是log:

Code: Select all

I (3538) wifi_init: rx ba win: 6
I (3548) wifi_init: tcpip mbox: 32
I (3548) wifi_init: udp mbox: 6
I (3548) wifi_init: tcp mbox: 6
I (3558) wifi_init: tcp tx win: 5744
I (3558) wifi_init: tcp rx win: 5744
I (3568) wifi_init: tcp mss: 1440
I (3568) wifi_init: WiFi IRAM OP enabled
I (3578) wifi_init: WiFi RX IRAM OP enabled
I (3578) phy_init: phy_version 912,d001756,Jun  2 2022,16:28:07
I (3628) wifi:mode : softAP (68:b6:b3:ac:31:2d)
I (3628) wifi:Total power save buffer number: 16
I (3628) wifi:Init max length of beacon: 752/752
I (3628) wifi:Init max length of beacon: 752/752
I (3638) wifi softAP: wifi_init_softap finished. SSID:EG1155_Assistant password:12345678 channel:1
I (3638) file_server: Starting HTTP Server
uartsend_read_XML_info
g_xml_file_read_error
uartsend_read_XML_info
VbatRsmpH==100000
I (8125128) wifi:new:<1,1>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (8125128) wifi:station: 42:a3:bf:4c:c2:d3 join, AID=1, bgn, 40U   
I (8125158) wifi softAP: station 42:a3:bf:4c:c2:d3 join, AID=1
I (8126378) esp_netif_lwip: DHCP server assigned IP to a station, IP is: 192.168.4.2
W (8126778) wifi:<ba-add>idx:2 (ifx:1, 42:a3:bf:4c:c2:d3), tid:0, ssn:14, winSize:64
return http_resp_dir_html!
return http_resp_dir_html!
I (9760938) file_server: Requested URI: /favicon.ico
I (9762358) file_server: Requested URI: /favicon.ico
return icon!
return http_resp_dir_html!
I (9763948) file_server: Requested URI: /favicon.ico
return icon!
I (10151578) wifi:station: 42:a3:bf:4c:c2:d3 leave, AID = 1, bss_flags is 658531, bss:0x3fcb437c
I (10151578) wifi:new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
W (10151578) wifi:<ba-del>idx
I (10151578) wifi softAP: station 42:a3:bf:4c:c2:d3 leave, AID=1
I (10230878) wifi:new:<1,1>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (10230878) wifi:station: 42:a3:bf:4c:c2:d3 join, AID=1, bgn, 40U
I (10230908) wifi softAP: station 42:a3:bf:4c:c2:d3 join, AID=1
I (10231118) esp_netif_lwip: DHCP server assigned IP to a station, IP is: 192.168.4.2
W (10231808) wifi:<ba-add>idx:2 (ifx:1, 42:a3:bf:4c:c2:d3), tid:0, ssn:14, winSize:64
I (10366608) wifi:station: 42:a3:bf:4c:c2:d3 leave, AID = 1, bss_flags is 658547, bss:0x3fcb437c
I (10366608) wifi:new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (10366618) wifi softAP: station 42:a3:bf:4c:c2:d3 leave, AID=1
I (10394878) wifi:new:<1,1>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1     
I (10394878) wifi:station: 42:a3:bf:4c:c2:d3 join, AID=1, bgn, 40U
I (10394918) wifi softAP: station 42:a3:bf:4c:c2:d3 join, AID=1
I (10395098) esp_netif_lwip: DHCP server assigned IP to a station, IP is: 192.168.4.2
I (10396138) esp_netif_lwip: DHCP server assigned IP to a station, IP is: 192.168.4.2
W (10396768) wifi:<ba-add>idx:2 (ifx:1, 42:a3:bf:4c:c2:d3), tid:0, ssn:14, winSize:64
W (11211828) wifi:<ba-del>idx
W (11214648) wifi:<ba-add>idx:2 (ifx:1, 42:a3:bf:4c:c2:d3), tid:0, ssn:1238, winSize:64
I (11215818) wifi:station: 42:a3:bf:4c:c2:d3 leave, AID = 1, bss_flags is 658531, bss:0x3fcb437c
I (11215818) wifi:new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1     
W (11215818) wifi:<ba-del>idx
I (11215818) wifi softAP: station 42:a3:bf:4c:c2:d3 leave, AID=1

ESP_WangYX
Posts: 97
Joined: Mon Jun 28, 2021 12:48 pm

Re: 使用ESP32-C3的SoftAP模式创建web服务器中的问题

Postby ESP_WangYX » Tue Sep 05, 2023 2:08 am

可以使用电脑或者其他手机进行测试看看。现在的手机普通拥有外网访问检测机制,即默认不启用无法访问外部网站的热点。

renbingcheng
Posts: 11
Joined: Fri May 12, 2023 7:12 am

Re: 使用ESP32-C3的SoftAP模式创建web服务器中的问题

Postby renbingcheng » Tue Sep 05, 2023 6:57 am

不行,感觉这是一个现象,在手机连接成功并熄屏一段时间后重新打开锁屏继续使用,所有设备可以连接上热点,但都无法访问页面web页面,无论是手机还是电脑。熄屏时间大概十几分钟
Last edited by renbingcheng on Tue Sep 05, 2023 10:32 am, edited 1 time in total.

renbingcheng
Posts: 11
Joined: Fri May 12, 2023 7:12 am

Re: 使用ESP32-C3的SoftAP模式创建web服务器中的问题

Postby renbingcheng » Tue Sep 05, 2023 10:32 am

ESP_WangYX wrote:
Tue Sep 05, 2023 2:08 am
可以使用电脑或者其他手机进行测试看看。现在的手机普通拥有外网访问检测机制,即默认不启用无法访问外部网站的热点。
不行,感觉这是一个现象,在手机连接成功并熄屏一段时间后重新打开锁屏继续使用,所有设备可以连接上热点,但都无法访问页面web页面,无论是手机还是电脑。熄屏时间大概十几分钟

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

Re: 使用ESP32-C3的SoftAP模式创建web服务器中的问题

Postby ESP_YJM » Mon Sep 11, 2023 8:00 am

从日志看息屏后重连热点,并访问网页,日志里只有手机连上热点,设备给手机分配 IP 的日志,没有看到手机访问 http server 的日志。你可以打开 LWIP 层 IP 层日志看下,看手机有没有访问设备。

renbingcheng
Posts: 11
Joined: Fri May 12, 2023 7:12 am

Re: 使用ESP32-C3的SoftAP模式创建web服务器中的问题

Postby renbingcheng » Mon Sep 11, 2023 8:06 am

ESP_YJM wrote:
Mon Sep 11, 2023 8:00 am
从日志看息屏后重连热点,并访问网页,日志里只有手机连上热点,设备给手机分配 IP 的日志,没有看到手机访问 http server 的日志。你可以打开 LWIP 层 IP 层日志看下,看手机有没有访问设备。
现象是手机连接ap之后无法访问http server,也没有相关日志。
我现在发现是由于ap断开连接之后,http server占用的stack没有被清除,导致反复连接之后,给http server分配的stack被占满,从而无法访问,请问我该怎么办。

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

Re: 使用ESP32-C3的SoftAP模式创建web服务器中的问题

Postby ESP_YJM » Wed Sep 13, 2023 2:34 am

你怎么发现的?有日志吗?

Who is online

Users browsing this forum: No registered users and 33 guests