Skip to content

Instantly share code, notes, and snippets.

@SergXIIIth
Created January 17, 2012 20:31
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save SergXIIIth/1628715 to your computer and use it in GitHub Desktop.
Save SergXIIIth/1628715 to your computer and use it in GitHub Desktop.
The first Arduino HTTP request
#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();
}
}
@phonicmouse
Copy link

Good

@mydhitz
Copy link

mydhitz commented May 15, 2018

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