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() {
}
-
could be that your router is refusing the connectionjsotola– jsotola2018年11月03日 18:19:13 +00:00Commented Nov 3, 2018 at 18:19
-
@jsotola how to fix it?TRomesh– TRomesh2018年11月03日 18:19:55 +00:00Commented Nov 3, 2018 at 18:19
-
1that is only a guess ..... there could be other reasons ...... try connecting to another network ..... maybe one that does not require a passwordjsotola– jsotola2018年11月03日 18:26:09 +00:00Commented Nov 3, 2018 at 18:26
-
try WiFiScan exampleJuraj– Juraj ♦2018年11月03日 18:28:54 +00:00Commented Nov 3, 2018 at 18:28
-
1including the SSID you want to connect?Juraj– Juraj ♦2018年11月03日 18:34:32 +00:00Commented Nov 3, 2018 at 18:34
2 Answers 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.
-
Thanks for the answer but i checked my router configs and its is DHCP enabledTRomesh– TRomesh2018年11月03日 18:59:36 +00:00Commented Nov 3, 2018 at 18:59
-
see DHCP logs in router if there is a record about DHCP request from the esp2018年11月03日 19:01:13 +00:00Commented Nov 3, 2018 at 19:01
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.
-
1where did you get this? 500 mA from USB is enough. he has no motor connected2018年11月04日 10:34:44 +00:00Commented Nov 4, 2018 at 10:34