Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- #include "RTClib.h"
- #include <EEPROM.h>
- #define time 1
- // Enter a MAC address and IP address for your controller below.
- // The IP address will be dependent on your local network:
- byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
- IPAddress ip(192, 168, 0, 177);
- // Initialize the Ethernet server library
- // with the IP address and port you want to use
- // (port 80 is default for HTTP):
- EthernetServer server(80);
- //----------------------------------------------------------------------------------------------------------------
- int i=0;
- String hora="";
- String readString;
- RTC_DS1307 RTC;
- void setup() {
- pinMode(2,OUTPUT);
- // Open serial communications and wait for port to open:
- Serial.begin(9600);
- RTC.begin(); // Inicia la comunicaci¢n con el RTC
- RTC.adjust(DateTime(__DATE__, __TIME__)); // Establece la fecha y hora (Comentar una vez establecida la hora)
- while (!Serial) {
- ; // wait for serial port to connect. Needed for native USB port only
- }
- Serial.println("Sistemas Digitales ;D");
- // start the Ethernet connection and the server:
- Ethernet.begin(mac, ip);
- // Check for Ethernet hardware present
- if (Ethernet.hardwareStatus() == EthernetNoHardware) {
- Serial.println("Ethernet shield no se encontro. No se puede correr el programa sin el hardware. :(");
- while (true) {
- delay(1); // do nothing, no point running without Ethernet hardware
- }
- }
- if (Ethernet.linkStatus() == LinkOFF) {
- Serial.println("El cable Ethernet no esta onectado.");
- }
- // start the server
- server.begin();
- Serial.print("El servidor esta en: ");
- Serial.println(Ethernet.localIP());
- }
- void loop() {
- // listen for incoming clients
- delay(1000);
- DateTime now = RTC.now(); // Obtiene la fecha y hora del RTC
- EthernetClient client = server.available();
- if (client) {
- while (client.connected()) {
- if (client.available()) {
- //---------------------------------------------------------------------------------------------------------------------------------
- char c = client.read();
- if(i==11 || i==12 || i==16 || i==17){
- if(i==16){
- hora +=':';
- }
- hora += c;
- }
- if(readString.length()< 100){
- readString += c;
- }
- i++;
- //Este escribe el texto en pantalla letra por letra
- Serial.write(c);
- // if you've gotten to the end of the line (received a newline
- // character) and the line is blank, the http request has ended,
- // so you can send a reply
- if (c == 'n') {
- Serial.println("acabo lectura");
- Serial.println(hora);
- Serial.println(readString);
- client.println("HTTP/1.1 200 OK"); // Enviar una respuesta tipica
- client.println("Content-Type: text/html");
- client.println("Connection: close");
- client.println("Refresh: 10");
- client.println();
- client.println("<!DOCTYPE HTML>");
- client.println(" <html lang='en-US'>");
- client.println("<html>");
- client.println("<head><meta charset='UTF-8'><title>Sistemas Digitales</title></head>");
- client.println("<body>");
- client.println("<div style='text-align:center;'>");
- client.print("<h1>Fecha y hora del servidor:");
- client.print(now.day(), DEC);
- client.print('/');
- client.print(now.month(), DEC);
- client.print('/');
- client.print(now.year(), DEC);
- client.print(' ');
- client.print(' ');
- int horini;
- horini=now.hour();
- String horartc = "0";
- if(horini<10){
- horartc += horini;
- }else{
- horartc= String(horini);
- }
- client.print(horartc);
- client.print(':');
- int minuto;
- minuto=now.minute();
- String mainut;
- if(minuto<10){
- mainut='0'+ String(minuto);
- }else{
- mainut= String(minuto);
- }
- client.print(mainut);
- client.println("</h1>");
- client.println("<form method='get'>");
- client.println("<br /><h2>¿A que horas le quiere dar de comer al chucho?</h2><br />");
- client.println("<input type='time' name='hora'>");
- client.println("<br/><h2>que dias lo quiere alimentar?</h2><br />");
- //dias en checkbox
- //client.println("<label><input type='checkbox' name='cbox1' value='?LunesOn'>Lunes</label><br><label><input type='checkbox' name='cbox2' value='?MartesOn'>Martes</label><br><label><input type='checkbox' name='cbox3' value='?MiercolesOn'>Miercoles</label><br><label><input type='checkbox' name='cbox4' value='?JuevesOn'>Jueves</label><br><label><input type='checkbox' name='cbox5' value='?ViernesOn'>Viernes</label><br><label><input type='checkbox' name='cbox6' value='?SabadoOn'>Sabado</label><br><label><input type='checkbox' name='cbox7' value='?DomingoOn'>Domingo</label><br>");
- client.println("<input type='submit' value='Enviar' id='enviar'> ");
- client.println("</form>");
- if (readString.length() >0) {
- Serial.println("hora del rtc");
- String horiux = horartc +':'+ mainut;
- Serial.println(horiux);
- EEPROM.put(0, hora);
- if(EEPROM.get( 0, hora ) == horiux){
- digitalWrite(2, HIGH);
- delay(10000);
- digitalWrite(2, LOW);
- delay(60000);
- }
- readString="";
- i=0;
- hora="";
- client.println("</body>");
- client.println("</html>");
- delay(1);
- // close the connection:
- client.stop();
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement