@@ -130,7 +130,49 @@ void loop() {
130130 * which might not guarantee the correct functioning of the ConnectionHandler
131131 * object.
132132 */
133- conMan.check ();
133+ if (conMan.check () != NetworkConnectionState::CONNECTED) {
134+ return ;
135+ }
136+
137+ Client &client = conMan.getClient ();
138+ IPAddress ip = IPAddress (104 , 21 , 62 , 246 );
139+ int port = 80 ;
140+
141+ Serial.println (" \n Starting connection to server..." );
142+ // if you get a connection, report back via serial:
143+ if (!client.connect (ip, port)) {
144+ Serial.println (" unable to connect to server" );
145+ return ;
146+ }
147+
148+ Serial.println (" connected to server" );
149+ // Make a HTTP request:
150+ size_t w = client.println (" GET /asciilogo.txt HTTP/1.1" );
151+ w += client.println (" Host: arduino.tips" );
152+ w += client.println (" User-Agent: Arduino" );
153+ w += client.println (" Connection: close" );
154+ w += client.println ();
155+ Serial.print (" Write size is " );
156+ Serial.println (w);
157+
158+ // if there are incoming bytes available
159+ // from the server, read them and print them:
160+ while (client.connected ()) {
161+ size_t len = client.available ();
162+ if (len) {
163+ uint8_t buff[len];
164+ client.read (buff, len);
165+ Serial.write (buff, len);
166+ }
167+ delay (0 );
168+ }
169+
170+ // if the server's disconnected, stop the client:
171+ Serial.println ();
172+ Serial.println (" disconnecting from server." );
173+ client.stop ();
174+ delay (1000 );
175+
134176}
135177
136178void onNetworkConnect () {
0 commit comments