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

Doesn¨t stop sending mails


#1

Hello:
I try to send a mail when de PIR sensor is activated. But wen I charge the program starts to send emails and doesnt stop.I dont now how can i solve this.

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>


char auth[] = "3859c00afb3b4ddeabeac179be498541";
char ssid[] = "WIFI ";
char pass[] = "946255638";




#include <SoftwareSerial.h>
SoftwareSerial EspSerial(10, 11); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

void setup()
{
  // Debug console
  Serial.begin(9600);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);
   pinMode(A0, INPUT);
}

void loop()
{
  Blynk.run();
  int value= digitalRead(A0);
  if(value == HIGH)
  {
    
    
    Blynk.email("your_email@mail.com", "Subject: Button Logger", "You just pushed the button...");

    
    }


}





#2

Hi Alex95,
Try to write this part outside the void loop. To do that you need to create a new void, It can be: void email();


#3

when A0 goes high, call a new function that sends the mail, and keeps the time the email was sent, and does not send another email until the desired time between emails has elapsed.

In your code, while the A0 is high it will try to send send thousands of emails per second. Blynk will probably only send one every 5 seconds, but you dont want that many either.


#4

@Alex95 As mentioned, you need to use logic code, flags and timers to regulate the sending of emails… or anything else that can potentially happen too much too fast.

There have been many topics about this already and there is sure to be some examples floating around you can search for. Here is a generic timed action example I put together that, with some study, you could work into a “send email only once every X amount of time as needed” process

Also, you need to understand how to avoid populating such code in your void loop() when running timing and communications sensitive applications like Blink and other IoT.