Skip to content

Commit

Permalink
Download arduino ascii logo while connected
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Nov 4, 2024
1 parent 8dcb05d commit 4861a1b
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,49 @@ void loop() {
* which might not guarantee the correct functioning of the ConnectionHandler
* object.
*/
conMan.check();
if (conMan.check() != NetworkConnectionState::CONNECTED) {
return;
}

Client &client = conMan.getClient();
IPAddress ip = IPAddress(104, 21, 62, 246);
int port = 80;

Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
if (!client.connect(ip, port)) {
Serial.println("unable to connect to server");
return;
}

Serial.println("connected to server");
// Make a HTTP request:
size_t w = client.println("GET /asciilogo.txt HTTP/1.1");
w += client.println("Host: arduino.tips");
w += client.println("User-Agent: Arduino");
w += client.println("Connection: close");
w += client.println();
Serial.print("Write size is ");
Serial.println(w);

// if there are incoming bytes available
// from the server, read them and print them:
while (client.connected()) {
size_t len = client.available();
if (len) {
uint8_t buff[len];
client.read(buff, len);
Serial.write(buff, len);
}
delay(0);
}

// if the server's disconnected, stop the client:
Serial.println();
Serial.println("disconnecting from server.");
client.stop();
delay(1000);

}

void onNetworkConnect() {
Expand Down

0 comments on commit 4861a1b

Please sign in to comment.