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.
while(client.available())
. If I am writing here is because I don't understand where's the error