My ESP32 disconnects from my computer when it starts to setup as access point or anything with wifi

/*
  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 = "69696969";

WiFiServer server(80);


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.
  // a valid password must have more than 7 characters
  if (!WiFi.softAP(ssid, password)) {
    log_e("Soft AP creation failed.");
    while(1);
  }
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.begin();

  Serial.println("Server started");
}

void loop() {
  WiFiClient client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
    Serial.println("New Client.");           // print a message out the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        if (c == '\n') {                    // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();

            // the content of the HTTP response follows the header:
            client.print("Click <a href=\"/H\">here</a> to turn ON the LED.<br>");
            client.print("Click <a href=\"/L\">here</a> to turn OFF the LED.<br>");

            // The HTTP response ends with another blank line:
            client.println();
            // break out of the while loop:
            break;
          } else {    // if you got a newline, then clear currentLine:
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }

        // Check to see if the client request was "GET /H" or "GET /L":
        if (currentLine.endsWith("GET /H")) {
          digitalWrite(LED_BUILTIN, HIGH);               // GET /H turns the LED on
        }
        if (currentLine.endsWith("GET /L")) {
          digitalWrite(LED_BUILTIN, LOW);                // GET /L turns the LED off
        }
      }
    }
    // close the connection:
    client.stop();
    Serial.println("Client Disconnected.");
  }
}

this is the wifi code from the examples and when it gets to the configuring access point it just disconnects, connects, disconnects,.... so on without any output.

The power LED slightly fluctuates too.
i have disconnected everything from the esp.
But when I try the LED blink example it works just fine and I think its a problem with the wifi.
I want to know if there is anything i can do about it.
Any help is appreciated.

how do you know it "just disconnects, connects, disconnects" if there is no output?

Could your ESP might be crashing and rebooting? power issues ?

sorry i forgot to mention, it disconnects and connects from the computer and i can see that from the arduino IDE. and the output as in the serial monitor

I've not seen this with my ESP32 (different kinds)... not sure what's going on.

but it works when i try the ledblink example. so i think its the wifi tghats causing problems

thanks for the reply though

you power the ESP32 through the USB I suppose. Nothing else connected on the board?

when i hold down the en key of my esp32 devkit it keeps it connected and i can see serial print until it reaches the wifi connect function then disconnects. but when uploading i have to hold it and let it go when it reaches connecting...

Nope nothing is connected

also, after uploading the LED blink example the led stops fluctuating and it stays connected and shows up in the arduino ide and i dont have to hold down the EN key

same with bluetooth too

I've not seen that... do you have another ESP to test with? may be yours is damaged

no, this is the only onne I have. But it was working perfectly a few days ago. I forgot to mention that

may be something happened in between? did you cut a trace to solder a external antenna? short circuit of some sort possible?
(not saying it's broken, just that this could be a possibility)

I think i probably broke it. i did not solder an external antenna or anything but i did connect an mpu6050 gyroscope to it. I probably shorted it then. also bought it from amazon and im returning it and ordering a new one anyways now so Thank you very much for the help

if you created a short circuit it's unfair to return it !

1 Like

you're right! I shall keep it as a reminder of my mistake. :smiley:

if there are still some stuff working you could use it for something else (as long as you don't expect reliability if it's really damaged)

1 Like

I hope to continue to see you in this forum!

Yes. I could use it as a normal arduino uno because it has all the othe r functions except the wifi