ESP8266 not connecting to Wi-Fi

Hi. I'm just started using the ESP8266 Wi-Fi Module and the one that I'm using is ESP8266-01S. I've uploaded the FirebaseDemo code to my ESP but the ESP just print "connecting........." on the serial monitor, which shows that it's not connected to the Wi-Fi.

Here are several things that I tried but it doesn't solve the problem:

  1. I've checked my SSID and password in the code. I didn't type it wrongly.
  2. From this post here, the ESP can't see the AP if it's in channel 13 and 14. I checked mine, it's in channel 1.
  3. I changed the baud rate to 115200, doesn't work.
  4. I uploaded the code to ESP8266-01 (the black one), it's not connecting to the Wi-Fi also.

Then, I try to connect to the Wi-Fi by sending AT command to my old ESP module. I want to know if there is any problem in my Wi-Fi setting which cause the ESP fails to connect to it. (I want to check the problem fast, so I didn't flash the AT firmware for the new ESP module. I just use my old ESP module since I never upload any Arduino code to that module, so the AT firmware is not corrupted.) I first send the command AT+CWMODE=1 to set it to station mode. Then I send AT+CWJAP with my SSID and password, I received "WIFI CONNECTED" and "WIFI GOT IP" on the serial monitor. So, from here I think there is no problem in my Wi-Fi setting.

Does anyone know how to solve the problem? Could there be any problem in the code? (I didn't change anything in the FirebaseDemo code except my SSID, password, FIREBASE_HOST and FIREBASE_AUTH.)

Thanks for your help.

Here's the sketch:

#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>

// Set these to run example.
#define FIREBASE_HOST "esp8266-01-d9e36.firebaseio.com"
#define FIREBASE_AUTH "XaULswRCs2SzVx39qbZDzsNa8vn1qjNl9NIH4kNA"
#define WIFI_SSID "tccstreamyx"
#define WIFI_PASSWORD "8901050231210"

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

  // connect to wifi.
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("connecting");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.print("connected: ");
  Serial.println(WiFi.localIP());
  
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}

int n = 0;

void loop() {
  // set value
  Firebase.setFloat("number", 42.0);
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /number failed:");
      Serial.println(Firebase.error());  
      return;
  }
  delay(1000);
  
  // update value
  Firebase.setFloat("number", 43.0);
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /number failed:");
      Serial.println(Firebase.error());  
      return;
  }
  delay(1000);

  // get value 
  Serial.print("number: ");
  Serial.println(Firebase.getFloat("number"));
  delay(1000);

  // remove value
  Firebase.remove("number");
  delay(1000);

  // set string value
  Firebase.setString("message", "hello world");
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /message failed:");
      Serial.println(Firebase.error());  
      return;
  }
  delay(1000);
  
  // set bool value
  Firebase.setBool("truth", false);
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /truth failed:");
      Serial.println(Firebase.error());  
      return;
  }
  delay(1000);

  // append a new value to /logs
  String name = Firebase.pushInt("logs", n++);
  // handle error
  if (Firebase.failed()) {
      Serial.print("pushing /logs failed:");
      Serial.println(Firebase.error());  
      return;
  }
  Serial.print("pushed: /logs/");
  Serial.println(name);
  delay(1000);
}

See my tip in
https://forum.arduino.cc/index.php?topic=637600.0

I've changed my code according to your suggestion.

This is what I get in my serial monitor:

connecting6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

So it might due to the ESP is not being configured in station mode? May I know how do I check if the ESP is being configured in station mode? I guess it's being done in the WiFi.begin() function?

try the WiFiScan example

I've tried the WiFiScan example and my SSID is listed there with a number behind it like (-59)*. May I know what does the number mean?

RSSI, or signal strength.
If you move the module in a different angle then the value will change after a rescan.
Leo..

OK. So now the ESP is able to find my Wi-Fi but just can't connect to it. Any idea on how to solve this? I think I should check if the ESP is being configured in station mode, which I think I should check the code for WiFi.begin(). But I actually couldn't find the ESP8266WiFi.cpp file.

Not too experienced with the ESP8266, but I think it remembers several things from a previous sketch.
More than just SSID and password.
I always include (overwrite) the mode in setup, to AP or STA or both.
Wise to read this guide.
Leo..

what type of password is used WPA or WEP? WEP is not enabled by default in ESP8266WiFi library

I wanted to check this but I wasn't able to access the setup page of my router. Before this I have tried to changed my Wi-Fi to unprotected, because I saw some post saying that the ESP can connect to the network if the network is unprotected. But the ESP still not connected after I changed it to unprotected. So, I changed it back to the original setting (and I'm sorry that I can't remember the original setting). Now, I don't know if what I did causes me to be unable to access the router setup page.

Another thing to update you guys, I have tried to connect my ESP to my mobile hotspot and it's connected.

try in sketch WiFi.enableInsecureWEP(true)

OK. I will let you know the result after I try that.

I've added WiFi.enableInsecureWEP(true) before the WiFi.begin() statement and it's working now. Thanks for your help.

Hey guys! Sorry for bring up this topic again. Recently I've changed my router to a dual band router and I know the ESP won't connect to 5GHz. So now I'm again facing problem in connecting the ESP to my Wi-Fi network. Does anyone know how to solve this? Thank you.

Shouldn't be a problem if both bands are enabled.

You did ofcourse put the old password in the new router, or upload the new password in the ESP.
Leo..

Problem solved. There are actually 2 SSID for my Wi-Fi network. The label 2.4GHz and 5GHz are automatically added to the SSID that I set. I actually typed in the one that I set instead of the one with label added to it. After changing it to the one with label, the ESP is connecting to my Wi-Fi network now.

1 Like