diff --git a/caldera_esp/caldera_esp.ino b/caldera_esp/caldera_esp.ino index 4656091..41df266 100755 --- a/caldera_esp/caldera_esp.ino +++ b/caldera_esp/caldera_esp.ino @@ -3,74 +3,107 @@ #include #include #include "confidencial.h" - -int loopcont; +String modo, estado, horaOn1, horaOff1, horaOn2, horaOff2, posOn1, posOn2, posOff1, posOff2, hora, minuto, segundo, dia, mes, ano; ESP8266WebServer server(80); - const int led = 13; void handleRoot() { - digitalWrite(led, 1); - server.send(200, "text/plain", "Hola desde el esp01! "+(String)loopcont); - digitalWrite(led, 0); + String mensaje, msj_arduino, valores_ino; + valores_ino = "Modo: "+modo+"\nEstado: "+estado+"\nHora encendido: "+horaOn1+"\nHora apagado: "+horaOff1+ + "\nHora encendido2: "+horaOn2+"\nHora apagado2: "+horaOff2+"\nPosiciones Servo ON1 y ON2: "+posOn1+", "+posOn2+ + "\nPosiciones Servo OFF1 y OFF2: "+posOff1+", "+posOff2+"\nHora y fecha: "+hora+":"+minuto+":"+segundo+" "+dia+ + "/"+mes+"/"+ano; + for (uint8_t i = 0; i < server.args(); i++) { + mensaje += " " + server.argName(i) + ": " + server.arg(i) + "\n"; + msj_arduino+=server.arg(i)+","; + } + server.send(200, "text/plain", "Argumentos: "+mensaje+"\nValores Arduino :\n"+valores_ino); + Serial.println(msj_arduino); + limpiaSerial(); } void handleNotFound() { - digitalWrite(led, 1); - String message = "Archivo no encontrado\n\n"; - message += "URI: "; - message += server.uri(); - message += "\nMethod: "; - message += (server.method() == HTTP_GET) ? "GET" : "POST"; - message += "\nArguments: "; - message += server.args(); - message += "\n"; - for (uint8_t i = 0; i < server.args(); i++) { - message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; - } - server.send(404, "text/plain", message); - digitalWrite(led, 0); + String message = "Archivo no encontrado\n\n"; + message += "URI: "; + message += server.uri(); + message += "\nMethod: "; + message += (server.method() == HTTP_GET) ? "GET" : "POST"; + message += "\nArguments: "; + message += server.args(); + message += "\n"; + for (uint8_t i = 0; i < server.args(); i++) { + message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; + } + server.send(404, "text/plain", message); } void setup(void) { - pinMode(led, OUTPUT); - digitalWrite(led, 0); - Serial.begin(115200); - WiFi.mode(WIFI_STA); - WiFi.begin(ssid, password); - loopcont = 0; - Serial.println(""); + pinMode(led, OUTPUT); + digitalWrite(led, 0); + Serial.begin(115200); + WiFi.mode(WIFI_STA); + WiFi.begin(ssid, password); + Serial.println(""); - // Wait for connection - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); - } - Serial.println(""); - Serial.print("Connected to "); - Serial.println(ssid); - Serial.print("IP address: "); - Serial.println(WiFi.localIP()); + // Wait for connection + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println(""); + Serial.print("Connected to "); + Serial.println(ssid); + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); - if (MDNS.begin("esp8266")) { - Serial.println("MDNS responder started"); - } + if (MDNS.begin("esp8266")) { + Serial.println("MDNS responder started"); + } - server.on("/", handleRoot); + server.on("/", handleRoot); - server.on("/inline", []() { - server.send(200, "text/plain", "esto funciona como debe"); - }); + server.on("/inline", []() { + server.send(200, "text/plain", "esto funciona como debe"); + }); - server.onNotFound(handleNotFound); + server.onNotFound(handleNotFound); - server.begin(); - Serial.println("HTTP server started"); + server.begin(); + Serial.println("HTTP server started"); +} + +void limpiaSerial() { + while(Serial.available() > 0) { + char temp = Serial.read(); + } } void loop(void) { - server.handleClient(); - loopcont+=1; + if (Serial.available() > 0) { + modo = Serial.readStringUntil(','); + estado = Serial.readStringUntil(','); + if(estado == "1") { + estado = "Encendido"; + } else if(estado == "0") { + estado = "Apagado"; + } + horaOn1 = Serial.readStringUntil(','); + horaOff1 = Serial.readStringUntil(','); + horaOn2 = Serial.readStringUntil(','); + horaOff2 = Serial.readStringUntil(','); + posOn1 = Serial.readStringUntil(','); + posOn2 = Serial.readStringUntil(','); + posOff1 = Serial.readStringUntil(','); + posOff2 = Serial.readStringUntil(','); + hora = Serial.readStringUntil(','); + minuto = Serial.readStringUntil(','); + segundo = Serial.readStringUntil(','); + dia = Serial.readStringUntil(','); + mes = Serial.readStringUntil(','); + ano = Serial.readStringUntil(','); + } + limpiaSerial(); + server.handleClient(); } diff --git a/caldera_rata/caldera_rata.ino b/caldera_rata/caldera_rata.ino index 7aeeb84..8c48ba5 100644 --- a/caldera_rata/caldera_rata.ino +++ b/caldera_rata/caldera_rata.ino @@ -15,7 +15,7 @@ Servo myservo_X; RTC_DS3231 reloj; volatile DateTime fecha; -unsigned long intervalo_loop=500; +unsigned long intervalo_loop=1000; unsigned long previoMillisLoop=0; unsigned long previoMillisTermo=0; unsigned long previoMillisAUTO=0; @@ -40,7 +40,7 @@ byte hr, mn, sg, di, me; int an; void setup() { - Serial.begin(9600); + Serial.begin(115200); myservo_X.attach(9); reloj.begin(); estado=1; @@ -62,7 +62,7 @@ void loop() { switch(estado) { case 1: // funcionamiento autonomo, por defecto - if ((unsigned long)(actualMillis - previoMillisAUTO) >= 2000) { + if ((unsigned long)(actualMillis - previoMillisAUTO) >= 1000) { if((((fecha.hour() >= horaON1) && (fecha.hour() < horaOFF1)) || ((fecha.hour() >= horaON2) && (fecha.hour() < horaOFF2))) && (estado_termo==0)) { termoACC(posON1, posON2);