ESP32 softAP troubles - can't connect

regressor
Posts: 5
Joined: Sat Aug 13, 2022 12:46 am

ESP32 softAP troubles - can't connect

Postby regressor » Wed Sep 28, 2022 9:34 am

Hi. I want esp32 to start own access point with fixed IP in setup mode and start web server. So I write a code:

Code: Select all

void start_board_webserver() {
    IPAddress local_ip(192, 168, 4, 1);
    IPAddress subnet(255, 255, 255, 0);

    WiFi.persistent(false);
    WiFi.softAPConfig(local_ip, local_ip, subnet, IPAddress(192, 168, 4, 100));
    WiFi.softAP("FCOLLECTOR");
    delay(2000);

    IPAddress myIP = WiFi.softAPIP();
    Serial.println("WIFI AP started for setup on " + myIP.toString());

    server.on("/", webHandleRoot);
    server.serveStatic("/css", LittleFS, "/css", "max-age=43200");
    server.onNotFound(webHandleNotFound);
    server.begin();

    Serial.println("Setup webserver started on port 80");
}

void start_board_sensors_setup() {
    while (true) {
        esp_task_wdt_reset();
        server.handleClient();

	// return to normal mode if jumper removed
        pinMode(BOARD_SETUP_PIN, INPUT_PULLUP);
        if (digitalRead(BOARD_SETUP_PIN) == HIGH) {
            device_deep_sleep();
        }
        pinMode(BOARD_SETUP_PIN, INPUT);
    }
}

void setup() {
    ......
    pinMode(BOARD_SETUP_PIN, INPUT_PULLUP);
    sleep(1);
    if (digitalRead(BOARD_SETUP_PIN) != HIGH) {
        indicate_setup_mode();
        start_board_webserver();
        start_board_sensors_setup();
    }
    
    pinMode(BOARD_SETUP_PIN, INPUT);
    ......
}

And yes - this activates wifi access point but I just can't connect to it. Windows 10 OS show error "Can't connect to this network" and its eventlog say "This network in inaccessible / RSSI: 255". Android phone connects silently buy ip address is wrong and device webserver can't be riched. Sometimes (VERY RARE) windows is able to connect and after connect all works and webserver is available.

I'm using vscode with platformio and added "build_flags = -DCORE_DEBUG_LEVEL=10". Sometimes I can see some ap related lines in serial output:

Code: Select all

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
onfigsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00hd_drv:0x00,w_r:0x00
load:0x3fff0030,len:1184
load:0x40078000,len:13132
load:0x40080400,en:3036
entry 0x4008054
[     2][V][WiFiServer.h:42] WiFiServer(): WiFiServer::WiFiServer(port=80, ...)
[     3][V][WebServer.cpp:85] WebServer(): WebServer::Webserver(port=80)
[     9][D][esp32-hal-cpu.c:214] setCpuFrequencyMhz(): PLL: 320 / 4 = 80 Mhz, APB: 80000000 Hz
E (1347) psram: PSRAM ID read error: 0xffffffff
[    17][W][esp32-hal-psram.c:71] psramInit(): PSRAM init failed!
[  2194][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 0 - WIFI_READY
[  2317][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring SoftAP static IP: 192.168.4.1, MASK: 255.255.255.0, GW: 192.168.4.1
[  2317][V][WiFiGeneric.cpp:390] _arduino_event_cb(): AP Started
[  2324][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 10 - AP_START
[  2331][V][WiFiGeneric.cpp:143] set_esp_interface_ip(): SoftAP: 192.168.4.1 | Gateway: 192.168.4.1 | DHCP Start: 192.168.4.100 | Netmask: 255.255.255.0
[  2344][V][WiFiGeneric.cpp:190] set_esp_interface_ip(): DHCP Server Range: 192.168.4.100 to 192.168.4.110
[  2356][V][WiFiGeneric.cpp:393] _arduino_event_cb(): AP Stopped
[  2359][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 11 - AP_STOP
[  2360][V][WiFiGeneric.cpp:390] _arduino_event_cb(): AP Started
[  2372][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 10 - AP_START
WIFI AP started for setup on 192.168.4.1
[  4383][V][RequestHandlersImpl.h:73] StaticRequestHandler(): StaticRequestHandler: path=/css uri=/css isFile=0, cache_header=max-age=43200

Setup webserver started on port 80
ADC analog value = 4.198
Battery level 100       
This is a log from vscode uploading a filesystem image:

Code: Select all

Serial port COM4
Connecting....
Chip is ESP32-D0WD (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 10:97:bd:12:5f:fc
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Flash will be erased from 0x00210000 to 0x003fffff...
Compressed 2031616 bytes to 7847...
Writing at 0x00210000... (100 %)
Wrote 2031616 bytes (7847 compressed) at 0x00210000 in 11.5 seconds (effective 1408.9 kbit/s)...
Hash of data verified.
And plaitformio.ini:

Code: Select all

[platformio]

[env:upstream_develop]
platform = espressif32
board = denky32
framework = arduino
lib_deps = 
	danilopinotti/Battery_18650_Stats@^1.0.0
	pstolarz/OneWireNg@^0.12.0
board_build.f_cpu = 80000000L
board_build.f_flash = 40000000L
board_build.partitions = no_ota.csv
board_build.filesystem = littlefs

build_flags = -DCORE_DEBUG_LEVEL=10

upload_port = COM4
Espressif 32 version: 5.1.1+sha.4901957

Also I tried another esp32 module with builtin antenna and result was same.
In normal (non-setup) mode device connects to AP (fast and reliable), receive ip and is able to send/receive data

What i'm doing wrong ?

username
Posts: 538
Joined: Thu May 03, 2018 1:18 pm

Re: ESP32 softAP troubles - can't connect

Postby username » Sat Oct 01, 2022 1:23 pm

Having a while loop without a delay is typically never a good idea in a RTOS environment. Rare cases apply.
without seeing the whole code, try sticking a delay in your start_board_sensors_setup() loop.

regressor
Posts: 5
Joined: Sat Aug 13, 2022 12:46 am

Re: ESP32 softAP troubles - can't connect

Postby regressor » Sun Oct 02, 2022 4:23 am

Added a delay(20); in loop and this doens't help. Device can connect to other APs fast and reliable (less than 1 second) but its own AP just doesn't work - i can make 30-50 failed connections to get one success :(

Also I use BLE and noticed that BLEDevice::init(""); takes 1400 milliseconds after deep sleep and 100ms after cold startup. Something wrong with wireless stack on esp32 :(

a2800276
Posts: 78
Joined: Sat Jan 23, 2016 1:59 pm

Re: ESP32 softAP troubles - can't connect

Postby a2800276 » Mon Oct 03, 2022 11:02 am

Just a guess: what is the antenna situation? It seems like maybe your device expects a ufl antenna, but nothing is attached and the reception on the windows side is bad.

Apart from that, try to use a sample firmware and see if that works to eliminate the possibility that the cause of the problem is in your code.

regressor
Posts: 5
Joined: Sat Aug 13, 2022 12:46 am

Re: ESP32 softAP troubles - can't connect

Postby regressor » Tue Oct 04, 2022 7:09 am

My device has two modes:

1. Normal work mode. In this mode device periodical wakes to do measurements and check if collector device available. If collector found (by BLE) device connects to WIFI AP and upload a file to web-server.
2. Setup mode. Device starts WIFI access point (no password), starts own web-server and then listen for connections. Webserver contains setup page (to set device name, date/time, calibrate sensors, clear settings and collected data).

In normal mode device able to discover (listening BLE advertisements) collector presense, connects to collector WIFI access point and send a file in 2-3 seconds. It works great and tested distance is over 50 meters.

In setup mode I can found device AP, but almost can't connect to it (tried from android and windows 10).

So this is not antenna issue at all. And I made some changes - now device in setup mode connects to WIFI AP and setup mDNS name. This is less convinient but at least it works.

swkidden
Posts: 1
Joined: Wed Oct 19, 2022 3:23 pm

Re: ESP32 softAP troubles - can't connect

Postby swkidden » Wed Oct 19, 2022 3:28 pm

I have encountered the same problem. Have you found an effective solution

Who is online

Users browsing this forum: Baidu [Spider] and 74 guests