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); }