espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.78k stars 7.44k forks source link

WiFi softAP extremely slow #6706

Open rtrbt opened 2 years ago

rtrbt commented 2 years ago

Board

ESP32-Ethernet-Kit V1.2, Tinkerforge ESP32 Brick (all flashed as ESP32 Dev Module)

Device Description

ESP32 Ethernet Kit: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/hw-reference/esp32/get-started-ethernet-kit.html#get-started-esp32-ethernet-kit-v1-2

ESP32 Brick: https://www.tinkerforge.com/en/doc/Hardware/Bricks/ESP32_Brick.html ESP32 Ethernet Brick: https://www.tinkerforge.com/en/doc/Hardware/Bricks/ESP32_Ethernet_Brick.html

Hardware Configuration

Nothing else is attached to the boards.

Version

other

IDE Name

Arduino IDE

Operating System

Arch Linux

Flash frequency

80 MHz

PSRAM enabled

no

Upload speed

921600

Description

The WiFi performance of clients connected to an ESP running as softAP is extremely bad in my tests. I'm using the following test setup:

Both clients are connected to the access point, one runs as Iperf server, one as client with the following results: (Server)

iperf> sta yourAP yourPassword
I (71521) cmd_wifi: sta connecting to 'yourAP'
I (73029) esp_netif_handlers: sta ip: 192.168.4.2, mask: 255.255.255.0, gw: 192.168.4.1
iperf> iperf -s -i 3
I (112400) cmd_wifi: mode=tcp-server sip=192.168.4.2:5001, dip=0.0.0.0:5001, interval=3, time=30
I (112402) iperf: Socket created
iperf> W (123592) wifi:<ba-add>idx:0 (ifx:0, c4:dd:57:b8:16:e9), tid:0, ssn:0, winSize:64
I (123606) iperf: accept: 192.168.4.3,54260

        Interval Bandwidth
   0-   3 sec       0.03 Mbits/sec
   3-   6 sec       0.02 Mbits/sec
   6-   9 sec       0.02 Mbits/sec
   9-  12 sec       0.02 Mbits/sec
  12-  15 sec       0.01 Mbits/sec
  15-  18 sec       0.01 Mbits/sec
  18-  21 sec       0.01 Mbits/sec
  21-  24 sec       0.02 Mbits/sec
  24-  27 sec       0.01 Mbits/sec
  27-  30 sec       0.01 Mbits/sec
   0-  30 sec       0.02 Mbits/sec
I (153688) iperf: TCP Socket server is closed.

(Client; note that the connection error after 30 seconds happens only because the server iperf command misses -t 30)

iperf> sta yourAP yourPassword
I (26924) cmd_wifi: sta connecting to 'yourAP'
I (28530) esp_netif_handlers: sta ip: 192.168.4.3, mask: 255.255.255.0, gw: 192.168.4.1
iperf> iperf -c 192.168.4.2 -i 3 -t 60
I (70414) cmd_wifi: mode=tcp-client sip=192.168.4.3:5001, dip=192.168.4.2:5001, interval=3, time=60
W (70508) wifi:<ba-add>idx:0 (ifx:0, c4:dd:57:b8:16:e9), tid:0, ssn:0, winSize:64
                                                                                                                                                                                                                  I (70522) iperf: Successfully connected

        Interval Bandwidth
iperf>    0-   3 sec       0.17 Mbits/sec
   3-   6 sec       0.00 Mbits/sec
   6-   9 sec       0.04 Mbits/sec
   9-  12 sec       0.00 Mbits/sec
  12-  15 sec       0.04 Mbits/sec
  15-  18 sec       0.00 Mbits/sec
  18-  21 sec       0.00 Mbits/sec
  21-  24 sec       0.00 Mbits/sec
  24-  27 sec       0.04 Mbits/sec
  27-  30 sec       0.00 Mbits/sec
W (103478) iperf: tcp client send error, error code: 104, reason: Connection reset by peer
I (103480) iperf: tcp client send error

I (103491) iperf: TCP Socket client is closed.
I (103491) iperf: iperf exit

If I run exactly the same test, but don't use the arduino-esp32 WiFiAccessPoint example, but instead the ESP-IDF 4.4.1 wifi/getting_started/softAP example https://github.com/espressif/esp-idf/tree/master/examples/wifi/getting_started/softAP the throughput is still not great, but way better than before: (Server)

iperf> sta myssid mypassword
I (11517) cmd_wifi: sta connecting to 'myssid'
I (13029) esp_netif_handlers: sta ip: 192.168.4.2, mask: 255.255.255.0, gw: 192.168.4.1
iperf> iperf -s -i 3
I (27293) cmd_wifi: mode=tcp-server sip=192.168.4.2:5001, dip=0.0.0.0:5001, interval=3, time=30
I (27295) iperf: Socket created
iperf> W (40402) wifi:<ba-add>idx:0 (ifx:0, c4:dd:57:b8:16:e9), tid:0, ssn:0, winSize:64
I (40409) iperf: accept: 192.168.4.3,57407

        Interval Bandwidth
   0-   3 sec       0.53 Mbits/sec
   3-   6 sec       6.85 Mbits/sec
   6-   9 sec       2.86 Mbits/sec
   9-  12 sec       0.22 Mbits/sec
  12-  15 sec       0.27 Mbits/sec
  15-  18 sec       0.38 Mbits/sec
  18-  21 sec       0.33 Mbits/sec
  21-  24 sec       0.39 Mbits/sec
  24-  27 sec       0.28 Mbits/sec
  27-  30 sec       0.44 Mbits/sec
   0-  30 sec       1.26 Mbits/sec
I (70708) iperf: TCP Socket server is closed.
I (70709) iperf: iperf exit

(Client; TCP error for the same reason as above)

iperf> sta myssid mypassword
I (15559) cmd_wifi: sta connecting to 'myssid'
I (17029) esp_netif_handlers: sta ip: 192.168.4.3, mask: 255.255.255.0, gw: 192.168.4.1
iperf> iperf -c 192.168.4.2 -i 3 -t 60
I (39321) cmd_wifi: mode=tcp-client sip=192.168.4.3:5001, dip=192.168.4.2:5001, interval=3, time=60
iperf> W (39536) wifi:<ba-add>idx:0 (ifx:0, c4:dd:57:b8:16:e9), tid:0, ssn:0, winSize:64
I (39545) iperf: Successfully connected

        Interval Bandwidth
   0-   3 sec       0.66 Mbits/sec
   3-   6 sec       6.90 Mbits/sec
   6-   9 sec       2.84 Mbits/sec
   9-  12 sec       0.17 Mbits/sec
  12-  15 sec       0.31 Mbits/sec
  15-  18 sec       0.39 Mbits/sec
  18-  21 sec       0.31 Mbits/sec
  21-  24 sec       0.39 Mbits/sec
  24-  27 sec       0.31 Mbits/sec
  27-  30 sec       0.39 Mbits/sec
W (70051) iperf: tcp client send error, error code: 104, reason: Connection reset by peer
I (70052) iperf: tcp client send error

I (70063) iperf: TCP Socket client is closed.
I (70064) iperf: iperf exit

If I use another Tinkerforge ESP32 Brick or ESP32 Ethernet Brick, as the softAP (instead of the ESP Ethernet Kit by Espressif), the performance stays the same.

If I use two linux PCs as Iperf server and client, both connected to a ESP softAP, the performance is as follows: (Running the ESP-IDF softAP example)

$ iperf -s -i 3
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size:  128 KByte (default)
------------------------------------------------------------
[  1] local 192.168.4.2 port 5001 connected with 192.168.4.3 port 46338 (icwnd/mss/irtt=14/1448/3960)
[ ID] Interval       Transfer     Bandwidth
[  1] 0.0000-3.0000 sec  7.97 MBytes  22.3 Mbits/sec
[  1] 3.0000-6.0000 sec  7.89 MBytes  22.1 Mbits/sec
[  1] 6.0000-9.0000 sec  7.95 MBytes  22.2 Mbits/sec
[  1] 9.0000-12.0000 sec  8.18 MBytes  22.9 Mbits/sec
[  1] 12.0000-15.0000 sec  6.70 MBytes  18.7 Mbits/sec
[  1] 15.0000-18.0000 sec  8.04 MBytes  22.5 Mbits/sec
[  1] 18.0000-21.0000 sec  7.95 MBytes  22.2 Mbits/sec
[  1] 21.0000-24.0000 sec  8.66 MBytes  24.2 Mbits/sec
[  1] 24.0000-27.0000 sec  8.17 MBytes  22.9 Mbits/sec
[  1] 27.0000-30.0000 sec  8.45 MBytes  23.6 Mbits/sec
[  1] 0.0000-30.1010 sec  80.3 MBytes  22.4 Mbits/sec

(Running the arduino-esp32 softAP example)

$ iperf -s -i 3
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size:  128 KByte (default)
------------------------------------------------------------
[  1] local 192.168.4.2 port 5001 connected with 192.168.4.3 port 46368 (icwnd/mss/irtt=14/1448/4440)
[ ID] Interval       Transfer     Bandwidth
[  1] 0.0000-3.0000 sec  1.32 MBytes  3.68 Mbits/sec
[  1] 3.0000-6.0000 sec  1.33 MBytes  3.72 Mbits/sec
[  1] 6.0000-9.0000 sec  1.34 MBytes  3.75 Mbits/sec
[  1] 9.0000-12.0000 sec  1.39 MBytes  3.87 Mbits/sec
[  1] 12.0000-15.0000 sec  1.40 MBytes  3.92 Mbits/sec
[  1] 15.0000-18.0000 sec  1.37 MBytes  3.83 Mbits/sec
[  1] 18.0000-21.0000 sec  1.32 MBytes  3.68 Mbits/sec
[  1] 21.0000-24.0000 sec  1.36 MBytes  3.80 Mbits/sec
[  1] 24.0000-27.0000 sec  1.01 MBytes  2.83 Mbits/sec
[  1] 27.0000-30.0000 sec  1.37 MBytes  3.84 Mbits/sec
[  1] 0.0000-30.6199 sec  13.5 MBytes  3.70 Mbits/sec

So the performance is much better in this case, however the ESP-IDF softAP is still faster by a factor of 6.

Sketch

/*
  WiFiAccessPoint.ino creates a WiFi access point and provides a web server on it.

  Steps:
  1. Connect to the access point "yourAp"
  2. Point your web browser to http://192.168.4.1/H to turn the LED on or http://192.168.4.1/L to turn it off
     OR
     Run raw TCP "GET /H" and "GET /L" on PuTTY terminal with 192.168.4.1 as IP address and 80 as port

  Created for arduino-esp32 on 04 July, 2018
  by Elochukwu Ifediora (fedy0)
*/

#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiAP.h>

#define LED_BUILTIN 2   // Set the GPIO pin where you connected your test LED or comment this line out if your dev board has a built-in LED

// Set these to your desired credentials.
const char *ssid = "yourAP";
const char *password = "yourPassword";

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);

  Serial.begin(115200);
  Serial.println();
  Serial.println("Configuring access point...");

  // You can remove the password parameter if you want the AP to be open.
  WiFi.softAP(ssid, password);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);

}

void loop() {
}

Debug Message

ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13516
load:0x40080400,len:3604
entry 0x400805f0
[⸮⸮mum⸮⸮⸮⸮2-hal-cpu.c:214] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz

Configuring access point...
[    29][D][WiFiGeneric.cpp:852] _eventCallback(): Arduino Event: 0 - WIFI_READY
[   114][D][WiFiGeneric.cpp:852] _eventCallback(): Arduino Event: 10 - AP_START
AP IP address: 192.168.4.1
Server started
[ 13349][D][WiFiGeneric.cpp:852] _eventCallback(): Arduino Event: 12 - AP_STACONNECTED
[ 13422][D][WiFiGeneric.cpp:852] _eventCallback(): Arduino Event: 14 - AP_STAIPASSIGNED
[ 44244][D][WiFiGeneric.cpp:852] _eventCallback(): Arduino Event: 12 - AP_STACONNECTED
[ 44286][D][WiFiGeneric.cpp:852] _eventCallback(): Arduino Event: 14 - AP_STAIPASSIGNED

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

rtrbt commented 2 years ago

Some additional tests with two ESPs as clients running the ESP-IDF 4.4.1 IPerf example as before and another ESP running the arduino-esp32 softAP example.

arduino-esp32 1.0.6

        Interval Bandwidth
   0-   3 sec       2.37 Mbits/sec
   3-   6 sec       0.11 Mbits/sec
   6-   9 sec       0.34 Mbits/sec
   9-  12 sec       0.37 Mbits/sec
  12-  15 sec       0.96 Mbits/sec
  15-  18 sec       0.40 Mbits/sec
  18-  21 sec       0.55 Mbits/sec
  21-  24 sec       1.02 Mbits/sec
  24-  27 sec       0.11 Mbits/sec
  27-  30 sec       0.89 Mbits/sec
   0-  30 sec       0.71 Mbits/sec

arduino-esp32 2.0.0 RC1

        Interval Bandwidth
   0-   3 sec       0.33 Mbits/sec
   3-   6 sec       0.19 Mbits/sec
   6-   9 sec       0.03 Mbits/sec
   9-  12 sec       0.82 Mbits/sec
  12-  15 sec       0.09 Mbits/sec
  15-  18 sec       0.03 Mbits/sec
  18-  21 sec       0.08 Mbits/sec
  21-  24 sec       0.28 Mbits/sec
  24-  27 sec       0.06 Mbits/sec
  27-  30 sec       0.64 Mbits/sec
   0-  30 sec       0.25 Mbits/sec

arduino-esp32 2.0.0

        Interval Bandwidth
   0-   3 sec       0.74 Mbits/sec
   3-   6 sec       0.05 Mbits/sec
   6-   9 sec       0.04 Mbits/sec
   9-  12 sec       0.42 Mbits/sec
  12-  15 sec       0.05 Mbits/sec
  15-  18 sec       0.47 Mbits/sec
  18-  21 sec       0.01 Mbits/sec
  21-  24 sec       0.84 Mbits/sec
  24-  27 sec       0.03 Mbits/sec
  27-  30 sec       0.02 Mbits/sec
   0-  30 sec       0.27 Mbits/sec

arduino-esp32 2.0.1

        Interval Bandwidth
   0-   3 sec       0.05 Mbits/sec
   3-   6 sec       0.09 Mbits/sec
   6-   9 sec       0.05 Mbits/sec
   9-  12 sec       0.03 Mbits/sec
  12-  15 sec       0.04 Mbits/sec
  15-  18 sec       0.06 Mbits/sec
  18-  21 sec       0.04 Mbits/sec
  21-  24 sec       0.08 Mbits/sec
  24-  27 sec       0.03 Mbits/sec
  27-  30 sec       0.08 Mbits/sec
   0-  30 sec       0.06 Mbits/sec

For comparision: with a "proper" WiFi router as AP:

        Interval Bandwidth
   0-   3 sec       11.91 Mbits/sec
   3-   6 sec       14.11 Mbits/sec
   6-   9 sec       14.50 Mbits/sec
   9-  12 sec       15.12 Mbits/sec
  12-  15 sec       15.38 Mbits/sec
  15-  18 sec       15.18 Mbits/sec
  18-  21 sec       15.35 Mbits/sec
  21-  24 sec       15.11 Mbits/sec
  24-  27 sec       15.76 Mbits/sec
  27-  30 sec       15.42 Mbits/sec
   0-  30 sec       14.78 Mbits/sec
guestisp commented 2 years ago

Saw something similiar right now. When ESP32 is running in AP mode, like for a captive portal, transferring files from the ESP32 to the wifi client is very very slow (the captive portar load after 20-30 seconds, if not timeout). The exact same sketch but with ESP32 connected to a wifi network and the same client reaching the esp32 via the wifi network , is very fast, the page loads almost in no time.

StefanKellerAC commented 2 years ago

+1

SonnyZheng commented 1 year ago

Facing the same problem, any solution? Thanks!

guestisp commented 1 year ago

i was able to solve only using ESP Arduino 1.x

SuGlider commented 1 year ago

This will require some time. But it is in the list for investigation and fixing.

ttlappalainen commented 1 year ago

I have the same problem.

I use AsyncTCP and ESPAsyncWebServer with PlatformIO. I use currently Espressif 32 3.5.0. With it SoftAP is pretty fast and usable. I have been trying to move to Espressif 32 6.1.0, but there SoftAP can not be used.

Saffarofski commented 1 year ago

I'm facing the same issue. I'm using esp32 wrover module with custome board and the speed rate is very low on AP mode but It's good in station mode. Another thing to mention is that this problem disappears whenever I touch the antenna ! (doesn't matter if It's external or internal) is it related to software or hardware?

ttlappalainen commented 1 year ago

As it works well with 3.5.0, sounds strange that touching antenna has anything to do with it.

jasongaunt commented 1 year ago

I too am having this same issue. Multiple different sketches I've written over the last 12-18 months for ESP32's using PlatformIO and espressif32 all have one thing in common; Intermittent / random massive slowdowns in WiFi performance.

Sometime's they work fine, sometimes they drop packets heavily, sometimes a reboot or a power cycle fixes it, sometimes it does not.

I never got to the bottom of this. I see the same performance issues depending on whether I'm connecting to it (access point) or if it's connected to my WiFi network.

I don't know if this information will be of any use but it may help narrowing down the cause;

Platform: M5Stack Stamp Pico (ESP32-PICO-D4) Codebase: Espressif 32 (5.0.0) with the following dependency graph...

PACKAGES:
 - framework-arduinoespressif32 @ 3.20003.220619 (2.0.3)
 - tool-esptoolpy @ 1.30300.0 (3.3.0)
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3

Dependency Graph
|-- FastLED @ 3.5.0
|-- ESP Async WebServer @ 1.2.3+sha.f71e3d4
|-- AsyncTCP @ 1.1.1+sha.ca8ac5f
|-- ArduinoJson @ 6.21.2
|-- LittleFS @ 2.0.0
|-- ArduinoOTA @ 2.0.0
|-- DNSServer @ 2.0.0
|-- WiFi @ 2.0.0

platformio.ini

[env]
platform = espressif32
framework = arduino
monitor_speed = 115200
build_flags = -Wno-write-strings
lib_deps =
    fastled/FastLED
    https://github.com/me-no-dev/ESPAsyncWebServer
    https://github.com/me-no-dev/AsyncTCP
    bblanchon/ArduinoJson
extra_scripts =
    pre:scripts/prebuild.py

[env:m5stack-pico]
board = pico32
board_build.partitions = scripts/stamp_partition_layout.csv
monitor_port = COM1
upload_speed = 921600
upload_port = COM1
monitor_filters = esp32_exception_decoder

[env:m5stamp-ota]
board = pico32
board_build.partitions = scripts/stamp_partition_layout.csv
upload_protocol = espota
upload_port = pico32.lan

Init routine

// Initialises WiFi as an AP and sets up captive portal DNS
void initWiFi() {
  Serial.print("Starting WiFi SoftAP... ");
  WiFi.useStaticBuffers(true);
  WiFi.setHostname(WIFI_HOSTNAME);
  WiFi.hostname(WIFI_HOSTNAME);
  WiFi.mode(WIFI_MODE_APSTA);
  IPAddress SOFTAP_IP(169, 254, 200, 1);
  IPAddress SOFTAP_NM(255, 255, 255, 0);
  IPAddress SOFTAP_GW(169, 254, 200, 1);
  WiFi.softAP(WIFI_AP_SSID, WIFI_AP_PASS);
  delay(200);
  WiFi.softAPConfig(SOFTAP_IP, SOFTAP_GW, SOFTAP_NM);
  dnsServer.start(DNS_PORT, "*", SOFTAP_IP);
  WiFi.onEvent(WiFiStationGotIP, ARDUINO_EVENT_WIFI_STA_GOT_IP);
  Serial.printf("done.\nYou can connect with the following details:\nSSID: %s\nPass: %s\n", WIFI_AP_SSID, WIFI_AP_PASS);
}

void setup()
{
  initWiFi();
  // Usual ArduinoOTA init code here..
  // My setup code here..
}

void loop() {
  ArduinoOTA.handle();
  dnsServer.processNextRequest();
  // My loop code here..
}