Time interval overlaping for email widget for multiple event

@Costas

Hi
I have 3 different event which set to call by 1sec interval.

Each event send an email once in 1 min if condition match.

As there is 15s time between emails suppose if all 3 condition match then 1st event will take priority and repete it self before any other event ready to send an email, I have check with diffrent time interval but luckily get 2 event mail.

I have tried with timeout function for email also but didn’t work.

Will be grateful to you if you can help me to resolve the issue.

Regards
Krunal

Paste your formatted broken code.

@Costas

thanks for the very prompt response.

one more this if i am using mq2 library then its effect the DHT11 temperature reading, i have made this code from copy & paste from here & there as i am not a programmer but some how i manage to work this code but now i stuck with above mention issue.

//#define BLYNK_DEBUG           // Comment this out to disable debug and save space
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <DHT.h>
#include <HX711.h>
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager
#include <ArduinoJson.h>          //https://github.com/bblanchon/ArduinoJson

char blynk_token[34] = "";
char low_level[5] = "";
char email_id[50] = "";

bool shouldSaveConfig = false; //flag for saving data

#define DHTPIN 2
#define DHTTYPE DHT11
#define SCALE_DOUT_PIN D2
#define SCALE_SCK_PIN D3
#define BATT_LOW 2160
#define Batt_FULL 2740
#define gaspin A0

#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

DHT dht(DHTPIN, DHTTYPE);
HX711 scale(SCALE_DOUT_PIN, SCALE_SCK_PIN);

SimpleTimer timer;

unsigned int notified = 0;
void resetNotified() {
  notified = 0;
}

void saveConfigCallback () {  //callback notifying us of the need to save config
  Serial.println("Should save config");
  shouldSaveConfig = true;
}

void load() {
  float weight = scale.get_units(1);
  Blynk.virtualWrite(V7, weight);
  if (weight <= (atoi(low_level)) && notified == 0) {
    notified = 1;
    Blynk.email(email_id, "warning", "lowload");
    timer.setTimeout(30000L, resetNotified); // 15 min between emails
  }
}

void tempsens() {
  float t = dht.readTemperature();
  Blynk.virtualWrite(V6, t);
  if (t >= 25 && notified == 0) { // check to see if flag is also set
    notified = 1;
    Blynk.email(email_id, "warning", "Temperature over 25C!");
    timer.setTimeout(30000L, resetNotified); // 5 min between emails
  }
}

void smoke() {
  float lpg = analogRead(gaspin);
  Blynk.virtualWrite(V8, lpg);
  if (lpg > 15 && notified == 0) {
    notified = 1;
    Blynk.email(email_id, "warning", "smoke");
    timer.setTimeout(30000L, resetNotified); // 5 min between emails
  }
}

void setup() {

  Serial.begin(115200);

  Serial.println();

  //SPIFFS.format();    //clean FS, for testing
  Serial.println("Mounting FS...");    //read configuration from FS json

  if (SPIFFS.begin()) {
    Serial.println("Mounted file system");
    if (SPIFFS.exists("/config.json")) {
      //file exists, reading and loading
      Serial.println("Reading config file");
      File configFile = SPIFFS.open("/config.json", "r");
      if (configFile) {
        Serial.println("Opened config file");
        size_t size = configFile.size();
        // Allocate a buffer to store contents of the file.
        std::unique_ptr<char[]> buf(new char[size]);

        configFile.readBytes(buf.get(), size);
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject(buf.get());
        json.printTo(Serial);
        if (json.success()) {
          Serial.println("\nparsed json");

          strcpy(blynk_token, json["blynk_token"]);
          strcpy(low_level, json["low_level"]);
          strcpy(email_id, json["email_id"]);

        } else {
          Serial.println("Failed to load json config");
        }
      }
    }
  } else {
    Serial.println("Failed to mount FS");
  }
  //end read

  // The extra parameters to be configured (can be either global or just in the setup)
  // After connecting, parameter.getValue() will get you the configured value
  // id/name placeholder/prompt default length
  WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 33);   // was 32 length
  WiFiManagerParameter custom_low_level("low", "low level", low_level, 5);
  WiFiManagerParameter custom_email_id("email_id", "email id", email_id, 50);
  Serial.println(blynk_token);
  Serial.println(low_level);
  Serial.println(email_id);

  //WiFiManager
  //Local intialization. Once its business is done, there is no need to keep it around
  WiFiManager wifiManager;

  wifiManager.setSaveConfigCallback(saveConfigCallback);   //set config save notify callback

  //set static ip
  // this is for connecting to Office router not GargoyleTest but it can be changed in AP mode at 192.168.4.1
  //wifiManager.setSTAStaticIPConfig(IPAddress(192,168,10,111), IPAddress(192,168,10,90), IPAddress(255,255,255,0));

  wifiManager.addParameter(&custom_blynk_token);   //add all your parameters here
  wifiManager.addParameter(&custom_low_level);
  wifiManager.addParameter(&custom_email_id);

  //wifiManager.resetSettings();  //reset settings - for testing

  //set minimu quality of signal so it ignores AP's under that quality
  //defaults to 8%
  //wifiManager.setMinimumSignalQuality();

  //sets timeout until configuration portal gets turned off
  //useful to make it all retry or go to sleep, in seconds
  wifiManager.setTimeout(600);   // 10 minutes to enter data and then Wemos resets to try again.

  //fetches ssid and pass and tries to connect, if it does not connect it starts an access point with the specified name
  //and goes into a blocking loop awaiting configuration
  if (!wifiManager.autoConnect("Wifiscale", "12345678")) {
    Serial.println("Failed to connect and hit timeout");
    delay(3000);
    //reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(5000);
  }
  Serial.println("Connected SmartBase :)");   //if you get here you have connected to the WiFi

  strcpy(blynk_token, custom_blynk_token.getValue());    //read updated parameters
  strcpy(low_level, custom_low_level.getValue());
  strcpy(email_id, custom_email_id.getValue());


  if (shouldSaveConfig) {      //save the custom parameters to FS
    Serial.println("saving config");
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
    json["blynk_token"] = blynk_token;
    json["low_level"] = low_level;
    json["email_id"] = email_id;

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile) {
      Serial.println("Failed to open config file for writing");
    }

    json.printTo(Serial);
    json.printTo(configFile);
    configFile.close();
    //end save
  }

  Serial.println("local ip");
  Serial.println(WiFi.localIP());


  scale.set_scale(23562);// <- set here calibration factor!!!
  scale.tare();

  Blynk.config(blynk_token);
  Blynk.connect();

  dht.begin();
  scale.begin(D2, D3);

  timer.setInterval(3000L, tempsens);
  timer.setInterval(2000L, load);
  timer.setInterval(1000L, smoke);

}

void loop()
{
  Blynk.run(); // Initiates Blynk
  timer.run(); // Initiates SimpleTimer
}

This limitation is only for manual Blynk.email invocation. Eventor doesn’t have this limitation. (only 100 emails per day)

Thanks for looking into matter,

Yes but with respect to code I have attached I am getting email at define interval for 1st event whrere other 2 event also above/below its set points.

Your code doesn’t seem to me correct. I think you may replace your Blynk.email instructions with corresponding Eventor events.

@Costas @Dmitriy
Thanks for your concern, but I really dont understand as I said I am copy-paste programmer.

I am getting email also but only for event which happened early.

if you can share any example then I will do changes accordingly.

I have google for similar example but didn’t find anything related.