BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Blynk notification issue

You have 2 calls at same time , not possible.

If only someone would tell him that he shouldn’t be reading the DHT11 once every second - oh wait, maybe they did :crazy_face:

Next thing you know someone will be telling him that you can only send one notification every 5 seconds and that he should use a ‘notification sent’ flag, but that would probably fall on deaf ears too!

Pete.

According to the DHT11 datasheet you can take measure every one second but in my opinion 5 to 10 seconds is better. I don’t know why he’s reading every 1 second, the temperature won’t change in 1 second.

The problem is that if you try to read the DHT11 once every second it starts to heat up. This skews the temperature and humidity readings, which are really inaccurate anyway.
You are also more likely to get NAN results, so its just a waste of time.

TBH, the DHT range of sensors are so poor that they belong in the bin. I quite like the SHT30 sensors, which are much more accurate in terms of temperature and are I2C which allows you to make the most of limited pins on an ESP8266.

I still don’t think there’s any point in taking readings more often than every 5-10 seconds.

Pete.

1 Like

this is another great temp sensor, and they even have waterproof versions !
[

DS18B20 Digital temperature sensor

@Blynk_Coeur Can I know whether there are any ways to solve that? @PeteKnight So I need to change it to timer.setInterval(5000L, sendSensor) right? @John93 timer.setInterval(5000L, sendSensor) isit the one you mention? @ScottB can you show me the code as reference?

I am new and i hope to gain knowledge here, thanks

Read this…

Pete.

Generally the main loop() has nothing in it but the Blynk.run() and a call to your shortest timer, let’s say “HeartBeat”. In most of my routines this call is something between 500 ms and 1 second. In that service routine you do whatever and call your other longer timers. I have a reporting timer at 60 seconds and a DHT timer at 5 seconds. Once the DHT gives me a successful read I don’t call it again until I report the results. DHTs pretty much suck and are not that reliable. Most fail within a year. DHT11s are better than DHT22s, which need to be powered down and repowered if they get in a persistent not a number state. Most of my temperature work is done with DS18B20s, which use one wire regardless of how many sensors there are and are addressable.

So essentially when you call heartbeat, it checks all the other timers in sequence. None of them appear in the loop() section.

Well, that statement confused me I’m afraid!

Pete.

Pete, don’t bitch at me about the tick marks…never posted code before.

[Unformatted code removed by moderator]

Actually the Blynk.run() is in the HeartBeatTimer.run() as well.

Well, that doesn’t help anybody now does it…feel better?

Take my advice. move to blynk iot and use automation.

If you don’t want to, or can’t be bothered to, follow the forum rules then your code or your post will be deleted.

Beside that, the code you posted simply had a ‘timer-object-name.run()` command in the void loop. That timer object will support 16 timer instances (or 12 if you use SimpleTimer instead of BlynkTimer).
It’s the timer object that you’re calling in the void loop, not an instance, so you assertion that your void loop should contain…

makes no sense.

The implication of this…

is that you are creating additional timer objects within the function called by a single timer instance which belongs to your initial timer object.
This would lead to a situation where say 5 timers had 5 timer objects with one timer each. This would use 4 times more memory and processor resources than doing it the correct way, which is to have one timer object and 5 timer instances.

Either way, your code didn’t demonstrate the child timer object scenario that you described, so didn’t help to verify that this is what you are actually doing.

Pete.

1 Like

You will receive notifications every second, it is better to put a flag in your code

About setInterval, try this :

 // Setup a function to be called every 10 seconds
    timer.setInterval(10000L, sendSensor);

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

about flag

if(digitalRead(FLOAT_SENSOR2) == HIGH) 
  {
     // turn LED on:
     digitalWrite(LED, HIGH);

  if(flag==0){
     Blynk.notify("First water level detected");
     flag=1; //Toggle flag
 }
   } 
   else 
   {
      // turn LED off:
      digitalWrite(LED, LOW);
      flag=0; //Reset notify when FLOAT_SENSOR2 is low

@Blynk_Coeur For the flag part can explain in more detail… Below is my coding, how about after adding blynk email

if(digitalRead(FLOAT_SENSOR2) == HIGH) 
  {
     // turn LED on:
     digitalWrite(LED, HIGH);
     Blynk.notify("First water level detected");
   } 
   else 
   {
      // turn LED off:
      digitalWrite(LED, LOW);
   }
   if(digitalRead(FLOAT_SENSOR) == HIGH) 
   {
      // turn BUZZER on:
      digitalWrite(BUZZER, HIGH);
Blynk.email("xxx@hotmail.com","Water Detection System","Flood alert !!!");

   } 
   else 
   {
      // turn BUZZER off:
      digitalWrite(BUZZER, LOW);
   }

The flag prevents sending multiple alerts.
You have to add the flag condition to the email function, otherwise you will receive an email every second and it’s not allowed .

Ok, I try to do some research and come back to you later. Thanks

1 Like

One timer multiple breakpoints…

BlynkTimer HeartbeatTimer;
void setup() {
HeartbeatTimer.setInterval(1000, sendHeartbeat);
HeartbeatTimer.setInterval(5000, sampleTimer);
HeartbeatTimer.setInterval(60000, dataTimer);
HeartbeatTimer.setInterval(30000, NetworkHeartbeat);
//
//
//
//
//
//
}
void loop(){
  ArduinoOTA.handle();
  HeartbeatTimer.run(); 
}

Better?

One timer object (HeartbeatTimer) with multiple timers is a better way to describe it.

If you read the “Staggering Timers” section of the topic I linked to then you’ll see how to avoid having your first two timers coinciding every 5 seconds, and them all coinciding every 60 seconds. This can get quite critical when you have shorter duration timers and functions that take a while to execute.

Pete.

Yea, I know. I often vary the times and, of course, it is impossible to have multiples of the same interval match exactly.

Better for me to have the logic separated and miss the times by a few milliseconds.