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

Blynk continuously sends notifications to IOS

Hello,

First-time coder and poster here, using a D1 Mini and IOS

I’ve been reading and experimenting with issues similar to mine but nothing seems to work for me. Push notifications get sent every second.
This brings me to my first question…
I need to have one notification and then every 10 minutes after. Are there any other options I could try?

I’ve added all my tests (commented) so that someone who could help, could maybe point out what I’ve done wrong.
At first, I thought it was my code, so tried another, didn’t work either
then tried adding a button to stop the notifications but couldn’t get it to work
then I thought it gets sent with the sendSensor and placed it in it’s own void() and that didn’t work either
timer.setInterval set at 10 min delays the message for that time but I do not get the first one at the trigger event, which is actually one I need
moved the notified = 0 to voidSetup didn’t help either
added a delay () which seems to work for short time periods but not long ones the device goes offline, might interrupt something in the blynk loop or something

//tried both of these with each one below
//BlynkTimer timer; 
SimpleTimer timer;

BLYNK_WRITE(V3)//Notifications on or off
{
  int pinValue2 = param.asInt();         // assigning incoming value from pin V1 to a variable
  if (pinValue2 == 1) {                        // If value is 1 run this command
    digitalWrite(D10, HIGH);              //D4 output from Wemos D1 mini
  }
  else {                                           // If value is 0 run this command
    digitalWrite(D10, LOW);
  }
  Serial.print("V3 Button value is: ");
  Serial.println(pinValue2);
}

void sendSensor()
{
  
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);

  //Notifications 1st try
  /*
    if (t >= 32 && notified == 0) {
      notified = 1;
      Blynk.notify ("Alert - Temperature over 32C!");
      timer.setTimeout(600000L, resetNotified); // 10 min between messages

    }
    else if (t < 32) { // set lower than 60... to stop the 59.9-60.0 bouncing.
      notified = 0;
    }

    if (t <= 26 && notified == 0) {
      notified = 1;
      Blynk.notify("Alert - Temperature under 27C!");
      timer.setTimeout(600000L, resetNotified); // 10 min between messages

    }
    else if (t > 27) {
      notified = 0;
    }
    }

    void resetNotified() {

    notified = 0;
    }
  */


  // Notifications 2nd try
  /*
    bool tempflag = true;

    if ((t < 32) && (tempflag == true)){
     Blynk.notify("Temperature is lower than 32C");
     tempflag = false;
    }
    if (t >= 32){
    tempflag = true;
    }
  */


  /*//Notification 3rd try with button

    if (V3 == 1){
      Serial.print( "Notifications are " );
      Serial.println( V3 );
    }
    else if (t > 20 && notified == 0){
          notified = 1;
          Blynk.notify ("Alert - Temperature over 20C!");
          timer.setTimeout(600000L, resetNotified); // 10 min between messages
     }
     else (t < 20);{ // set lower than 60... to stop the 59.9-60.0 bouncing.
           notified = 0;
     }
  */
}



//Notifications 4th try in void
void sendNotification()
{
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  
  //Temperature too High
  if (t >= 28 && notified == 0) {
    notified = 1;
    Blynk.notify ("Alert - Temperature over 32C!");
    //delay(1000);    // 1 second til next notification --> Works
    delay(10000);   // 10 seconds till next notification --> Works
    //delay(60000);   // 1 minute till next notification --> Device goes offline a few seconds after 1st notification
    //delay(600000);   // 10 minutes till next notification --> Device goes offline a few seconds after 1st notification
    notified = 0;
     }
  else if (t < 31) { 
    notified = 0;
  }
 
//Temperature too Low
  if (t <= 27 && notified == 0) {
    notified = 1;
    Blynk.notify ("Alert - Temperature under 27C!");
     }
  else if (t > 28) { //Set lower or higher than (if) event
    notified = 0;
  }

}


//Notifications 5th try in void with button
/*
void sendNotification()
{
  int pinValue2 = V3;
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  
  //Temperature too High
  if (t >= 28 && notified == 0 && pinValue2 == 1) {
    notified = 1;
    Blynk.notify ("Alert - Temperature over 32C!");
    
     }
  else if (t < 31) { 
    notified = 0;
  }
 
//Temperature too Low
  if (t <= 27 && notified == 0 && pinValue2 == 1) {
    notified = 1;
    Blynk.notify ("Alert - Temperature under 27C!");
     }
  else if (t > 28) { //Set lower or higher than (if) event
    notified = 0;
  }

}
*/

void resetNotified() {

  notified = 0;
}


void setup()
{
  Serial.begin(115200);
  Blynk.config(auth);
  dht.begin();
  timer.setInterval(1000L, sendSensor);
 // timer.setInterval(1000L, sendNotification); // 1 second delay
 // timer.setInterval(60000L, sendNotification); // 1 minute delay
  timer.setInterval(600000L, sendNotification); // 10 minutes delay from when triggered and sends but works for the 10 min notification
  timer.setInterval(60000L, resetNotified); // this seems to do nothing
}

void loop()
{
  Blynk.run();
  timer.run();
}

My second question: I also need help with getting the virtual button on V3 in the Blynk app to work so that I can turn notifications on and off… what am I doing wrong?

Thanks in advance for your assistance

I think your best approach is the first try. But the issue is in logic.
For example: if temp > 32, the first if will send a notification, and set the notified flag. The second else if immediately reset the flag because temp > 27. The next call to sendSensor() just after 1s will resend the notification, and so on.

Try this code (missing some part at the beginning like yours, like #include, etc) . The V3 now can be used to enable/disable notification.

....

BlynkTimer timer; 

bool notified     = false;
bool allowNotify  = false;

char auth[] = "Your_Token";
char ssid[] = "Your_SSID";
char pass[] = "Your_Pass";

BLYNK_WRITE(V3)   //Notifications on or off, make it a ON/OFF switch, not pushbutton
{
  allowNotify = param.asInt();        // assigning incoming value from pin V3 to a variable
  
  if (allowNotify) {                  // If value is 1 run this command
    digitalWrite(D10, HIGH);          //D4 output from Wemos D1 mini
  }
  else {                              // If value is 0 run this command
    digitalWrite(D10, LOW);
  }
  Serial.print("V3 Button value is: ");
  Serial.println(allowNotify);
}

void sendSensor()
{
  
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);

  if (allowNotify)
  {
    //Notifications 1st try
    if (t >= 32 && !notified) 
    {
      notified = true;
      Blynk.notify ("Alert - Temperature over 32C!");
      timer.setTimeout(600000L, resetNotified); // 10 min between messages
    }
    else if ((t < 31) && (t > 28)) 
    {
      notified = false;
    }
    else if (t <= 27 && !notified) 
    {
      notified = true;
      Blynk.notify("Alert - Temperature under 27C!");
      timer.setTimeout(600000L, resetNotified); // 10 min between messages
    }
  }
}

void resetNotified() 
{
  notified = 0;
}

void setup()
{
  Serial.begin(115200);
  WiFi.begin(ssid, pass);
  Blynk.config(auth);
  Blynk.connect();
        
  dht.begin();
  timer.setInterval(1000L, sendSensor);
}

void loop()
{
  Blynk.run();
  timer.run();
}

1 Like

@khoih you sir, are my HERO!

Thank you very much! It’s working perfectly, exactly what I needed and I learnt something new.