Esp8266 notification email

Hola tengo un ESP8266 mi idea es accionar los relays mediante botones, y si este relay se apaga por falla envie un mensaje. Dejo el codigo para que me digan en que le estoy errando


Hi, I have an ESP8266. My idea is to activate the relays through buttons, and if this relay goes off due to a failure send a message. I leave the code to be told what I’m missing


#define BLYNK_PRINT Serial

#define D0   16 //GPIO16 - WAKE UP
#define D1   5  //GPIO5
#define D2   4  //GPIO4
#define D3   0  //GPIO0
#define D4   2  //GPIO2 - TXD1
#define D5   14 //GPIO14 - HSCLK
#define D6   12 //GPIO12 - HMISO
#define D7   13 //GPIO13 - HMOSI - RXD2
#define D8   15 //GPIO15 - HCS   - TXD2
#define RX   3  //GPIO3 - RXD0 
#define TX   1  //GPIO1 - TXD0
 
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "10e337a9217b4b83b238f97118ac52ce";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Ethark 2.4";
char pass[] = "homeland442";

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);


  // Envia correo electrónico cuando el hardware se conecte al servidor de Blynk
  //Parametros por defecto "Correo electronico", "Asunto", "Mensaje a enviar"
  
  Blynk.email("******@hotmail.com", "Estado de Relay", "Relay Desactivado");
  pinMode(4, OUTPUT);// pin D2(GPIO4) como Salida


  
}


void Alarma()
{
  // si la alarma se activa este envia un correo y espera 15 segundos.

  int Sensor = digitalRead(4); // variable para almacenar los estados del Relay
  if (Sensor == 0) // Si el Relay se apaga
  {
    Serial.println("Relay Desactivado"); //Imprime por el monitor serial
    Blynk.email("*******@hotmail.com", "Estado de Relay", "Relay Desactivado");
    delay(200);
  }
}



void loop()
{
  Alarma();// llama a ejecutar la funcion
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}


Dejo el codigo como aporte

#define BLYNK_PRINT Serial    //Comente esto para desactivar impresiones y ahorrar espacio
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

const int Relay1 = 16;
const int Relay2 = 5;
const int Relay3 = 4;
const int Relay4 = 0;

int relay_failed;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "**********************************";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***********";
char pass[] = "**********";

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  // Envia correo electrónico cuando el hardware se conecte al servidor de Blynk
  //Parametros por defecto "Correo electronico", "Asunto", "Mensaje a enviar"
  
  Blynk.email("*******@hotmail.com", "Estado de Relay:", "En Marcha.");
  pinMode(16,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(0,OUTPUT);
}

void RelayEstado()
{
  // si la alarma se activa este envia un correo y espera 15 segundos.

  int relay_failed = digitalRead(16); // variable para almacenar los estados del relay
                     digitalRead(5);
                     digitalRead(4); 
                     digitalRead(0);  
  
  if (relay_failed == HIGH) // si el relay falla
  {
    Serial.println("Relay Falló"); //Imprime por el monitor serial
    Blynk.email("*******@hotmail.com", "Estado de Relay:", "Relay Falló.");
    delay(200);
  }
}
void loop()
{
  RelayEstado();// llama a ejecutar la funcion
  Blynk.run();
}

Does something not work for you in this code as expected? Please state that for us to understand the problem.

Move this out of loop() to setup() triggered by a timer.