Advertisement
Guest User

Untitled

a guest
Feb 4th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3.  
  4. // Enter a MAC address for your controller below.
  5. // Newer Ethernet shields have a MAC address printed on a sticker on the shield
  6. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  7. // if you don't want to use DNS (and reduce your sketch size)
  8. // use the numeric IP instead of the name for the server:
  9. //IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
  10. char server[] = "www.arduino.php5.sk";    // name address for Google (using DNS)
  11.  
  12. // Set the static IP address to use if the DHCP fails to assign
  13. IPAddress ip(192, 168, 1, 254);
  14.  
  15. // Initialize the Ethernet client library
  16. // with the IP address and port of the server
  17. // that you want to connect to (port 80 is default for HTTP):
  18. EthernetClient client;
  19.  
  20. void setup() {
  21.   // Open serial communications and wait for port to open:
  22.   Serial.begin(9600);
  23.   while (!Serial) {
  24.     ; // wait for serial port to connect. Needed for native USB port only
  25.   }
  26.  
  27.   // start the Ethernet connection:
  28.   if (Ethernet.begin(mac) == 0) {
  29.     Serial.println("Failed to configure Ethernet using DHCP");
  30.     // try to congifure using IP address instead of DHCP:
  31.     Ethernet.begin(mac, ip);
  32.   }
  33.   // give the Ethernet shield a second to initialize:
  34.   delay(1000);
  35.   Serial.println("connecting...");
  36.  
  37.   // if you get a connection, report back via serial:
  38.  
  39. }
  40.  
  41. void loop() {
  42.  if (client.connect(server, 80)) {
  43.     Serial.println("connected");
  44.     // Make a HTTP request:
  45.     client.println("GET readme.txt HTTP/1.1");
  46.     client.println("Host: www.arduino.php5.sk");
  47.     client.println("Connection: close");
  48.     client.println();
  49.   } else {
  50.     // if you didn't get a connection to the server:
  51.     Serial.println("connection failed");
  52.   }
  53.   if (client.available()) {
  54.     char c = client.read();
  55.     Serial.print(c);
  56.   }
  57.  
  58.   // if the server's disconnected, stop the client:
  59.   if (!client.connected()) {
  60.     Serial.println();
  61.     Serial.println("disconnecting.");
  62.     client.stop();
  63.  
  64.     // do nothing forevermore:
  65.     while (true);
  66.   }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement