Skip to main content
Added language specifier to colour the code and made two words bold
Source Link

I am seeing some very strange behavior with my ESP8266ESP8266. When I connect it to the WiFi for the first couple of times I am not seeing any issues and the ESP8266 connects just fine.

But after an arbitrary amount of times (like when I restart the unit) it tries to connect for AGES (like multiple minutes). Eventually it says "Connected""Connected" but the IP is completely wrong and it is not connected to the internet (GET request fails).

#include <ESP8266WiFi.h> #include <ESP8266HTTPClient.h> #include <WiFiClient.h> // Replace these with your WiFi network settings const char* ssid = "MYSSID"; //replace this with your WiFi network name const char* password = "MYPASSWORD"; //replace this with your WiFi network password void setup() { Serial.begin(115200); delay(1000); IPAddress ip(192,168,1,77); IPAddress gateway(192,168,1,1); IPAddress subnet(255,255,255,0); // If I uncomment this line then it works fine // WiFi.config(ip, gateway, subnet); 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() { HTTPClient http; String serverPath = "http://www.google.com"; http.begin(serverPath.c_str()); // Send HTTP GET request int httpResponseCode = http.GET(); Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); String payload = http.getString(); Serial.println(payload); // Free resources http.end(); delay(1000); } 
 #include <ESP8266WiFi.h> #include <ESP8266HTTPClient.h> #include <WiFiClient.h> // Replace these with your WiFi network settings const char* ssid = "MYSSID"; //replace this with your WiFi network name const char* password = "MYPASSWORD"; //replace this with your WiFi network password void setup() { Serial.begin(115200); delay(1000); IPAddress ip(192,168,1,77); IPAddress gateway(192,168,1,1); IPAddress subnet(255,255,255,0); // If I uncomment this line then it works fine // WiFi.config(ip, gateway, subnet); 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() { HTTPClient http; String serverPath = "http://www.google.com"; http.begin(serverPath.c_str()); // Send HTTP GET request int httpResponseCode = http.GET(); Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); String payload = http.getString(); Serial.println(payload); // Free resources http.end(); delay(1000); } 

I am seeing some very strange behavior with my ESP8266. When I connect it to the WiFi for the first couple of times I am not seeing any issues and the ESP8266 connects just fine.

But after an arbitrary amount of times (like when I restart the unit) it tries to connect for AGES (like multiple minutes). Eventually it says "Connected" but the IP is completely wrong and it is not connected to the internet (GET request fails).

#include <ESP8266WiFi.h> #include <ESP8266HTTPClient.h> #include <WiFiClient.h> // Replace these with your WiFi network settings const char* ssid = "MYSSID"; //replace this with your WiFi network name const char* password = "MYPASSWORD"; //replace this with your WiFi network password void setup() { Serial.begin(115200); delay(1000); IPAddress ip(192,168,1,77); IPAddress gateway(192,168,1,1); IPAddress subnet(255,255,255,0); // If I uncomment this line then it works fine // WiFi.config(ip, gateway, subnet); 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() { HTTPClient http; String serverPath = "http://www.google.com"; http.begin(serverPath.c_str()); // Send HTTP GET request int httpResponseCode = http.GET(); Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); String payload = http.getString(); Serial.println(payload); // Free resources http.end(); delay(1000); } 

I am seeing some very strange behavior with my ESP8266. When I connect it to the WiFi for the first couple of times I am not seeing any issues and the ESP8266 connects just fine.

But after an arbitrary amount of times (like when I restart the unit) it tries to connect for AGES (like multiple minutes). Eventually it says "Connected" but the IP is completely wrong and it is not connected to the internet (GET request fails).

 #include <ESP8266WiFi.h> #include <ESP8266HTTPClient.h> #include <WiFiClient.h> // Replace these with your WiFi network settings const char* ssid = "MYSSID"; //replace this with your WiFi network name const char* password = "MYPASSWORD"; //replace this with your WiFi network password void setup() { Serial.begin(115200); delay(1000); IPAddress ip(192,168,1,77); IPAddress gateway(192,168,1,1); IPAddress subnet(255,255,255,0); // If I uncomment this line then it works fine // WiFi.config(ip, gateway, subnet); 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() { HTTPClient http; String serverPath = "http://www.google.com"; http.begin(serverPath.c_str()); // Send HTTP GET request int httpResponseCode = http.GET(); Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); String payload = http.getString(); Serial.println(payload); // Free resources http.end(); delay(1000); } 
Tweeted twitter.com/StackArduino/status/1316619832880660480
added 656 characters in body; edited title
Source Link

ESP8266 WiFi Not Connecting to Internet Without Static IP

But after an arbitrary amount of times (like when I restart the unit) it tries to connect for AGES (like multiple minutes). Eventually it says "Connected" but the IP is completely wrong and it definitely is not connected to the routerinternet (GET request fails).

#include <ESP8266WiFi.h> #include <ESP8266HTTPClient.h> #include <WiFiClient.h> // Replace these with your WiFi network settings const char* ssid = "MYSSID"; //replace this with your WiFi network name const char* password = "MYPASSWORD"; //replace this with your WiFi network password void setup() { Serial.begin(115200); delay(1000); IPAddress ip(192,168,1,77); IPAddress gateway(192,168,1,1); IPAddress subnet(255,255,255,0); // If I uncomment this line then it works fine // WiFi.config(ip, gateway, subnet); 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() { HTTPClient http;   String serverPath = "http://www.google.com"; http.begin(serverPath.c_str()); // Send HTTP GET request int httpResponseCode = http.GET(); Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); String payload = http.getString(); Serial.println(payload); // Free resources http.end(); delay(1000); } 

So the question is: Has anyone seen this behavior and maybe give some hints about how I can get the internet connection to be consistent without needing a static IP?

Update: If I run a ping to 169.254.104.241 I get a reply. But if I try to get anything from the internet I get HTTP Response Code = -1.

ESP8266 WiFi Not Connecting Without Static IP

But after an arbitrary amount of times (like when I restart the unit) it tries to connect for AGES (like multiple minutes). Eventually it says "Connected" but the IP is completely wrong and it definitely is not connected to the router.

#include <ESP8266WiFi.h> // Replace these with your WiFi network settings const char* ssid = "MYSSID"; //replace this with your WiFi network name const char* password = "MYPASSWORD"; //replace this with your WiFi network password void setup() { Serial.begin(115200); delay(1000); IPAddress ip(192,168,1,77); IPAddress gateway(192,168,1,1); IPAddress subnet(255,255,255,0); // If I uncomment this line then it works fine // WiFi.config(ip, gateway, subnet); 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() { } 

So the question is: Has anyone seen this behavior and maybe give some hints about how I can get the connection to be consistent without needing a static IP?

ESP8266 WiFi Not Connecting to Internet Without Static IP

But after an arbitrary amount of times (like when I restart the unit) it tries to connect for AGES (like multiple minutes). Eventually it says "Connected" but the IP is completely wrong and it is not connected to the internet (GET request fails).

#include <ESP8266WiFi.h> #include <ESP8266HTTPClient.h> #include <WiFiClient.h> // Replace these with your WiFi network settings const char* ssid = "MYSSID"; //replace this with your WiFi network name const char* password = "MYPASSWORD"; //replace this with your WiFi network password void setup() { Serial.begin(115200); delay(1000); IPAddress ip(192,168,1,77); IPAddress gateway(192,168,1,1); IPAddress subnet(255,255,255,0); // If I uncomment this line then it works fine // WiFi.config(ip, gateway, subnet); 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() { HTTPClient http;   String serverPath = "http://www.google.com"; http.begin(serverPath.c_str()); // Send HTTP GET request int httpResponseCode = http.GET(); Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); String payload = http.getString(); Serial.println(payload); // Free resources http.end(); delay(1000); } 

So the question is: Has anyone seen this behavior and maybe give some hints about how I can get the internet connection to be consistent without needing a static IP?

Update: If I run a ping to 169.254.104.241 I get a reply. But if I try to get anything from the internet I get HTTP Response Code = -1.

Added the question.
Source Link

I am seeing some very strange behavior with my ESP8266. When I connect it to the WiFi for the first couple of times I am not seeing any issues and the ESP8266 connects just fine.

But after an arbitrary amount of times (like when I restart the unit) it tries to connect for AGES (like multiple minutes). Eventually it says "Connected" but the IP is completely wrong and it definitely is not connected to the router.

Here are the odd things:

  • If I assign a static IP then it ALWAYS works and connects within seconds
  • If I factory reset my router then it works again for a few times
  • I have not seen this with any other device (like laptops or cellphones)

It is almost as if the DHCP is failing to assign an IP and then returns some random default.

#include <ESP8266WiFi.h> // Replace these with your WiFi network settings const char* ssid = "MYSSID"; //replace this with your WiFi network name const char* password = "MYPASSWORD"; //replace this with your WiFi network password void setup() { Serial.begin(115200); delay(1000); IPAddress ip(192,168,1,77); IPAddress gateway(192,168,1,1); IPAddress subnet(255,255,255,0); // If I uncomment this line then it works fine // WiFi.config(ip, gateway, subnet); 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() { } 

When DHCP magically works it assigns: 192.168.1.159

When DHCP does not work I get: 169.254.104.241

When I use a static IP then the static IP is assigned.

So the question is: Has anyone seen this behavior and maybe give some hints about how I can get the connection to be consistent without needing a static IP?

I am seeing some very strange behavior with my ESP8266. When I connect it to the WiFi for the first couple of times I am not seeing any issues and the ESP8266 connects just fine.

But after an arbitrary amount of times (like when I restart the unit) it tries to connect for AGES (like multiple minutes). Eventually it says "Connected" but the IP is completely wrong and it definitely is not connected to the router.

Here are the odd things:

  • If I assign a static IP then it ALWAYS works and connects within seconds
  • If I factory reset my router then it works again for a few times
  • I have not seen this with any other device (like laptops or cellphones)

It is almost as if the DHCP is failing to assign an IP and then returns some random default.

#include <ESP8266WiFi.h> // Replace these with your WiFi network settings const char* ssid = "MYSSID"; //replace this with your WiFi network name const char* password = "MYPASSWORD"; //replace this with your WiFi network password void setup() { Serial.begin(115200); delay(1000); IPAddress ip(192,168,1,77); IPAddress gateway(192,168,1,1); IPAddress subnet(255,255,255,0); // If I uncomment this line then it works fine // WiFi.config(ip, gateway, subnet); 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() { } 

When DHCP magically works it assigns: 192.168.1.159

When DHCP does not work I get: 169.254.104.241

When I use a static IP then the static IP is assigned.

I am seeing some very strange behavior with my ESP8266. When I connect it to the WiFi for the first couple of times I am not seeing any issues and the ESP8266 connects just fine.

But after an arbitrary amount of times (like when I restart the unit) it tries to connect for AGES (like multiple minutes). Eventually it says "Connected" but the IP is completely wrong and it definitely is not connected to the router.

Here are the odd things:

  • If I assign a static IP then it ALWAYS works and connects within seconds
  • If I factory reset my router then it works again for a few times
  • I have not seen this with any other device (like laptops or cellphones)

It is almost as if the DHCP is failing to assign an IP and then returns some random default.

#include <ESP8266WiFi.h> // Replace these with your WiFi network settings const char* ssid = "MYSSID"; //replace this with your WiFi network name const char* password = "MYPASSWORD"; //replace this with your WiFi network password void setup() { Serial.begin(115200); delay(1000); IPAddress ip(192,168,1,77); IPAddress gateway(192,168,1,1); IPAddress subnet(255,255,255,0); // If I uncomment this line then it works fine // WiFi.config(ip, gateway, subnet); 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() { } 

When DHCP magically works it assigns: 192.168.1.159

When DHCP does not work I get: 169.254.104.241

When I use a static IP then the static IP is assigned.

So the question is: Has anyone seen this behavior and maybe give some hints about how I can get the connection to be consistent without needing a static IP?

Source Link
Loading