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 rolled back the question to original version answered by Jaromanda – Juraj Mar 23 at 9:03
  • i tried reaching the IP address in you code, using a web browser, without success ..... no response to ping either ............ please use a valid IP address in your code ...... update your post with corrected info – jsotola Mar 23 at 18:24
  • @JaromandaX, please undelete your answer – Juraj Mar 24 at 20:13
-2

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.

  • why would he use a WebServer example if he wants to connect to a WebServer in Internet as client? – Juraj Mar 24 at 20:02
  • I know he has a different problem. My esp-01 Wifi Client was also returning 0 every time i wanted to connect. But once i had tested this HelloServer example it got connected; and after that my wifi chip is synchronized with every kind of code i have tried. Maybe after doing this his NodeMCU board gets synchronized too. – Rohan Mar 26 at 17:22
  • there is no such thing as 'synchronized' – Juraj Mar 26 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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