Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- #include <Wire.h>
- #include "RTClib.h"
- RTC_DS1307 RTC;
- static byte mymac[] = {0xDE,0xAD,0xBE,0xEF,0xFE,0xED};
- static byte myip[] = {192,168,1,10};
- EthernetServer server(80);
- void setup () {
- Serial.begin(9600);
- Wire.begin();
- RTC.begin();
- if (!RTC.isrunning()) {
- Serial.println("RTC is not running");
- RTC.adjust(DateTime(__DATE__, __TIME__));
- }
- Ethernet.begin(mymac, myip);
- server.begin();
- Serial.print("Server is at: ");
- Serial.println(Ethernet.localIP());
- }
- void loop() {
- DateTime now = RTC.now();
- EthernetClient client = server.available();
- if (client) {
- //Serial.println("Client connected");
- boolean currentLineIsBlank = true;
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- //Serial.write(c);
- if (c == '\n' && currentLineIsBlank) {
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println("Connnection: close");
- client.println();
- client.println("<!DOCTYPE HTML>");
- client.println("<html>");
- client.println("<meta http-equiv=\"refresh\" content=\"1\">");
- client.println("<br />");
- client.print(now.year(), DEC);
- client.print('/');
- client.print(now.month(), DEC);
- client.print('/');
- client.print(now.day(), DEC);
- client.print(' ');
- client.print(now.hour(), DEC);
- client.print(':');
- client.print(now.minute(), DEC);
- client.print(':');
- client.print(now.second(), DEC);
- client.println("<br />");
- client.println("</html>");
- Serial.print(now.year(), DEC);
- Serial.print('/');
- Serial.print(now.month(), DEC);
- Serial.print('/');
- Serial.print(now.day(), DEC);
- Serial.print(' ');
- Serial.print(now.hour(), DEC);
- Serial.print(':');
- Serial.print(now.minute(), DEC);
- Serial.print(':');
- Serial.print(now.second(), DEC);
- Serial.println();
- break;
- }
- if (c == '\n') {
- // you're starting a new line
- currentLineIsBlank = true;
- }
- else if (c != '\r') {
- // you've gotten a character on the current line
- currentLineIsBlank = false;
- }
- }
- }
- delay(1);
- client.stop();
- //Serial.println("Client disconnected");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment