Blynk2.0 - Notification delay

I have problem about Notification delay.
I want to make notification delay every 1 minute

This is my event setting:

This is my whole code :

#define BLYNK_TEMPLATE_ID "TMPL1ZBP7FMf"
#define BLYNK_DEVICE_NAME "MUSHROOM"
#define BLYNK_AUTH_TOKEN "************"

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <DHT_U.h>
#include <SimpleTimer.h>

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "******";
char pass[] = "******";

#define DHTPIN D2
#define DHTTYPE DHT11
#define relay D1

DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;


void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
  Serial.println(dht.readHumidity());;
    if (V5 < 70){
    Blynk.logEvent("moisalert", "Humidity Low");
    Serial.println("Humidity Low");
}
}

void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  dht.begin();
  timer.setInterval(1000L, sendSensor);
  pinMode(relay, OUTPUT);
}

void loop()
{
  Blynk.run();
  timer.run();
}
BLYNK_WRITE(V1)
{
  int button = param.asInt();
  
  if (button == 1){
   digitalWrite(relay, HIGH);
   Serial.println(button);
  }
  else if (button == 0){
    digitalWrite(relay, LOW);
    Serial.println(button);
  }

}

This is notify code :

if (V5 < 70){
Blynk.logEvent("moisalert", "Humidity Low");
Serial.println("Humidity Low");
}

The simple solution is to call sendSensor once every minute, rather than every second.
In this scenario that doesn’t seem like an unreasonable thing to do.

Alternatively, put your humidity alert in a separate function and call that every minute.

Pete

2 Likes

Do you have any example code.
I have no idea about this code.

Use 60000L instead of 1000L, so it will be like this

timer.setInterval(60000L, sendSensor);
1 Like

I’m new at this .Thanks for help.

1 Like

No problem buddy, we are here to help :slightly_smiling_face:

2 Likes