esp32-c3 TCP/IP通讯,接收慢

ddddhh
Posts: 3
Joined: Wed Feb 01, 2023 7:19 am

esp32-c3 TCP/IP通讯,接收慢

Postby ddddhh » Wed Feb 01, 2023 8:00 am

IDF版本V4.3.1(事实上V4.3.4也一样的),现象:1,使用TCP或UDP通讯时,接收数据很慢,最长延时1s,有时候又很快,感觉刚好卡在某个时间点就快。2,数据量很小,几个字节。3,发送几乎没有延时。4,使用网络ping,平均4ms。有几点需要说明:1,我的代码是在esp32 d0wd v3一直量产使用的,没有这个问题。2,更换使用v4.3.1\examples\protocols\sockets\tcp_server例程,也是同样问题。3,硬件使用自己设计主板,芯片ESP32-C3,和NodeMCU ESP-C3-13/13U-Kit(板载安信可ESP-C3-13,芯片C3FN4),两个硬件平台上,均表现一致。

以下为tcp server例程启动:

ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0x1 (POWERON),boot:0xc (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x1778
load:0x403ce000,len:0x8dc
load:0x403d0000,len:0x2984
entry 0x403ce000
[0;32mI (30) boot: ESP-IDF v4.3.1-dirty 2nd stage bootloader[0m
[0;32mI (30) boot: compile time 09:20:54[0m
[0;32mI (30) boot: chip revision: 3[0m
[0;32mI (33) boot.esp32c3: SPI Speed : 80MHz[0m
[0;32mI (37) boot.esp32c3: SPI Mode : DIO[0m
[0;32mI (42) boot.esp32c3: SPI Flash Size : 2MB[0m
[0;32mI (47) boot: Enabling RNG early entropy source...[0m
[0;32mI (52) boot: Partition Table:[0m
[0;32mI (56) boot: ## Label Usage Type ST Offset Length[0m
[0;32mI (63) boot: 0 nvs WiFi data 01 02 00009000 00006000[0m
[0;32mI (70) boot: 1 phy_init RF data 01 01 0000f000 00001000[0m
[0;32mI (78) boot: 2 factory factory app 00 00 00010000 00100000[0m
[0;32mI (85) boot: En
d of partition table[0m
[0;32mI (89) esp_image: segment 0: paddr=00010020 vaddr=3c080020 size=140c0h ( 82112) map[0m
[0;32mI (110) esp_image: segment 1: paddr=000240e8 vaddr=3fc8dc00 size=03140h ( 12608) load[0m
[0;32mI (113) esp_image: segment 2: paddr=00027230 vaddr=40380000 size=08de8h ( 36328) load[0m
[0;32mI (123) esp_image: segment 3: paddr=00030020 vaddr=42000020 size=7ac68h (502888) map[0m

[0;32mI (200) esp_image: segment 4: paddr=000aac90 vaddr=40388de8 size=04c18h ( 19480) load[0m
[0;32mI (204) esp_image: segment 5: paddr=000af8b0 vaddr=50000000 size=00010h ( 16) load[0m
[0;32mI (210) boot: Loaded app from partition at offset 0x10000[0m
[0;32mI (212) boot: Disabling RNG early entropy source...[0m
[0;32mI (228) cpu_start: Pro cpu up.[0m
[0;32mI (241) cpu_start: Pro cpu start user code[0m
[0;32mI (241) cpu_start: cpu freq: 160000000[0m
[0;32mI (241) cpu_start: Application information:[0m
[0;32mI (244) cpu_start: Project name: tcp_server[0m
[0;32mI (249) cpu_start: App version: 1[0m
[0;32mI (253) cpu_start: Compile time: Jan 18 2023 12:22:31[0m
[0;32mI (259) cpu_start: ELF file SHA256: 2b4dfc118119d540...[0m
[0;32mI (265) cpu_start: ESP-IDF: v4.3.1-dirty[0m
[0;32mI (271) heap_init: Initializing. RAM available for dynamic allocation:[0m
[0;32mI (278) heap_init: At 3FC94DC0 len 0002B240 (172 KiB): DRAM[0m
[0;32mI (284) heap_in
it: At 3FCC0000 len 0001F060 (124 KiB): STACK/DRAM[0m
[0;32mI (291) heap_init: At 50000010 len 00001FF0 (7 KiB): RTCRAM[0m
[0;32mI (298) spi_flash: detected chip: generic[0m
[0;32mI (302) spi_flash: flash io: dio[0m
[0;33mW (306) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.[0m
[0;32mI (319) sleep: Configure to isolate all GPIO pins in sleep state[0m
[0;32mI (326) sleep: Enable automatic switching of GPIO sleep configuration[0m
[0;32mI (333) cpu_start: Starting scheduler.[0m
[0;32mI (341) pp: pp rom version: 9387209[0m
[0;32mI (341) net80211: net80211 rom version: 9387209[0m
I (351) wifi:wifi driver task: 3fc9e024, prio:23, stack:6656, core=0
[0;32mI (351) system_api: Base MAC address is not set[0m
[0;32mI (361) system_api: read default base MAC address from EFUSE[0m
I (361) wifi:wifi firmware version: 88c8747
I (371) wifi:wifi certification version: v7.0
I (371) wifi:config NVS flash: en
abled
I (371) wifi:config nano formating: disabled
I (381) wifi:Init data frame dynamic rx buffer num: 32
I (381) wifi:Init management frame dynamic rx buffer num: 32
I (391) wifi:Init management short buffer num: 32
I (391) wifi:Init dynamic tx buffer num: 32
I (401) wifi:Init static tx FG buffer num: 2
I (401) wifi:Init static rx buffer size: 1600
I (401) wifi:Init static rx buffer num: 10
I (411) wifi:Init dynamic rx buffer num: 32
[0;32mI (411) wifi_init: rx ba win: 6[0m
[0;32mI (421) wifi_init: tcpip mbox: 32[0m
[0;32mI (421) wifi_init: udp mbox: 6[0m
[0;32mI (421) wifi_init: tcp mbox: 6[0m
[0;32mI (431) wifi_init: tcp tx win: 5744[0m
[0;32mI (431) wifi_init: tcp rx win: 5744[0m
[0;32mI (441) wifi_init: tcp mss: 1440[0m
[0;32mI (441) wifi_init: WiFi IRAM OP enabled[0m
[0;32mI (441) wifi_init: WiFi RX IRAM OP enabled[0m
[0;32mI (451) example_connect: Connecting to qixin...[0m
[0;32mI (451) phy_init: phy_version 500,985899c,Apr 19 2021,16:05:08[0m

I (591) wifi:set rx active PTI: 0, rx ack PTI: 0, and default PTI: 0
I (591) wifi:mode : sta (84:f7:03:3a:6e:fc)
I (591) wifi:enable tsf
[0;32mI (591) example_connect: Waiting for IP(s)[0m

I (2641) wifi:new:<2,1>, old:<1,0>, ap:<255,255>, sta:<2,1>, prof:1

I (3211) wifi:state: init -> auth (b0)
I (3241) wifi:state: auth -> assoc (0)
I (3251) wifi:state: assoc -> run (10)

I (3351) wifi:connected with qixin, aid = 11, channel 2, 40U, bssid = a8:02:db:e0:86:3e
I (3351) wifi:security: WPA2-PSK, phy: bgn, rssi: -30
I (3361) wifi:pm start, type: 1

I (3361) wifi:set rx beacon pti, rx_bcn_pti: 0, bcn_timeout: 0, mt_pti: 25000, mt_time: 10000

I (3441) wifi:BcnInt:102400, DTIM:1

[0;32mI (5341) example_connect: Got IPv6 event: Interface "example_connect: sta" address: fe80:0000:0000:0000:86f7:03ff:fe3a:6efc, type: ESP_IP6_ADDR_IS_LINK_LOCAL[0m

W (5441) wifi:<ba-add>idx:0 (ifx:0, a8:02:db:e0:86:3e), tid:0, ssn:2, winSize:64

[0;32mI (6341) esp_netif_handlers: example_connect: sta ip: 192.168.2.43, mask: 255.255.255.0, gw: 192.168.2.1[0m
[0;32mI (6341) example_connect: Got IPv4 event: Interface "example_connect: sta" address: 192.168.2.43[0m
[0;32mI (6341) example_connect: Connected to example_connect: sta[0m
[0;32mI (6351) example_connect: - IPv4 address: 192.168.2.43[0m
[0;32mI (6361) example_connect: - IPv6 address: fe80:0000:0000:0000:86f7:03ff:fe3a:6efc, type: ESP_IP6_ADDR_IS_LINK_LOCAL[0m
[0;32mI (6371) example: Socket created[0m
[0;32mI (6371) example: Socket bound, port 8000[0m
[0;32mI (6381) example: Socket listening[0m

[0;32mI (16041) example: Socket accepted ip address: 192.168.2.100[0m

[0;32mI (18901) example: Received 9 bytes: 123456789[0m

[0;32mI (20161) example: Received 9 bytes: 123456789[0m

[0;32mI (22391) example: Received 9 bytes: 123456789[0m

[0;32mI (24331) example: Received 9 bytes: 123456789[0m

[0;32mI (26481) example: Received 9 bytes: 123456789[0m

[0;33mW (30991) example: Connection closed[0m
[0;32mI (30991) example: Socket listening[0m

以下为收发数据:
QQ截图20230201154550.jpg
QQ截图20230201154550.jpg (32.62 KiB) Viewed 3237 times
以下是ping测试网络延时(在我的硬件主板上,延时更低):
ping.jpg
ping.jpg (29.06 KiB) Viewed 3237 times

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

Re: esp32-c3 TCP/IP通讯,接收慢

Postby ESP_YJM » Thu Feb 02, 2023 2:53 am

你试一下把 wifi 的 power save 关了,esp_wifi_set_ps(0),可以打印下返回值看看有没有生效。对于 TCP,你可以设置 socket option TCP_NODELAY.
如果这个试了还不行,你把 wifi 的 RX,TX AMPDU 也关了,通过 menuconfig(Component config->Wi-Fi->WiFi AMPDU TX/RX)

ddddhh
Posts: 3
Joined: Wed Feb 01, 2023 7:19 am

Re: esp32-c3 TCP/IP通讯,接收慢

Postby ddddhh » Thu Feb 02, 2023 7:36 am

ESP_YJM wrote:
Thu Feb 02, 2023 2:53 am
你试一下把 wifi 的 power save 关了,esp_wifi_set_ps(0),可以打印下返回值看看有没有生效。对于 TCP,你可以设置 socket option TCP_NODELAY.
如果这个试了还不行,你把 wifi 的 RX,TX AMPDU 也关了,通过 menuconfig(Component config->Wi-Fi->WiFi AMPDU TX/RX)
1, 在我的代码中已经设置:esp_wifi_set_ps(WIFI_PS_NONE); //不省电模式
2, TCP也是设置了NODELAY:
int opt=1;

if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
ESP_LOGE(TAG, "tcp server socket create fail");
goto _exit0;
}

if(-1 == setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (const void *)&opt, sizeof(int)))
{
ESP_LOGI(TAG, "In Socket Set TCP_NODELAY error!");
goto _exit0;
}

3, AMPDU 默认是使能了,晚些关了试试再给您回复。我没有仔细了解过这个设置的作用,但我疑惑为什么在esp32 d0wd上运行没有问题,这个芯片上也是使能了此项。

ddddhh
Posts: 3
Joined: Wed Feb 01, 2023 7:19 am

Re: esp32-c3 TCP/IP通讯,接收慢

Postby ddddhh » Sat Feb 04, 2023 7:50 am

ESP_YJM wrote:
Thu Feb 02, 2023 2:53 am
你试一下把 wifi 的 power save 关了,esp_wifi_set_ps(0),可以打印下返回值看看有没有生效。对于 TCP,你可以设置 socket option TCP_NODELAY.
如果这个试了还不行,你把 wifi 的 RX,TX AMPDU 也关了,通过 menuconfig(Component config->Wi-Fi->WiFi AMPDU TX/RX)
关闭AMPDU,测试很成功,除了网络本身延时,基本没有多余的延时。
但由此产生了两个疑惑:
1,为何之前在ESP32-D0WD上面也是使能状态,但没有这个问题?难道因为它处理器速度快?
2,这个功能的关闭,对数据传输有何影响?我在IDF编程指南搜索AMPDU,几乎没有相关介绍。我准备将以前量产的ESP32D0WD代码转移到ESP32C3继续量产,担心到时候出现大批量问题。

Who is online

Users browsing this forum: No registered users and 53 guests