bcn_timout造成重启

ninesuntj
Posts: 3
Joined: Wed Mar 31, 2021 6:14 am

bcn_timout造成重启

Postby ninesuntj » Wed Mar 31, 2021 12:22 pm

麻烦请教一个问题,我现在用的esp-idf是最新的版本,用的模块是ESP32-WROOM,我的应用同时支持蓝牙和OTA升级,主要的任务是通过http的post请求一个服务器然后取回数据,现在的工作模式是发送post请求,然后得到请求回复,解析数据以后一秒钟发送下一次请求。我的程序结构和peform stream read 类似:大概是如下一个结构:
while(1)
{
esp_http_client_init()
esp_http_client_open();
esp_http_client_write();
esp_http_client_fetch_headers()
esp_http_client_read()
解析数据
esp_http_client_close();
esp_http_client_cleanup();
}
这样反复循环,开始能够正常收到数据循环,大概120次左右esp32就会重启,出现的log输出:

D (185942) HTTP_CLIENT: Begin connect to: http://192.168.1.110:80
D (185942) esp-tls: host:192.168.1.110: strlen 13
D (185942) esp-tls: [sock=54] Resolved IPv4 address: 192.168.1.110
D (185952) esp-tls: [sock=54] Connecting to server. HOST: 192.168.1.110, Port: 80
D (185992) esp-tls: non-tls connection established
D (185992) HTTP_CLIENT: Write header[4]: POST /mqtt/handlers/httpserver.ashx HTTP/1.1
User-Agent: ESP32 HTTP Client/1.0
Host: 192.168.1.110
Content-Type: application/json
Content-Length: 78


D (194362) HTTP_CLIENT: Begin connect to: http://192.168.1.110:80
D (194362) esp-tls: host:192.168.1.110: strlen 13
D (194372) esp-tls: [sock=54] Resolved IPv4 address: 192.168.1.110
D (194372) esp-tls: [sock=54] Connecting to server. HOST: 192.168.1.110, Port: 80
D (194692) esp-tls: non-tls connection established
D (194702) HTTP_CLIENT: Write header[4]: POST /mqtt/handlers/httpserver.ashx HTTP/1.1
User-Agent: ESP32 HTTP Client/1.0
Host: 192.168.1.110
Content-Type: application/json
Content-Length: 78


I (202332) wifi:
  1. bcn_timout,ap_probe_send_start
D (202362) HTTP_CLIENT: Begin connect to: http://192.168.1.110:80
D (202362) esp-tls: host:192.168.1.110: strlen 13
D (202362) esp-tls: [sock=54] Resolved IPv4 address: 192.168.1.110
D (202372) esp-tls: [sock=54] Connecting to server. HOST: 192.168.1.110, Port: 80
D (202722) esp-tls: non-tls connection established
D (202722) HTTP_CLIENT: Write header[4]: POST /mqtt/handlers/httpserver.ashx HTTP/1.1
User-Agent: ESP32 HTTP Client/1.0
Host: 192.168.1.110
Content-Type: application/json
Content-Length: 78


I (204842) wifi:ap_probe_send over, resett wifi status to disassoc
I (204842) wifi:state: run -> init (c800)
I (204842) wifi:pm stop, total sleep time: 145908275 us / 200493962 us

W (204842) wifi:<ba-del>idx
W (204852) wifi:<ba-del>idx
I (204852) wifi:new:<6,0>, old:<6,2>, ap:<255,255>, sta:<6,2>, prof:1
D (204862) event: running post WIFI_EVENT:5 with handler 0x4014907c and context 0x3ffdf2c0 on loop 0x3ffcdaf0
0x4014907c: wifi_default_action_sta_disconnected at xxxxx/esp-idf/components/esp_wifi/src/wifi_default.c:107

D (204862) esp_netif_handlers: esp_netif action disconnected with netif0x3ffdf044 from event_id=5
D (204872) esp_netif_lwip: check: remote, if=0x3ffdf044 fn=0x4013e354
0x4013e354: esp_netif_down_api at xxxx/esp-idf/components/esp_netif/lwip/esp_netif_lwip.c:1226


D (204882) esp_netif_lwip: esp_netif_down_api esp_netif:0x3ffdf044
E (204892) TRANSPORT_BASE: esp_tls_conn_write error, errno=Software caused connection abort
D (204892) esp_netif_lwip: esp_netif_dhcpc_cb lwip-netif:0x3ffdf0a4
E (204902) HTTP_CLIENT: Error write request
D (204902) esp_netif_lwip: esp_netif_start_ip_lost_timer esp_netif:0x3ffdf044
D (204912) esp_netif_lwip: if0x3ffdf044 start ip lost tmr: interval=120
D (204922) esp_netif_lwip: esp_netif_start_ip_lost_timer esp_netif:0x3ffdf044
D (204932) esp_netif_lwip: if0x3ffdf044 start ip lost tmr: already started
D (204932) esp_netif_lwip: check: local, if=0x3ffdf044 fn=0x4013eb38
0x4013eb38: esp_netif_update_default_netif_lwip at xxxxxx/esp-idf/components/esp_netif/lwip/esp_netif_lwip.c:174


D (204942) esp_netif_lwip: esp_netif_update_default_netif_lwip 0x3ffdf044
D (204952) esp_netif_lwip: call api in lwip: ret=0x0, give sem
D (204952) event: running post WIFI_EVENT:5 with handler 0x400de130 and context 0x3ffdf384 on loop 0x3ffcdaf0
0x400de130: on_wifi_disconnect at /home/niexuzhong/esp-idf/examples/ota/build/../main/wifi.c:245

I (204962) WiFi Station: Wi-Fi disconnected, trying to reconnect...
I (204972) HTTP_CLIENT: open socket error
I (204982) wifi:new:<6,2>, old:<6,0>, ap:<255,255>, sta:<6,2>, prof:1
I (204982) wifi:state: init -> auth (b0)
D (204982) HTTP_CLIENT: Begin connect to: http://192.168.1.110:80
D (204992) esp-tls: host:192.168.1.110: strlen 13
D (205002) esp-tls: [sock=54] Resolved IPv4 address: 192.168.1.110
D (205002) esp-tls: [sock=54] Connecting to server. HOST: 192.168.1.110, Port: 80
E (205012) esp-tls: [sock=54] connect() error: Host is unreachable
E (205022) esp-tls: Failed to open new connection
E (205022) TRANSPORT_BASE: Failed to open a new connection
E (205032) HTTP_CLIENT: Connection failed, sock < 0
I (205032) HTTP_CLIENT: open socket error
D (205042) HTTP_CLIENT: Begin connect to: http://192.168.1.110:80
E (205042) esp-tls: empty esp_tls parameter
E (205052) esp-tls: Failed to open new connection
E (205062) TRANSPORT_BASE: Failed to open a new connection
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.

Core 0 register dump:
PC : 0x401af1d7 PS : 0x00060930 A0 : 0x801af218 A1 : 0x3ffbc2d0
我在网上搜索一下,发现可能是内存不够了,造成这个bcn_timout,ap_probe_send_start错误,现在的问题是我一秒钟post一次,这样重启的太频繁了,请问有什么建议可以改善重启?

ESP_Gargamel
Posts: 786
Joined: Wed Nov 14, 2018 8:45 am

Re: bcn_timout造成重启

Postby ESP_Gargamel » Wed Mar 31, 2021 12:38 pm

1、你在 while 循环里,加一个 esp_get_free_heap_size 来获取剩余内存,看内存是否有在持续减少;
2、你可以通过 menuconfig,把 WiFi 的 debug log 放开;
3、如果不使用蓝牙,是否有问题?
4、换个路由是否有问题?
5、能否用最新的 release 版本做测试?master 版本未必是最稳定的。

ninesuntj
Posts: 3
Joined: Wed Mar 31, 2021 6:14 am

Re: bcn_timout造成重启

