Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. <?PHP
  2. echo "<html> <head></head><body> hello </body></html>";
  3. ?>
  4.  
  5. #include <SPI.h>
  6. #include <Ethernet.h>
  7.  
  8.  
  9. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  10. // if you don't want to use DNS (and reduce your sketch size)
  11. // use the numeric IP instead of the name for the server:
  12. //IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
  13. char server[] = "http://localhost/"; // name address for Google (using DNS)
  14.  
  15. // Set the static IP address to use if the DHCP fails to assign
  16. IPAddress ip(192, 168, 0, 177);
  17.  
  18. // Initialize the Ethernet client library
  19. // with the IP address and port of the server
  20. // that you want to connect to (port 80 is default for HTTP):
  21. EthernetClient client;
  22.  
  23. void setup() {
  24. // Open serial communications and wait for port to open:
  25. Serial.begin(9600);
  26. while (!Serial) {
  27. ; // wait for serial port to connect. Needed for Leonardo only
  28. }
  29.  
  30. // start the Ethernet connection:
  31. if (Ethernet.begin(mac) == 0) {
  32. Serial.println("Failed to configure Ethernet using DHCP");
  33. // no point in carrying on, so do nothing forevermore:
  34. // try to congifure using IP address instead of DHCP:
  35. Ethernet.begin(mac, ip);
  36. }
  37. // give the Ethernet shield a second to initialize:
  38. delay(1000);
  39. Serial.println("connecting...");
  40.  
  41.  
  42. if (client.connect(server, 80)) {
  43. Serial.println("connected");
  44. // Make a HTTP request:
  45. client.println("GET /hello.php HTTP/1.0");
  46. client.println("Host: http://localhost/");
  47. client.println("Connection: close");
  48. client.println();
  49. }
  50. else {
  51.  
  52. Serial.println("connection failed");
  53. }
  54. }
  55.  
  56. void loop()
  57. {
  58.  
  59. if (client.available()) {
  60. char c = client.read();
  61. Serial.print(c);
  62. }
  63.  
  64.  
  65. if (!client.connected()) {
  66. Serial.println();
  67. Serial.println("disconnecting.");
  68. client.stop();
  69.  
  70.  
  71. while (true);
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement