Hello people, when I receive a permanent 1 in the “pinEntradaSirena” input of the esp8266, I need it not to send me notifications immediately, but if about 5 seconds have passed before that time, it does not send any notification… can you help me. From already thank you very much.
I need to be able to implement this delay so that the system only sends me notifications only when the 1 is maintained for more than 5 seconds, before that time I don’t need notifications of that input.
> //Placa versión: Lolin WeMos D1 R1 3.0.2
> //Versión Biblioteca Blynk: 1.1.0
>
>
>
> // Fill-in information from your Blynk Template here
>
>
> #define BLYNK_TEMPLATE_ID "TMPL2FNX-JgNz"
> #define BLYNK_DEVICE_NAME "panelwifi503"
>
> #define BLYNK_FIRMWARE_VERSION "0.1.10"
>
> #define BLYNK_PRINT Serial
> // #define BLYNK_DEBUG
>
> #define APP_DEBUG
>
> // Uncomment your board, or configure a custom board in Settings.h
> // #define USE_SPARKFUN_BLYNK_BOARD
> // #define USE_NODE_MCU_BOARD
> // #define USE_WITTY_CLOUD_BOARD
> #define USE_WEMOS_D1_MINI
>
> #include "BlynkEdgent.h"
> #include <Ticker.h>
> Ticker ticker;
> // #include <RCSwitch.h>
> // RCSwitch mySwitch = RCSwitch();
>
> ///////////PINES SIRINA2///////
> int pinEntradaSirena = 12; //GPIO12 = D6
> int pinPGM_Pulso = 14; //GPIO14 = D5
> int pinEstado = 13; //GPIO 13 = D7
> //////////////////////////////
>
> const byte ledPin = 16;
> bool alarm_mode = false;
> bool verificador = false;
> bool variable = false;
>
> int contconexion = 0;
> int conteoReactivacion = 0;
> int estado_1 = 0;
> int estado_2 = 0;
> int cont = 0;
> String mensaje = "";
> bool ledTestigo = LOW;
> //int VirtualPinA = 3;
> // int resetact = 1;
> int resetestado = 1;
> int historialDisparo = 0;
> int estadoinicial = 0;
> int latchButton;
> int latchFlag;
> WidgetLCD lcd_estado(V5);
>
>
> unsigned long previousMillis = 0;
> unsigned long momentoDisparoAlarma = 0;
> bool estaAlarmaActivada = false, estaAlarmaActivadaAnterior = false;
> bool estaSirenaSonando = false, estaSirenaSonandoAnterior = false;
>
> bool notificacionEnviada = false;
>
> BlynkTimer timer;
>
>
> //===== Botón de enclavamiento temporizado =====
> BLYNK_WRITE(V6)
> { // Widget de botón configurado como interruptor
>
> Blynk.setProperty(V6, "color", "#12a370"); // RED //COLOR FONDO DE BOTON, ON
> Blynk.setProperty(V6, "label", ""); // ON
>
> latchButton = param.asInt();
> if (latchButton == 1 && latchFlag == 0)
> {
> latchFlag = 1; // Impide que se presione el botón más de una vez mientras el relé está activado
> // ----- Comience su cosa cronometrada aquí
> digitalWrite(pinPGM_Pulso, HIGH); // Activate digital pin
> // -----
> timer.setTimeout(1500L, []() { // liberación del botón de enganche después de 1.5 segundos
> // ----- Detén tu cosa cronometrada aquí
> digitalWrite(pinPGM_Pulso, LOW); //Desactivar pin digital
>
> // -----
> Blynk.virtualWrite(V6, 1); // Restaurar el botón de enclavamiento en ON hasta que finalice el temporizador
>
> Blynk.setProperty(V6, "color", "#12a370"); // RED //COLOR FONDO DE BOTON, ON
> Blynk.setProperty(V6, "label", ""); // ON
>
> latchFlag = 0; // se restablece para permitir la siguiente interacción
> }); // Final Función temporizador
> }
> else
> {
> if (latchButton == 0 && latchFlag == 1)
> { // Si intenta apagar el botón antes de que se acabe el tiempo
> Blynk.virtualWrite(V6, 1); // Restaurar el botón de enclavamiento en ON hasta que finalice el temporizador
> }
> }
> }
>
>
>
> //Esta función se ejecuta cada vez que Blynk pasa de "desconectado" a "conectado", ya sea por reconexión a WiFi/internet.
> //Dentro de ella forzamos la actualización de los pines virtuales en función de los GPIOs sin enviar eventos.
> BLYNK_CONNECTED() {
> Blynk.virtualWrite(V1, !digitalRead(pinEstado));
> Blynk.virtualWrite(V0, digitalRead(pinEntradaSirena)?"SONANDO ACTUALMENTE":"");
> lcd_estado.clear();
> }
>
> //Esto funcionaba pero ya no
> BLYNK_APP_CONNECTED()
> {
> Serial.println("App Abierta.");
> }
>
> BLYNK_APP_DISCONNECTED()
> {
> Serial.println("App Cerrada.");
> }
>
> void setup() {
> delay(50);
> pinMode(pinEntradaSirena, INPUT_PULLUP); // Da 1 cuando se dispara la alarma
> pinMode(pinPGM_Pulso, OUTPUT); // Entrega un pulso de 1,5s para activar desactivar la alarma
> pinMode(pinEstado, INPUT_PULLUP); // Lee si la alarma está activada, evento "alarma activada"
> Blynk.virtualWrite(V6, 1); // set coloured button to default ON state
> //mySwitch.enableTransmit(2); //pin donde se conecta al modulo el rf de la alarma.
> Serial.begin(115200);
>
> lcd_estado.clear();
> lcd_estado.print(5, 0, "SIRINA");
>
> BlynkEdgent.begin();
> }
>
> void loop() {
> BlynkEdgent.run();
> timer.run();
> //Serial.flush();
>
> /******* LED TESTIGO *****************/
> if(millis() - previousMillis >= 1000) { //Esta función se ejecuta una vez cada 1000 miliSegundos, basado en ejemplo Digital\BlynkWithoutDelay
> previousMillis = millis(); //Al usar este método dentro del loop evitamos el uso de interrupciones.
> ledTestigo =! ledTestigo; //Alternamos el estado, si estaba encendiDo lo apagamos y visceversa.
> Blynk.virtualWrite(3, 1023*ledTestigo); //Si el led esta en 0 la cuenta da 0, y si estaba en 1 la cuenta da 1023; encendiendo el Led Virtual en Blynk
>
>
> if(digitalRead(pinEstado)) {
> lcd_estado.print(0, 0, " ACTIVADO ");
> lcd_estado.print(0, 1, " HOGAR PROTEGIDO ");
> }
> else {
> lcd_estado.print(0, 0, " DESACTIVADO ");
> lcd_estado.print(0, 1, " SIN PROTECCION ");
> }
> }
>
> /******* ALARMA ACTIVADA/DESACTIVADA *****************/
> estaAlarmaActivada = digitalRead(pinEstado);
> if(estaAlarmaActivada != estaAlarmaActivadaAnterior and estaSirenaSonando == false) { //Analizamos si la alarma cambió de estado,
> estaAlarmaActivadaAnterior = estaAlarmaActivada; //Y si lo hizo actualizamos Blynk
>
> if(estaAlarmaActivada) {
> Blynk.virtualWrite(V1, 0);
> serialDebug("estado","activada");
> Blynk.logEvent("alarma_activada");
>
>
> // Blynk.setProperty(V6, "color", "#ff0000"); //Rojo
> // Blynk.setProperty(V6, "label", "DESACTIVAR");
> }
>
> else {
> Blynk.virtualWrite(V1, 1);
> serialDebug("estado","desactivada");
> Blynk.logEvent("alarma_desactivada");
>
> // Blynk.setProperty(V6, "color", "#00ff00"); //Verde
> // Blynk.setProperty(V6, "label", "ACTIVAR ALARMA");
>
> }
> }
>
>
> /******* SIRENA *****************/
> estaSirenaSonando = digitalRead(pinEntradaSirena);
> if(estaSirenaSonando != estaSirenaSonandoAnterior) { //Analizamos si la sirena cambió de estado (sonando o no)
> estaSirenaSonandoAnterior = estaSirenaSonando; //y si cambió de estado debemos analizar si la alarma estaba activada o no
>
> if(estaSirenaSonando == false) {
> Blynk.virtualWrite(V0, 0);
> serialDebug("sirena","normal");
> }
>
> else {
> Blynk.virtualWrite(V0, 1);
> Blynk.logEvent("disparo_de_alarma");
> momentoDisparoAlarma = millis();
> serialDebug("sirena","SONANDO");
>
>
> if (estaAlarmaActivada == false) {
> //Serial.println("Sonando, alarma desactivada");
> //Serial.println("{\"alerta\":\"ENVIADA\"}");
> Blynk.virtualWrite(V2, "NORMAL");
> Blynk.logEvent("alarma_desactivada");
> }
> else {
> Blynk.virtualWrite(V2, "ALERTA");
> Blynk.logEvent("alarma_activada");
> //Serial.println("{\"alerta\":\"no\"}");
> }
> }
> }
>
> if(digitalRead(pinEntradaSirena) and millis() - momentoDisparoAlarma >=30*1000){ //Si la sirena está sonando cada 30 segundos enviamos la notificacion a blynk (total blynk la limita)
> momentoDisparoAlarma = millis();
> Blynk.logEvent("disparo_de_alarma");
> Serial.println("disparo de alarma");
> }
> }
>
> void serialDebug(String key, String value) {
> Serial.println("{\""+key+"\":\""+value+"\"}");
> }