Postby ninesuntj » Tue Apr 06, 2021 12:54 am

按照您的建议,我关闭了蓝牙,使能了wifi debug,增加了esp_get_free_internal_heap_size,根据 占用堆的大小,输出也不是一直增长的,是有变化的,在bcn_timout后log如下:

I (254523) wifi:bcn_timout,ap_probe_send_start
I (254553) HTTP_CLIENT: take memory is 23088
D (254553) HTTP_CLIENT: Begin connect to: http://192.168.1.110:80
D (254553) esp-tls: host:192.168.1.110: strlen 13
D (254563) esp-tls: [sock=54] Resolved IPv4 address: 192.168.1.110
D (254563) esp-tls: [sock=54] Connecting to server. HOST: 192.168.1.110, Port: 80
D (257953) esp-tls: non-tls connection established
D (257953) HTTP_CLIENT: Write header[4]: POST /mqtt/handlers/httpserver.ashx HTTP/1.1
User-Agent: ESP32 HTTP Client/1.0
Host: 192.168.1.110
Content-Type: application/json
Content-Length: 78


I (263973) HTTP_CLIENT: take memory is 22396
D (263973) HTTP_CLIENT: Begin connect to: http://192.168.1.110:80
D (263973) esp-tls: host:192.168.1.110: strlen 13
D (263983) esp-tls: [sock=54] Resolved IPv4 address: 192.168.1.110
D (263983) esp-tls: [sock=54] Connecting to server. HOST: 192.168.1.110, Port: 80
I (266943) wifi:bcn_timout,ap_probe_send_start
E (268993) esp-tls: [sock=54] select() timeout
E (268993) esp-tls: Failed to open new connection
E (268993) TRANSPORT_BASE: Failed to open a new connection
E (268993) HTTP_CLIENT: Connection failed, sock < 0
I (269003) HTTP_CLIENT: open socket error
I (269003) HTTP_CLIENT: take memory is 23580
D (269013) HTTP_CLIENT: Begin connect to: http://192.168.1.110:80
D (269013) esp-tls: host:192.168.1.110: strlen 13
D (269023) esp-tls: [sock=54] Resolved IPv4 address: 192.168.1.110
D (269023) esp-tls: [sock=54] Connecting to server. HOST: 192.168.1.110, Port: 80
E (274033) esp-tls: [sock=54] select() timeout
E (274033) esp-tls: Failed to open new connection
E (274033) TRANSPORT_BASE: Failed to open a new connection
E (274033) HTTP_CLIENT: Connection failed, sock < 0
I (274043) HTTP_CLIENT: open socket error
I (274043) HTTP_CLIENT: take memory is 21204
D (274053) HTTP_CLIENT: Begin connect to: http://192.168.1.110:80
D (274053) esp-tls: host:192.168.1.110: strlen 13
E (274063) esp-tls: couldn't get hostname for :192.168.1.110: getaddrinfo() returns 203, addrinfo=0x0
E (274073) esp-tls: Failed to open new connection
E (274073) TRANSPORT_BASE: Failed to open a new connection
E (274083) HTTP_CLIENT: Connection failed, sock < 0
I (274083) HTTP_CLIENT: open socket error

abort() was called at PC 0x40083377 on core 0
0x40083377: lock_init_generic at /home/niexuzhong/esp-idf/components/newlib/locks.c:74

至于路由器曾经在多个路由器上试过,结果都是一样的,另外我试过用http_client的测试程序,把结构程序改成和我应用相似的,在同样的路由器和相同软件版本下可以稳定运行。出现bcn_timout的概率很小,基本没有。由此应该可以排除路由器的影响,软件的版本我会尽快用一个release版测试一下。
谢谢!

heke8861
Posts: 6
Joined: Thu Oct 13, 2022 6:03 am

Re: bcn_timout造成重启

Postby heke8861 » Thu Oct 13, 2022 6:18 am

请问解决了吗 是怎么解决的呢

Who is online

Users browsing this forum: No registered users and 29 guests