Android doesn't connect to ESP32 AP

Hello everyone,

I’ve tried a simple example program to create an access point on ESP32. It is visible on my smartphone, but when I try to connect to it, it is hanging on “acquiring IP address” step.

My code:

#include <Arduino.h>
#include <Preferences.h>
#include <WiFi.h>

Preferences preferences;

void setup() {
  Serial.begin(115200);
  
  String ssid, pass;
  bool result = preferences.begin("gnuk-esp32", false);
  if(result) {
    ssid = preferences.getString("ssid", "gnuk-esp32");
    pass = preferences.getString("pass", "");
  }

  WiFi.softAP(ssid.c_str(), pass.c_str());
  WiFi.onEvent([](system_event_t *sys_event){
    Serial.println("SYSTEM_EVENT_AP_STACONNECTED");
    Serial.printf(MACSTR, MAC2STR(sys_event->event_info.sta_connected.mac));
  }, SYSTEM_EVENT_AP_STACONNECTED);
  WiFi.onEvent([](system_event_t *sys_event){
    Serial.println("SYSTEM_EVENT_AP_STADISCONNECTED");
    Serial.printf(MACSTR, MAC2STR(sys_event->event_info.sta_disconnected.mac));
  }, SYSTEM_EVENT_AP_STADISCONNECTED);
}

void loop() {
}

My platformio.ini relevant part:

[env:esp-wrover-kit]
platform = espressif32
board = esp-wrover-kit
framework = arduino

By default it creates “gnuk-esp32” AP without password. I can see repeated lines of “SYSTEM_EVENT_AP_STACONNECTED” and “SYSTEM_EVENT_AP_STADISCONNECTED” in the serial output.
What am I missing here?

With

one can note that the format string has no \n at the end so newline will be printed, so the output is possibly not flushed to the console.

Possibly needs an explicit call to configure the DHCP server on the SoftAP as shown in Wifi.softAPConfig() sometimes set the wrong IP address · Issue #985 · espressif/arduino-esp32 · GitHub, or the smartphone doesn’t like the fact that it doesn’t receive an internet connection through that WiFi and reconnects…

Thanks, that did the trick.