Last active
March 4, 2019 06:33
-
-
Save kala13x/7db7c08119896956da4c to your computer and use it in GitHub Desktop.
WebClient example for Arduino HR911105A Ethernet Shield
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
/* ============================================ | |
Desc: WebClient for arduino Ethernet Shield | |
Date: 03.03.2015 - kala13x (a.k.a 7th Ghost) | |
Site: http://off-sec.com/ | |
============================================ */ | |
#include <SPI.h> | |
#include <Ethernet.h> | |
// MAC address for controller | |
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; | |
// IP address for controller | |
IPAddress ip(192,168,0,177); | |
// Web Server adress | |
char server[] = "192.168.0.13"; | |
// Initialise Client | |
EthernetClient client; | |
void setup() | |
{ | |
Serial.begin(9600); | |
while (!Serial) { | |
; // wait for serial port to connect | |
} | |
if (Ethernet.begin(mac) == 0) | |
{ | |
Serial.println("Failed to configure Ethernet using DHCP"); | |
Ethernet.begin(mac, ip); | |
} | |
// give the Ethernet shield a second to initialize | |
delay(1000); | |
Serial.println("connecting..."); | |
// if you get a connection, report back via serial | |
if (client.connect(server, 25000)) | |
{ | |
Serial.println("connected"); | |
// Make a HTTP request | |
client.println("GET /"); | |
client.println("Host: 192.168.0.13"); | |
client.println("Connection: close"); | |
client.println(); | |
} else Serial.println("connection failed"); | |
} | |
void loop() | |
{ | |
// Read and print response from server | |
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(); | |
// Do nothing forevermore | |
while(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment