Guest User

Untitled

a guest
Dec 4th, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3. #include <Wire.h>
  4. #include "RTClib.h"
  5.  
  6. RTC_DS1307 RTC;
  7.  
  8. static byte mymac[] = {0xDE,0xAD,0xBE,0xEF,0xFE,0xED};
  9. static byte myip[] = {192,168,1,10};
  10. EthernetServer server(80);
  11.  
  12. void setup () {
  13.  
  14. Serial.begin(9600);
  15. Wire.begin();
  16. RTC.begin();
  17.  
  18. if (!RTC.isrunning()) {
  19. Serial.println("RTC is not running");
  20. RTC.adjust(DateTime(__DATE__, __TIME__));
  21. }
  22.  
  23. Ethernet.begin(mymac, myip);
  24. server.begin();
  25.  
  26. Serial.print("Server is at: ");
  27. Serial.println(Ethernet.localIP());
  28. }
  29.  
  30. void loop() {
  31. DateTime now = RTC.now();
  32.  
  33. EthernetClient client = server.available();
  34. if (client) {
  35. //Serial.println("Client connected");
  36.  
  37. boolean currentLineIsBlank = true;
  38. while (client.connected()) {
  39. if (client.available()) {
  40. char c = client.read();
  41. //Serial.write(c);
  42.  
  43. if (c == '\n' && currentLineIsBlank) {
  44.  
  45. client.println("HTTP/1.1 200 OK");
  46. client.println("Content-Type: text/html");
  47. client.println("Connnection: close");
  48. client.println();
  49. client.println("<!DOCTYPE HTML>");
  50. client.println("<html>");
  51.  
  52. client.println("<meta http-equiv=\"refresh\" content=\"1\">");
  53. client.println("<br />");
  54. client.print(now.year(), DEC);
  55. client.print('/');
  56. client.print(now.month(), DEC);
  57. client.print('/');
  58. client.print(now.day(), DEC);
  59. client.print(' ');
  60. client.print(now.hour(), DEC);
  61. client.print(':');
  62. client.print(now.minute(), DEC);
  63. client.print(':');
  64. client.print(now.second(), DEC);
  65. client.println("<br />");
  66. client.println("</html>");
  67.  
  68. Serial.print(now.year(), DEC);
  69. Serial.print('/');
  70. Serial.print(now.month(), DEC);
  71. Serial.print('/');
  72. Serial.print(now.day(), DEC);
  73. Serial.print(' ');
  74. Serial.print(now.hour(), DEC);
  75. Serial.print(':');
  76. Serial.print(now.minute(), DEC);
  77. Serial.print(':');
  78. Serial.print(now.second(), DEC);
  79. Serial.println();
  80. break;
  81. }
  82.  
  83.  
  84. if (c == '\n') {
  85. // you're starting a new line
  86. currentLineIsBlank = true;
  87. }
  88. else if (c != '\r') {
  89. // you've gotten a character on the current line
  90. currentLineIsBlank = false;
  91. }
  92. }
  93. }
  94.  
  95. delay(1);
  96.  
  97. client.stop();
  98. //Serial.println("Client disconnected");
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment