2
votes

I am trying to connect my ESP8266 NodeMCU to my Mobile Hotspot Wifi

When I try to connect to the ESP Wifi using laptop, It says Wifi Connected, no Internet access. Which means, The Wifi_SSID and Password are fetched by ESP correctly.

Why is the ESP not able to connect to the Internet?

I have used Arduino IDE for uploading code to ESP8266. I have uploaded the below code to the ESP8266.

#include <FirebaseArduino.h>
    #include <ESP8266WiFi.h>
    // Set these to run example.
    #define WIFI_SSID "OnePlus3"
    #define WIFI_PASSWORD ""
    #define FIREBASE_DB_URL "https://my_db_url.firebaseio.com/"
    #define FIREBASE_DB_SECRET_KEY "fakezaSyDsdadasddwGClaAy8ltYgywwo6i_VzXgY"

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

  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }

  Firebase.begin(FIREBASE_DB_URL, FIREBASE_DB_SECRET_KEY);
  Firebase.stream("/automation");  
}


void loop() {
  if (Firebase.failed()) {
    Serial.println("streaming error");
    Serial.println(Firebase.error());
  }

  if (Firebase.available()) {
     FirebaseObject event = Firebase.readEvent();
     String eventType = event.getString("type");
     eventType.toLowerCase();
     Serial.print(eventType);
     if (eventType == "put") {
      String path = event.getString("path");
      String data = event.getString("data");
      if (path.equals("/fan/value")) {
        if (data.equals("off")) {
          digitalWrite(D1, HIGH);
        } else {
          digitalWrite(D1, LOW);
        }
      } else if (path.equals("/light/value")) {
        if (data.equals("off")) {
          digitalWrite(D2, HIGH);
        } else {
          digitalWrite(D2, LOW);
        }
      } 
     }
  }   
}
1
you should add if(WiFi.status() == WL_CONNECTED) just after loop starts probably.Trishant Pahwa

1 Answers

0
votes

Troubleshooting ESP8266 not connecting to WiFi Failure to connect to the WiFi network can be caused by some factors. Among them I highlight:

1 - The ESP8266 has a particularity of the initial state of its GPIOs during an initialization. As the intention is to make a connection to the Internet, I suggest that you leave the ESP8266 only with the power and communication connections. If you have a NodeMCU you can use only the USB cable.

2 - Wrong filling in of the access data of the router will cause an error in the connection. Please note that you have to put in your code the WLAN SSID and WLAN PASS information, which are, respectively, the name and password of your network. It is worth remembering that the capture of these characters is case sensitive.

3 - If your router is not connected to the Internet, then you will have feedback via the serial monitor of your local IP, but you will not have confirmation of access with the Google server. Test it with your smartphone or computer and check if everything is fine with your Internet connection.

4 - It is difficult, but I have already seen incompatibility with the internet provider. To solve, test on different networks. I suggest that we carry out tests with your smartphone functioning as a WiFi router. You can even check the connected devices quickly and easily.

You can learn more about it in this link (Eduardo Castro) in Brazilian Portuguese: https://www.filipeflop.com/blog/como-conectar-o-esp8266-a-internet/