Hello good here I am still solving problems with my old code that worked fine with the previous blynk and with the new one I found some limitations, I have a problem with the events I reach the maximum limit very quickly, and reading I think I found the problem but I don’t know how solve it my knowledge is very basic in programming. I have an output of an atmega328 that when triggering an action sends a permanent HIGH of 5 minutes to the input "EntradaSirena = 5; " of the esp8266 therefore it does not HIGH sending notifications and as I read somewhere that causes the problem that I have with my event limits, I read over there that fellow pete wrote to set a flag to limit junk notifications, but in my case the value is only high for 5 minutes and after that time is low, I was checking and I think one of the One way is to put setTimeout but I honestly don’t know how to implement it in my code. I hope you can help me in advance, thanks.
// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLunOk9YJk"
#define BLYNK_DEVICE_NAME "Sirina1"
#define BLYNK_FIRMWARE_VERSION "0.1.9"
#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();
const byte ledPin = 16;
bool alarm_mode = false ;
bool verificador = false;
bool variable = false;
int jumper = 16;
int EntradaSirena = 5;
int estado = 13;
int PGM_PULSO = 14;
int contconexion = 0;
int conteoReactivacion = 0;
int estado_1 = 0;
int estado_2 = 0;
int cont = 0;
String mensaje = "";
int ledState = LOW; // ledState used to set the LED
int VirtualPinA = 3;
//int resetact = 1;
int resetestado = 1;
int historialDisparo = 0;
int estadoinicial = 0;
int latchButton;
int latchFlag;
void ledState1()
{
if (ledState == LOW) {
ledState = HIGH;
Blynk.virtualWrite(VirtualPinA, 0);
} else {
ledState = LOW;
Blynk.virtualWrite(VirtualPinA, 1023);
}
}
BlynkTimer timer;
void myTimerEvent() {
estado_1=digitalRead(estado);//lee el estado y lo guarda en la variable mensaje
while((estado_1!=estado_2)&&(cont!=1)){//sale del bucle cuando el valor de mensaje es 1
estado_2=digitalRead(estado);//lee el estado y lo guarda en la variable mensaje
if(digitalRead(estado) == HIGH){
Blynk.virtualWrite(V1, 0);
Blynk.logEvent("alarma_activada");
cont++;
}else{
Blynk.virtualWrite(V1, 1);
Blynk.logEvent("alarma_desactivada");
cont++;
}
estado_1=estado_2;
}
cont=0;
if(digitalRead(jumper) == HIGH){
Serial.println('1');
variable = true;
}else{
Serial.println('0');
variable = false;
}
if (digitalRead(EntradaSirena) == 0) {
Blynk.virtualWrite(V0, "NORMAL");
}
if (digitalRead(EntradaSirena) == 1)
{
Blynk.virtualWrite(V0, "ALERTA");
Blynk.logEvent("disparo_de_alarma");
if (digitalRead(estado) == 1) {
Blynk.virtualWrite(V2, "NORMAL");
Blynk.logEvent("alarma_desactivada");
}
if (digitalRead(estado) == 0)
{
Blynk.virtualWrite(V2, "ALERTA");
Blynk.logEvent("alarma_activada");
}
if (alarm_mode == true)
{
}
}
}
//===== Timeed latching button =====
BLYNK_WRITE(V1) { // Button Widget set as switch
latchButton = param.asInt();
if (latchButton == 1 && latchFlag == 0) {
latchFlag = 1; // Keeps from allowing button press more then once while relay activated
// ----- Start your timed thing here
digitalWrite(PGM_PULSO, HIGH); // Activate digital pin
// -----
timer.setTimeout(1500L, []() { // Timed Lambda Function - Latching Button release after 5 seconds
// ----- Stop your timed thing here
digitalWrite(PGM_PULSO, LOW); // Deactivate digital pin
// -----
Blynk.virtualWrite(V1, 0); // Reset Latching Button to OFF
latchFlag = 0; // resets to allow next interaction
}); // END Timer Function
} else {
if (latchButton == 0 && latchFlag == 1) { // If you try to tun off the button before time is up
Blynk.virtualWrite(V1, 1); // Restore Latching Button ON until timer is finished
}
}
}
void setup()
{
pinMode(EntradaSirena, INPUT_PULLUP);
pinMode(PGM_PULSO, OUTPUT);
pinMode(estado, INPUT_PULLUP);
pinMode(jumper, INPUT);
// mySwitch.enableTransmit(2); //pin donde se conecta al modulo el rf de la alarma.
Serial.begin(115200);
Serial.println();
timer.setInterval(1000L, myTimerEvent);
timer.setInterval(1000L, ledState1); //timer will run every sec
BlynkEdgent.begin();
}
void loop() {
BlynkEdgent.run();
timer.run();
}