0

I'm trying to connect my nodeMCU to my WiFi network but it keeps printing ........ which means is not connecting to the network. Here is my code used to connect to WiFi. Any reason why it isn't connecting to WiFi network?.

#include <ESP8266WiFi.h>

        // Replace these with your WiFi network settings
        const char* ssid = "******"; //replace this with your WiFi network name
        const char* password = "******"; //replace this with your WiFi network password

        void setup()
        {
          delay(1000);
          Serial.begin(57600);

          WiFi.begin(ssid, password);

          Serial.println();
          Serial.print("Connecting");
          while (WiFi.status() != WL_CONNECTED)
          {
            delay(500);
            Serial.print(".");
          }

          Serial.println("success!");
          Serial.print("IP Address is: ");
          Serial.println(WiFi.localIP());
        }

        void loop() {
        }
18
  • could be that your router is refusing the connection
    – jsotola
    Nov 3, 2018 at 18:19
  • @jsotola how to fix it?
    – TRomesh
    Nov 3, 2018 at 18:19
  • 1
    that is only a guess ..... there could be other reasons ...... try connecting to another network ..... maybe one that does not require a password
    – jsotola
    Nov 3, 2018 at 18:26
  • try WiFiScan example
    – Juraj
    Nov 3, 2018 at 18:28
  • 1
    including the SSID you want to connect?
    – Juraj
    Nov 3, 2018 at 18:34

2 Answers 2

2

If your WiFi network doesn't have DHCP, then you must set the IP addresses

example:

  IPAddress ip(192, 168, 1, 8);
  IPAddress gw(192, 168, 1, 1);
  IPAddress sn(255, 255, 255, 0);
  WiFi.config(ip, gw, sn, gw);

gw is gateway. the last parmeter is dns server's IP. sn is subnet mask.

2
  • Thanks for the answer but i checked my router configs and its is DHCP enabled
    – TRomesh
    Nov 3, 2018 at 18:59
  • see DHCP logs in router if there is a record about DHCP request from the esp
    – Juraj
    Nov 3, 2018 at 19:01
-1

If your powering the device via a computer USB port there is a good chance it’s not providing enough power for the wifi. Try powering fron an external source.

1
  • 1
    where did you get this? 500 mA from USB is enough. he has no motor connected
    – Juraj
    Nov 4, 2018 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.