Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. /*
  2. Web Server
  3.  
  4. A simple web server that shows the value of the analog input pins.
  5. using an Arduino Wiznet Ethernet shield.
  6.  
  7. Circuit:
  8. * Ethernet shield attached to pins 10, 11, 12, 13
  9. * Analog inputs attached to pins A0 through A5 (optional)
  10.  
  11. created 18 Dec 2009
  12. by David A. Mellis
  13. modified 9 Apr 2012
  14. by Tom Igoe
  15.  
  16. */
  17.  
  18. #include <SPI.h>
  19. #include <Ethernet.h>
  20.  
  21. // Enter a MAC address and IP address for your controller below.
  22. // The IP address will be dependent on your local network:
  23. byte mac[] = {
  24. 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  25. IPAddress ip(192,168,1,177);
  26.  
  27. // Initialize the Ethernet server library
  28. // with the IP address and port you want to use
  29. // (port 80 is default for HTTP):
  30. EthernetServer server(80);
  31.  
  32. void setup() {
  33. // Open serial communications and wait for port to open:
  34. Serial.begin(9600);
  35. while (!Serial) {
  36. ; // wait for serial port to connect. Needed for Leonardo only
  37. }
  38.  
  39.  
  40. // start the Ethernet connection and the server:
  41. Ethernet.begin(mac, ip);
  42. server.begin();
  43. Serial.print("server is at ");
  44. Serial.println(Ethernet.localIP());
  45. }
  46.  
  47. void loop() {
  48. // listen for incoming clients
  49. EthernetClient client = server.available();
  50. if (client) {
  51. Serial.println("new client");
  52. // an http request ends with a blank line
  53. boolean currentLineIsBlank = true;
  54. while (client.connected()) {
  55. if (client.available()) {
  56. char c = client.read();
  57. Serial.write(c);
  58. // if you've gotten to the end of the line (received a newline
  59. // character) and the line is blank, the http request has ended,
  60. // so you can send a reply
  61. if (c == '\n' && currentLineIsBlank) {
  62. // send a standard http response header
  63. client.println("HTTP/1.1 200 OK");
  64. client.println("Content-Type: text/html");
  65. client.println("Connection: close"); // the connection will be closed after completion of the response
  66. client.println("Refresh: 5"); // refresh the page automatically every 5 sec
  67. client.println();
  68. client.println("<!DOCTYPE HTML>");
  69. client.println("<html>");
  70.  
  71. // Here is the head of the page
  72. client.println("<head>");
  73. client.println("<link href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css\" rel=\"stylesheet\">");
  74. client.println("<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js\">");
  75. client.println("<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js\"></script>");
  76.  
  77. // The styles
  78. client.println("<style>");
  79. client.println("span { font-size:50px; }");
  80. client.println("</style>");
  81.  
  82. client.println("</head>");
  83.  
  84. // Here is the body of the page
  85. client.println("<body>");
  86.  
  87. // importante
  88. client.println("<span class=\"glyphicon glyphicon-flash\" aria-hidden=\"true\"></span>");
  89.  
  90. client.println("<div class=\"container\">");
  91.  
  92. client.println("<div class=\"row\">");
  93. client.println("<div class=\"col-md-6\">");
  94. client.println("<button class=\"btn btn-default\" type=\"submit\">Button</button>");
  95. client.println("</div>");
  96. client.println("<div class=\"col-md-6\">");
  97. client.println("<div class=\"progress\">");
  98. client.println("<div class=\"progress-bar\" role=\"progressbar\" aria-valuenow=\"60\" aria-valuemin=\"0\" aria-valuemax=\"100\" style=\"width: 60%;\">");
  99. client.println(" 60%");
  100. client.println("</div>");
  101. client.println("</div>");
  102. client.println("</div>");
  103. client.println("</div>");
  104.  
  105. client.println("</div>");
  106.  
  107. client.println("</body>");
  108.  
  109. client.println("</html>");
  110. break;
  111. }
  112. if (c == '\n') {
  113. // you're starting a new line
  114. currentLineIsBlank = true;
  115. }
  116. else if (c != '\r') {
  117. // you've gotten a character on the current line
  118. currentLineIsBlank = false;
  119. }
  120. }
  121. }
  122. // give the web browser time to receive the data
  123. delay(1);
  124. // close the connection:
  125. client.stop();
  126. Serial.println("client disonnected");
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement