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 Oct 31, 2024
1 parent 8dcb05d commit 374d057
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*
*/

REDIRECT_STDOUT_TO(Serial)

#include <Arduino_ConnectionHandler.h>

#include "arduino_secrets.h"
Expand Down Expand Up @@ -130,7 +132,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 374d057

Please sign in to comment.