1

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");
  WiFi.begin(ssid);
  //Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

Detection of captive portal

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

  Serial.print("Connecting to ");
  Serial.println(host);

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

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

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

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

  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.

9
  • nothing? it connects to wifi? it connects to server? maybe it takes longer then 500 ms until the response arrives
    – Juraj
    Commented 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
    Commented Mar 21, 2018 at 19:06
  • your way of waiting for the response with delay is wrong. see some WiFiClient example
    – Juraj
    Commented 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
    Commented Mar 22, 2018 at 10:53
  • 1
    @dandavis Is there any working httpclient?
    – Timmy
    Commented Mar 22, 2018 at 15:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.