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 a946dd1
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,53 @@ void loop() {
* which might not guarantee the correct functioning of the ConnectionHandler
* object.
*/
conMan.check();
if (conMan.check() != NetworkConnectionState::CONNECTED) {
return;
}

#if !defined(BOARD_HAS_LORA)
Client &client = conMan.getClient();
/* arduino.tips */
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);
#endif

}

void onNetworkConnect() {
Expand Down

0 comments on commit a946dd1

Please sign in to comment.