When I try to use this code below, I just want to see the result of my http request
through the serial monitor. Unfortunately, client.println is not displaying results.
Any reason why?
#include <SPI.h>
#include <WiFi.h>
char ssid[] = "username"; // your network SSID (name)
char pass[] = "password"; // your network password
int status = WL_IDLE_STATUS;
char servername[]="www.arduino.cc"; // remote server we will connect to
WiFiClient client;
void setup() {
Serial.begin(9600);
Serial.println("Attempting to connect to WPA network...");
Serial.print("SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
// don't do anything else:
while(true);
}
else {
Serial.println("Connected to wifi");
Serial.println("\nStarting connection...");
// if you get a connection, report back via serial:
if (client.connect(servername, 80)) {
Serial.println("connected");
// Make a HTTP request:
// byte joe[2000];
client.println("GET /latest.txt HTTP/1.1");
client.println("Host: www.arduino.cc");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
while (client.available()) {
char c = client.read();
Serial.write(c);
}
client.println();
}
}
}
void loop() {
}