ESP32 not connecting to wifi

Hi, I am having issues with my ESP32 dev board. For some reason it is struggling to connect to the wifi, after I made some measurements with multimeter on pin 15. Serial monitor is showing endless attempts to connect without success. Board is not connected to anything else.

Hi @pariston_hill
I have an ESP32 logging power from my solar panel meter - described here

I use the esp32 wifi events to manage the wifi connection.

//wifi handling
// event handlers from https://techtutorialsx.com/2019/09/22/esp32-soft-ap-station-disconnected-event/

void initWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);   **//make sure your ssid & password are correct**
  Serial.print("initWiFi: Connecting to WiFi ..");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(1000);
  }
  //Serial.println(WiFi.localIP());
}


void WiFiStationConnected(WiFiEvent_t event, WiFiEventInfo_t info) {
  Serial.println("Connected to AP successfully!");
  WiFiState = 1;
  digitalWrite(LED_WiFi, WiFiState); //indicate wifi connected -  BLUE LED
}

void WiFiGotIP(WiFiEvent_t event, WiFiEventInfo_t info) {
  Serial.println("WiFi connected - hostname & IP address: ");
  Serial.print(WiFi.getHostname());
  Serial.println(WiFi.localIP());
}

void WiFiStationDisconnected(WiFiEvent_t event, WiFiEventInfo_t info) {
  Serial.println("Disconnected from WiFi access point");
  Serial.print("WiFi lost connection. Reason: ");
  Serial.println(info.disconnected.reason);
  Serial.println("Trying to Reconnect");
  WiFiState = 0;
  digitalWrite(LED_WiFi, WiFiState); //indicate wifi not connected -  BLUE LED
  WiFi.begin(ssid, password);
}

and in setup():

void setup() {
  Serial.begin(115200);
  pinMode(LED_WiFi, OUTPUT);
  pinMode(LED_Pulse, OUTPUT);
  pinMode(intPin, INPUT_PULLUP);
  
  digitalWrite(LED_WiFi, 0); //ensure blue LED off

  // added in V2.11:  delete old wifi config
  WiFi.disconnect(true);
    delay(200);

  WiFi.onEvent(WiFiStationConnected, SYSTEM_EVENT_STA_CONNECTED);
  WiFi.onEvent(WiFiGotIP, SYSTEM_EVENT_STA_GOT_IP);
  WiFi.onEvent(WiFiStationDisconnected, SYSTEM_EVENT_STA_DISCONNECTED);

  initWiFi();
  delay(200);

 ...

  Serial.println("Setup complete \n");
}

Maybe try the code you have on another ESP32, to see if you get the same problem.

Does the code also work on Arduino IoT Cloud sketch? if it does its gonna be a great help in solving this same problem as well

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.