Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. #include <Dhcp.h>
  2. #include <Dns.h>
  3. #include <Ethernet.h>
  4. #include <EthernetClient.h>
  5. #include <EthernetServer.h>
  6. #include <EthernetUdp.h>
  7. #include <SPI.h>
  8.  
  9. byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02 };
  10. IPAddress ip(192,168,1,100);
  11. EthernetServer server(80);
  12.  
  13. void setup() {
  14. Serial.begin(9600);
  15. while (!Serial) {
  16. ; // wait for serial port to connect. Needed for native USB port only
  17. }
  18.  
  19. Ethernet.begin(mac, ip);
  20. server.begin();
  21. Serial.print("server is at ");
  22. Serial.println(Ethernet.localIP());
  23. }
  24.  
  25. void loop() {
  26.  
  27. EthernetClient client = server.available();
  28.  
  29. if (client) {
  30. Serial.println("new client");
  31. // an http request ends with a blank line
  32. boolean currentLineIsBlank = true;
  33. while (client.connected()) {
  34. if (client.available()) {
  35. char c = client.read();
  36. Serial.write(c);
  37. // if you've gotten to the end of the line (received a newline
  38. // character) and the line is blank, the http request has ended,
  39. // so you can send a reply
  40. if (c == '\n' && currentLineIsBlank) {
  41. // send a standard http response header
  42. client.println("HTTP/1.1 200 OK");
  43. client.println("Content-Type: text/html");
  44. client.println("Connection: close"); // the connection will be closed after completion of the response
  45. client.println("Refresh: 5"); // refresh the page automatically every 5 sec
  46. client.println();
  47. client.println("<!DOCTYPE HTML>");
  48. client.println("<html>");
  49.  
  50. // output the value of each analog input pin
  51. int analogChannel = 0;
  52. int digitalChannel=13;
  53. int moistureSensor = analogRead(analogChannel);
  54. int dht11Sensor = digitalRead(digitalChannel);
  55.  
  56. client.print("analog input ");
  57. client.print(analogChannel);
  58. client.print(" is ");
  59. client.print(moistureSensor);
  60. client.println("<br />");
  61. client.print("digital input ");
  62. client.print(digitalChannel);
  63. client.print(" is ");
  64. client.print(dht11Sensor);
  65. client.println("<br />");
  66. client.println("</html>");
  67. }
  68. if (c == '\n') {
  69. // you're starting a new line
  70. currentLineIsBlank = true;
  71. } else if (c != '\r') {
  72. // you've gotten a character on the current line
  73. currentLineIsBlank = false;
  74. }
  75. }
  76. }
  77. // give the web browser time to receive the data
  78. delay(1);
  79. // close the connection:
  80. client.stop();
  81. Serial.println("client disconnected");
  82. }
  83.  
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement