Blynk 2.0 Notifications issues

Hello,

I am new to Blynk and Esp8266 however I managed to write and make a functioning setup and code that detects temperature, humidity and water level and write the data to the Blynk 2.0 android app without any issues. I have also enabled automation and utilized it to send me a phone notification if the water level went above 500. I am trying to set up an event to send me an phone notification and email whenever water level is above 200 using the event tab under Blynk.console and Blynk.logEvent in the code and I am having with it.

Code is below

#include "BlynkEdgent.h"
BlynkTimer timer;
#include <DHT.h>
#include<ESP8266WiFi.h>
float h;
float t;
DHT dht(D5, DHT11);
int dt= 1000;
int waterPin = A0;
int waterData = 0;
void setup()
{
  Serial.begin(9600);
  dht.begin();
  BlynkEdgent.begin();
  delay(500);
  timer.setInterval(1000L, DHT11sensor);
  timer.setInterval(1000L,Watersensor);
}

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

  Blynk.virtualWrite(V1, t);
  Blynk.virtualWrite(V2, h);

}

void Watersensor(){
  waterData = analogRead(waterPin);
Serial.println(waterData);
delay(1000);
 Blynk.virtualWrite(V3,waterData);
 ledgrid();
 
}
void ledgrid(){

  if (waterData>200){
    Blynk.logEvent("water","The Water Level is HIGH");

  }
}

void loop() { 

BlynkEdgent.run(); 
timer.run();
  }

Below are the attached are what I have in terms of events.

What I have set up in terms of events doesn’t seem to send phone notifications with any regularity.

Any help with my code or my configuration of the blynk.consule events tab is welcome.

Thank you

Saif

@waynemail85 please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

Thank you for the feedback.

I inserted the triple backticks so hopefully you are able to see my code.

Thanks

Under void watersensor (); i can see a delay1000(); which is a blocking function.
And at the same time you are trying to read n send data(2 functions) at the same time interval 1000L, and one them having delay in it.

I would first remove the delay. And change the timer interval like:

timer.setInterval(1000L, DHT11sensor);
timer.setInterval(1010L,Watersensor);

This way each function will have time to finish its job n move to next on.

Thank you very much Madhukesh for your recommendations. I did as you recommended.
The notifications are still a not working as desired. The notifications are not consistent.

For example, this afternoon, I received 100 notifications 1 second apart even though my limit period under events is 15 minutes. From my understanding limit period restricts the number of notifications that I can receive to one per limit period. My event counter is 0. Before changing it to limit period of 15 minutes, I had it at 1 minute

If I was to guess, I believe the problem is that I am either doing something wrong with my notifications or I am not resetting ESP8266 and it is getting mixed up. Beyond that I am really struggling to figure out what is the problem.

Is there a specific amount of time that it takes once the code is updated and the limit period/event counter is changed that it takes before the event notifications get activated.

Thank you in advance for your help

Saif

It would be nice if you share(code) what you have come up with till now… so that we can look for errors.

Thats quite obvious ! Because the water level stays high all the time until we use it and the water level gets low again. This may take min or hours !!

What i would do is :
If level is high - flag = 1

After 15min is elapsed (timer)
flag = 0

So again if the water level is high even after 15min then you will receive another notification.

If you have rapid change in water level, you can have an function which can reset the flag if the water level changes above or below the threshold.

Flag is basically to stop the Blynk.logEvent from triggering again n again till the conditions are true for a long time.

@Madhukesh I think you need to read the first post in the topic.

@waynemail85 I agree that your code could be improved significantly, limiting the frequency at which you are sending Blynk.logEvent() commands to the Blynk server. However, it does seem that there is an issue with Blynk. as it appears to be ignoring the Notifications Limit settings.

Are you certain that you haven’t also use the Automations settings within the app to create notifications?

Pete.

Thank you PeteKnight. I didn’t know that the automation settings can create problems with blynk.logEvent() command. I was using Automations. I deleted it and that resolved the problem. I am wondering though if I can still use the automation setting with the Blynk.logEvent() command if the limit setting is the same?

Thank you Madhukesh for your recommendation to use flags. Code is below

#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>


#define BLYNK_TEMPLATE_ID "TMPLaM59E-Tv"
#define BLYNK_DEVICE_NAME "Temperature"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"
#define BLYNK_PRINT Serial
#define APP_DEBUG  
#include "BlynkEdgent.h"
BlynkTimer timer;
#include <DHT.h>
#include<ESP8266WiFi.h>
float h;
float t;
DHT dht(D5, DHT11);
int dt= 1000;
int waterPin = A0;
int waterData = 0;
boolean Flag = 0;

void setup()
{
  Serial.begin(9600);
  dht.begin();
  BlynkEdgent.begin();
  delay(500);
  timer.setInterval(1000L, DHT11sensor);
  timer.setInterval(1010L,Watersensor);
  timer.setInterval(120000L,change_flag);
}

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

  Blynk.virtualWrite(V1, t);
  Blynk.virtualWrite(V2, h);

}

void Watersensor(){
  waterData = analogRead(waterPin);
Serial.println(waterData);
 Blynk.virtualWrite(V3,waterData);
 ledgrid();
 
}
void ledgrid(){

  if (waterData>200 && Flag==1){
 Serial.println("Hello");
    Blynk.logEvent("water","The Water Level is HIGH");
Flag=0;
  }
}

void change_flag(){

Flag =1;

}

void loop() { 

BlynkEdgent.run(); 
timer.run();
  }

Using this code, the Blynk.logEvent() command is triggered every 2 minutes but since I have my notification limit to 30 minutes, I only get one email and push notification every 30 minutes.

You did mention the following
If you have rapid change in water level, you can have an function which can reset the flag if the water level changes above or below the threshold.

I am wondering if you can give me an idea on what you are thinking when you mention the above.

Lastly, is there a way to delete timeline data from the blynk app and the blynk.cloud webpage.

Thank you very much for all your help in all of this and I hope you are able to see my code without a problem.

Create a math function
If water level has changed more than the threshold lets say 100 litres or 100 points then flag =0;

Subtracting with the current, previous values and comparing with threshold value.

If ( CV - PB >= threshold || CV - PB <= threshold )
Flag = 0;

Just a theory … need to make changes accordingly.