ESP8266 WiFiClient connection always returns 0 I am trying to use a NodeMCU as a station to connect to a webserver, however, the WiFiClient connect function always returns 0 for no reason. I am able to connect the NodeMCU to my home WiFi, but it just cannot connect to any server (either with IP address or with URL). 

If anyone is interested, the following is the testing code (I did not include the libraries intentionally for the clearness of the code).

int status = WL_IDLE_STATUS;
IPAddress server(74,125,115,105);  // Google

// Initialize the client library
WiFiClient client;

void setup() {
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  Serial.println("Connecting to AP specified during programming");
  WiFi.begin("mySSID", "myPassword");
  while (WiFi.status() != WL_CONNECTED) {delay(500); Serial.print("."); }
  Serial.print("\r\nWiFi connected IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println();
}

void loop() {
  Serial.println(client.connect(server,80));
}
I had the same problem with my esp-01. Just download ESPWenServer library from here.


  https://github.com/esp8266/ESPWebServer


And from this try HelloServer.ino example code. If it still does not connects-
1.Either your WIFI is not working
2.You are typing wrong SSID and PASSWORD
3.Spacing between SSID name or PASSWORD is the issue.


For the 3rd one if possible change your Wifi password or name if it has spaces between it.