Guest User

Untitled

a guest
May 9th, 2012
45
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SPI.h>
  2.  
  3. #include <Ethernet.h>
  4.  
  5. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  6. IPAddress ip( 192,168,0,4 );
  7. byte gateway[] = { 192,168,0,1 };
  8. byte subnet[] = { 255,255,255,0 };
  9. IPAddress dns( 192,168,0,1 );
  10.  
  11. EthernetServer server(80);
  12.  
  13. void setup()
  14. {
  15. delay(1500);
  16. // start the serial library:
  17. Serial.begin(9600);
  18. Serial.println("Starting");
  19.  
  20. if (Ethernet.begin(mac) == 0)
  21. {
  22. Serial.println("Failed to configure Ethernet using DHCP");
  23. for(;;);
  24. }
  25.  
  26. delay(2000);
  27. server.begin();
  28. Serial.print("Init finished IP: ");
  29. Serial.println(Ethernet.localIP());
  30. }
  31.  
  32. void loop()
  33. {
  34. // listen for incoming clients
  35. EthernetClient client = server.available();
  36. if (client) {
  37. Serial.println("Client!");
  38. // an http request ends with a blank line
  39. boolean currentLineIsBlank = true;
  40. while (client.connected()) {
  41. while(client.available()) {
  42. char c = client.read();
  43. // if you've gotten to the end of the line (received a newline
  44. // character) and the line is blank, the http request has ended,
  45. // so you can send a reply
  46. if (c == '\n' && currentLineIsBlank) {
  47. Serial.println("sending response");
  48. // send a standard http response header
  49. client.println("HTTP/1.0 200 OK");
  50. client.println("Content-Type: text/html");
  51. client.println();
  52. client.println("<HTML><BODY>TEST OK!</BODY></HTML>");
  53. client.stop();
  54. }
  55. else if (c == '\n') {
  56. // you're starting a new line
  57. currentLineIsBlank = true;
  58. }
  59. else if (c != '\r') {
  60. // you've gotten a character on the current line
  61. currentLineIsBlank = false;
  62. }
  63. }
  64. }
  65. Serial.println("Done sending.");
  66. }
  67. }
RAW Paste Data