What am I doing?

Trying to connect to a free wifi with a Nodemcu 0.9.

What I have already done?

Connecting and loading a test page in order to be redirected to the login page

Connection code:

 const char* ssid = "polimi";

  Serial.println("Attempting to connect");
  //Wait for connection
  while (WiFi.status() != WL_CONNECTED) {

Detection of captive portal

  String host = "clients3.google.com";
  String site = "/generate_204";

  Serial.print("Connecting to ");

  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");

  // We now create a URI for the request
  Serial.print("Requesting URL: ");

  client.print(String("GET ") + site + " HTTP/1.1\r\n" +
    "Host: " + host + "\r\n" + 
    "Connection: close\r\n\r\n");  

  // Read all the lines of the reply from server and print them to Serial
    String line = client.readStringUntil('\r');

  Serial.println("###Connection closed###");

What am I obtaining?

Nothing, but I wanted to obtain the html strings of the captive portal

What I'd Like

Find a way to follow the redirect and finally send a POST with my credential.

  • nothing? it connects to wifi? it connects to server? maybe it takes longer then 500 ms until the response arrives
    – Juraj
    Mar 21, 2018 at 17:53
  • @Juraj For sure it connects to the wifi then print the "requesting url..." and "###connection close ###". Absolutely no redirect. Client. Readstring does nothing
    – Timmy
    Mar 21, 2018 at 19:06
  • your way of waiting for the response with delay is wrong. see some WiFiClient example
    – Juraj
    Mar 22, 2018 at 6:38
  • @Juraj Can you show me where to find interesting example? This is what I've found on internet. I suppose I'm waiting using: while(client.available()). If I am writing here is because I don't understand where's the error
    – Timmy
    Mar 22, 2018 at 10:53
  • 1
    @dandavis Is there any working httpclient?
    – Timmy
    Mar 22, 2018 at 15:49


Your Answer

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

Browse other questions tagged or ask your own question.