Ok muchas gracias, lo voy a probar, aunque empiezo a ver qué funciona mal. El programa revisa la micro sd y compara los valores con la hora del rtc durante los 4 primeros segundos de cada minuto, funciona bien si la primera lectura resulta ser la que coincide la hora con el texto de la micro sd, creo que se debe a que acumula información en la variable (o algo así), en cualquier caso agrego el código completo (aun no esta acabado).
#include <ESP8266WiFi.h> //Incluimos la librería para del WiFi
#include <Wire.h>
#include <SPI.h> //libreria para conexion SPI
#include <SD.h> //libreria del modulo de tarjeta SD
#include "RTClib.h" // libreria del reloj RTC
RTC_DS3231 rtc; // Declaramos un RTC DS3231
const char *ssid = "VodafoneMobileWiFi-14FB4F"; //Credenciales del WiFi
const char *password = "BV22A54398"; //
IPAddress ip(192,168,0,200); //Credenciales del WiFi
IPAddress gateway(192,168,0,1); //Credenciales del WiFi
IPAddress subnet(255,255,255,0); //Credenciales del WiFi
IPAddress dns(192,168,0,1); //Credenciales del WiFi
//////////////////////////////////////////
int rele1 = D3; // DECLARACION
int rele2 = D8; //
int boton = D0; //
unsigned long tiempo; // DE
unsigned long tiempo1; //
int tiempo2; //
char hora[8]; //
String inicio1sec1=""; //
String fin1sec1=""; //
String inicio2sec1=""; //
String fin2sec1=""; // VARIABLES
String inicio3sec2=""; //
String fin3sec2=""; //
String inicio4sec2=""; //
String fin4sec2="";
File myFile; //
const int chipSelect = 2; /////////////////////////////////////////
WiFiServer server(80);
void setup() {
Serial.begin(115200); //Inicio el puerto serie
while (!Serial) { ; } //epera para conectar con puerto serie
delay(10);
if (! rtc.begin()) { //
Serial.println("No hay un módulo RTC"); //Comprobamos si tenemos el RTC conectado
while (1); //
}
// Ponemos en hora, solo la primera vez, luego comentar y volver a cargar.
// Ponemos en hora con los valores de la fecha y la hora en que el sketch ha sido compilado.
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
Serial.println();
///////////////////////////////////////////
WiFi.mode(WIFI_STA); //
WiFi.config(ip, gateway, subnet); //
WiFi.begin(ssid, password); // CON LAS
Serial.print("Conectando a:\t"); //
Serial.println(ssid); //
delay(2000); // CREDENCIALES
//
//
while (WiFi.status() != WL_CONNECTED) { // PREVIAS DEL
delay(500); //
Serial.print("."); //
} // WIFI INICIAMOS
{ //
Serial.println(""); //
Serial.println("WiFi conectado"); // LA CONEXION
//
server.begin(); // Inicializo el servidor //
/////////////////
// Muestro la IP local asignada. URL del servidor //
Serial.print("Usa esta URL para conectar al servidor: "); //
Serial.print("http://"); //
Serial.print(WiFi.localIP()); //
Serial.println("/"); //
} //////////////////////
pinMode(rele1, OUTPUT); // DECLARACION DE SI LOS
digitalWrite(rele1, LOW);// PINES SON ENTRADA O
pinMode(rele2, OUTPUT); // SALIDA Y SU ESTADO
digitalWrite(rele2, LOW);// INICIAL (ALTO/BAJO)
pinMode(boton, INPUT); //
}
void loop() {
{
DateTime now = rtc.now();
//Serial.print(now.hour());
//Serial.print(':');
//Serial.print(now.minute());
//Serial.print(':');
//Serial.print(now.second());
// hora = now.hour();
//minuto = now.minute();
//segundo = now.second();
//sprintf(hora, "%d:%d:%d", now.hour(), now.minute(), now.second());
sprintf(hora, "%0.2d:%0.2d", now.hour(), now.minute());
Serial.println(hora);
//Serial.println(inicio1sec1);
delay (100);
if (now.second()<= 4) {
SD.begin(2);
myFile = SD.open( "1.txt");
if (myFile) {
while (myFile.available()) {
inicio1sec1+=(char)myFile.read();
Serial.println(inicio1sec1);
if (inicio1sec1==hora)
{
digitalWrite (rele1,HIGH);
Serial.println ("regando en el sector 1");
}
}
myFile.close(); }
}
///////////////////////////
// if (inicio1sec1==(int)strtol(hora, NULL, 8 ))
if (fin1sec1==hora)
{
digitalWrite (rele1,LOW);
Serial.println ("apagado el sector 1");
}
if (inicio2sec1==hora)
{
digitalWrite (rele1,HIGH);
Serial.println ("regando en el sector 1");
}
if (fin2sec1==hora)
{
digitalWrite (rele1,LOW);
Serial.println ("apagado el sector 1");
}
if (inicio3sec2==hora)
{
digitalWrite (rele2,HIGH);
Serial.println ("regando en el sector 2");
}
if (fin3sec2==hora)
{
digitalWrite (rele2,LOW);
Serial.println ("apagado el sector 2");
}
if (inicio4sec2==hora)
{
digitalWrite (rele2,HIGH);
Serial.println ("regando en el sector 2");
}
if (fin4sec2==hora)
{
digitalWrite (rele2,LOW);
Serial.println ("apagado el sector 2");
}
}
///////////////////////////////////////////////////////
// if ((hora ==horaInicio) && (minutos == minutosInicio) && (segundos == segundosInicio))
// {
// digitalWrite (rele1,HIGH);
// Serial.println ("regando en el sector 1");
//}
//else
//{
//Serial.println ("aun no es hora de regar en el sector 1 ");
//}
///////////////////////////////////////////////////////
// ESTE SECTOR CONTIENE LA LOGICA DE LOS BOTONES FISICOS
if (digitalRead(D0)==1) { //
tiempo1 =millis(); //
while(digitalRead(D0)==1) {} //
tiempo2=millis(); // EN ELLA SE COMPRUEBA SI SE ESTA PULSANDO EL BOTON,
tiempo=(tiempo2-tiempo1); //
//
//
if (tiempo < 150) //
{ // EN CASO DE QUE SE ESTE PULSANDO SE CUENTA EL TIEMPO
if (digitalRead(rele1)==HIGH) //
{ //
digitalWrite (rele1,LOW);} //
else //
{ //
digitalWrite (rele1,HIGH);} // QUE SE MANTIENE PULSADO, SI ES MENOS DE 0.15 SEGUNDOS,
} //
else if (tiempo > 150) //
{ //
if (digitalRead(rele2)==HIGH) //
{ // CAMBIA EL ESTADO DEL RELE 1, SI ES MAS DE 0.15 SEGUNDOS
digitalWrite (rele2,LOW);} //
else //
{ //
digitalWrite (rele2,HIGH); //
} } // CAMBIA EL ESTADO DEL RELE 2
} ////////////////////////////////////////
}