Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1.  
  2. #include <SPI.h>
  3. #include <Ethernet.h>
  4.  
  5. // MAC address from Ethernet shield sticker under board
  6. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  7. byte gateway[] = { 192, 168, 0, 1 };
  8. byte subnet[] = { 255, 255, 0, 0 };
  9. IPAddress ip(192, 168, 0, 189); // IP address, may need to change depending on network
  10. EthernetServer server(80); // create a server at port 80
  11.  
  12. void setup()
  13. {
  14. Ethernet.begin(mac, ip,gateway,subnet); // initialize Ethernet device
  15. server.begin(); // start to listen for clients
  16. }
  17.  
  18. void loop()
  19. {
  20. EthernetClient client = server.available(); // try to get client
  21.  
  22. if (client) { // got client?
  23. boolean currentLineIsBlank = true;
  24. while (client.connected()) {
  25. if (client.available()) { // client data available to read
  26. char c = client.read(); // read 1 byte (character) from client
  27. // last line of client request is blank and ends with \n
  28. // respond to client only after last line received
  29. if (c == '\n' && currentLineIsBlank) {
  30. // send a standard http response header
  31. client.println("HTTP/1.1 200 OK");
  32. client.println("Content-Type: text/html");
  33. client.println("Connection: close");
  34. client.println();
  35. // send web page
  36. client.println("<!DOCTYPE html>");
  37. client.println("<html>");
  38. client.println("<head>");
  39. client.println("<title>Arduino Web Page</title>");
  40. client.println("</head>");
  41. client.println("<body>");
  42. client.println("<h1>Hello from Arduino!</h1>");
  43. client.println("<p>A web page from the Arduino server</p>");
  44. client.println("</body>");
  45. client.println("</html>");
  46. break;
  47. }
  48. // every line of text received from the client ends with \r\n
  49. if (c == '\n') {
  50. // last character on line of received text
  51. // starting new line with next character read
  52. currentLineIsBlank = true;
  53. }
  54. else if (c != '\r') {
  55. // a text character was received from client
  56. currentLineIsBlank = false;
  57. }
  58. } // end if (client.available())
  59. } // end while (client.connected())
  60. delay(1); // give the web browser time to receive the data
  61. client.stop(); // close the connection
  62. } // end if (client)
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement