ESP32 rebooting when user tries to connect to wifi

Hi I´m new in Platformio and I´ve been having a problem using ESP32 wifi.
I created a very simple program in wich a wifi spot is created.
The problem is that when I try to connect my PC to the wifi, ESP32 reboots.

This is the program:

main.cpp:

#include <Arduino.h>

#include “WiFi.h”

const char* ssid = “esp-wifi”;
const char* password = “1234”;
IPAddress ip(192, 168, 4, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress gateway(192, 168, 1, 1);

void setup() {
WiFi.softAPConfig(ip, gateway, subnet);

WiFi.softAP(ssid, password);
}

void loop() {

}

platformio.ini:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino

So you’ve set a subnet mask of 255.255.255.0. Since the gateway is at 192.168.1.1 you have the ranges 192.168.1.0 to 192.168.1.255. The IP 192.168.4.1 is out of that range.

Thank you. I changed it now but the problem persists.

Hm also your password seems very short, under the minimum length of the WPA2 standard of 8 characters. Could you try this code:

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

IPAddress local_IP(192,168,4,22);
IPAddress gateway(192,168,4,9);
IPAddress subnet(255,255,255,0);

const char* ssid = "esp-wifi";
const char* password = "12345678";

void setup()
{
  Serial.begin(115200);
  Serial.println();

  Serial.print("Setting soft-AP configuration ... ");
  Serial.println(WiFi.softAPConfig(local_IP, gateway, subnet) ? "Ready" : "Failed!");

  Serial.print("Setting soft-AP ... ");
  Serial.println(WiFi.softAP(password, password) ? "Ready" : "Failed!");

  Serial.print("Soft-AP IP address = ");
  Serial.println(WiFi.softAPIP());
}

void loop() {
    delay(1000);
    Serial.println("Number clients connected: " + String(WiFi.softAPgetStationNum()));
}

And if it crashes, the full serial output of the run.

Thank you, but ESP32 is still rebooting. It does get the number of connections correctly, but I don´t know why it is still rebooting

Can you provide the serial output please. (e.g. using miniterm.py or the pio monitor command, but then set monitor_speed = 115200).

How do you power the ESP32a nd which exact one do you have? WiFi is power hungry. Have you tried a different USB cable or a USB port directly on the computer?

1 Like

I don´t know why but now it is working. Thank you very much.

Huh good to hear… still double check power sources :eyes:

1 Like