Created
January 17, 2012 20:31
-
-
Save SergXIIIth/1628715 to your computer and use it in GitHub Desktop.
The first Arduino HTTP request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <Ethernet.h> | |
byte mac[] = { 0x00, 0xAB, 0xCB, 0xCD, 0xDE, 0x02 }; | |
IPAddress ip(192,168,0,140); | |
IPAddress server(173,194,70,103); | |
EthernetClient client; | |
void connect(){ | |
if (client.connect(server, 80)) { | |
Serial.print("Make a HTTP request ... "); | |
client.println("GET /search?q=arduino HTTP/1.0"); | |
client.println("HOST: google.com"); | |
client.println(); | |
Serial.println("ok"); | |
} | |
else { | |
// kf you didn't get a connection to the server: | |
Serial.println("connection failed"); | |
} | |
} | |
void setup() { | |
Serial.begin(9600); | |
Serial.print("Setup LAN ... "); | |
// give the Ethernet shield a second to initialize: | |
delay(1000); | |
Ethernet.begin(mac, ip); | |
Serial.println("ok"); | |
delay(1000); | |
connect(); | |
} | |
void loop(){ | |
if (client.available()) { | |
char c = client.read(); | |
Serial.print(c); | |
} | |
// if the server's disconnected, stop the client: | |
if (!client.connected()) { | |
Serial.println(); | |
Serial.println("disconnecting."); | |
client.stop(); | |
delay(3000); | |
connect(); | |
} | |
} | |
im try and show
disconnecting.
connection failed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good