Login Timeout

yup put it behind a timer at 500ms, then make sure you set a boolean after you send the email so that it only sends once.

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

void monitorFridge(){
  if (tempCong >= -8 && !sentNotice) 
    {
      //Blynk.notify("Temperatura alta!");
      Blynk.email("rodrigo.cavalheiro@gmail.com", "Alerta de temperatura", "Câmara de congelados acima de -8C!");
     sentNotice= 1; // mark it sent so it doesnt loop and flood
     } else if(tempCong != -8) {
   sentNotice= 0;
}
}

Jamin, that was awesome!

I can read the temperatures in the app but I don’t receive the emails.
Please notice that there are 2 temp sensors.
Both boolean variables were declared correctly.

My code:

    void setup()
    {
  // Set console baud rate
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  DS18B20.begin();
  DS18B20B.begin();

  timer.setInterval(5000L, sendTemps); // Temperature sensor polling interval (5000L = 5 seconds)
  
}

void sendTemps()
{
  DS18B20.requestTemperatures(); // Polls the sensors
  DS18B20B.requestTemperatures();

  tempCong = DS18B20.getTempCByIndex(0); // Gets first probe on wire in lieu of by address
  tempResf = DS18B20B.getTempCByIndex(0);

  Blynk.virtualWrite(4, tempCong);
  Blynk.virtualWrite(5, tempResf);
}

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

void monitorFridge(){
  if (tempCong >= -8 && !sentNotice1) 
    {
      //Blynk.notify("Temperatura alta!");
      Blynk.email("rodrigo.cavalheiro@gmail.com", "Alerta de temperatura", "Câmara de congelados acima de -8C!");
     sentNotice1= 1; // mark it sent so it doesnt loop and flood
     } else if(tempCong < -8) {
   sentNotice1= 0;
}
  if (tempResf >= 11 && !sentNotice2) 
    {
      //Blynk.notify("Temperatura alta!");
      Blynk.email("rodrigo.cavalheiro@gmail.com", "Alerta de temperatura", "Câmara de congelados acima de 11C!");
     sentNotice2= 1; // mark it sent so it doesnt loop and flood
     } else if(tempResf < 11 ) {
   sentNotice2= 0;
}
}

Hey firstly just make sure you format your code correctly.
do this:

```
code
```

also you forgot to set up a timer for monitorFridge().

timerFridge = timer.setInterval(500L, monitorFridge); 

Jamin, last question: I can’t receive the emails.

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

void monitorFridge(){
  if (tempCong >= -8 && !sentNotice1) 
    {
      //Blynk.notify("Temperatura alta!");
     Blynk.email("rodrigo.cavalheiro@gmail.com", "Congelados > Alerta de temperatura", "Câmara de congelados acima de -8C!");
     sentNotice1= 1; // mark it sent so it doesnt loop and flood
     } else if(tempCong < -8) {
     sentNotice1= 0;
}
  if (tempResf >= 11 && !sentNotice2) 
    {
      //Blynk.notify("Temperatura alta!");
     Blynk.email("rodrigo.cavalheiro@gmail.com", "Refrigerados > Alerta de temperatura", "Câmara de refrigerados acima de 11C!");
     sentNotice2= 1; // mark it sent so it doesnt loop and flood
     } else if(tempResf < 11 ) {
     sentNotice2= 0;
}
}

Also, I put a timerFridge.setInterval(5000L, monitorFridge); in void setup()

Thanks!

where is sentnotice declared?

Please paste your code in it’s entirety.

Here it ts.

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#define ONE_WIRE_BUS 10
#define TWO_WIRE_BUS 11

#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <TimeLib.h>
#include <SimpleTimer.h>

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);

OneWire twoWire(TWO_WIRE_BUS);
DallasTemperature DS18B20B(&twoWire);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "token";


// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "RingOfFire";
char pass[] = "xxxxxxx";

//variables
float tempCong;
float tempResf;
boolean sentNotice1;
boolean sentNotice2;
SimpleTimer timer;
SimpleTimer timerFridge;

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

void setup()
{
  // Set console baud rate
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  DS18B20.begin();
  DS18B20B.begin();

  timer.setInterval(5000L, sendTemps); // Temperature sensor polling interval (5000L = 5 seconds)
  timerFridge.setInterval(5000L, monitorFridge);
}

void sendTemps()
{
  DS18B20.requestTemperatures(); // Polls the sensors
  DS18B20B.requestTemperatures();

  tempCong = DS18B20.getTempCByIndex(0); // Gets first probe on wire in lieu of by address
  tempResf = DS18B20B.getTempCByIndex(0);

  Blynk.virtualWrite(4, tempCong);
  Blynk.virtualWrite(5, tempResf);
}

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

void monitorFridge(){
  if (tempCong >= -8 && !sentNotice1) 
    {
      //Blynk.notify("Temperatura alta!");
     Blynk.email("rodrigo.cavalheiro@gmail.com", "Congelados > Alerta de temperatura", "Câmara de congelados acima de -8C!");
     sentNotice1= 1; // mark it sent so it doesnt loop and flood
     } else if(tempCong < -8) {
     sentNotice1= 0;
}
  if (tempResf >= 11 && !sentNotice2) 
    {
      //Blynk.notify("Temperatura alta!");
     Blynk.email("rodrigo.cavalheiro@gmail.com", "Refrigerados > Alerta de temperatura", "Câmara de refrigerados acima de 11C!");
     sentNotice2= 1; // mark it sent so it doesnt loop and flood
     } else if(tempResf < 11 ) {
     sentNotice2= 0;
}
}

btw - this is how i run simpletimer:

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#define ONE_WIRE_BUS 10
#define TWO_WIRE_BUS 11

#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <TimeLib.h>
#include <SimpleTimer.h>

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);

OneWire twoWire(TWO_WIRE_BUS);
DallasTemperature DS18B20B(&twoWire);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "token";


// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "RingOfFire";
char pass[] = "xxxxxxx";

//variables
float tempCong;
float tempResf;
boolean sentNotice1;
boolean sentNotice2;
SimpleTimer timer;

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

void setup()
{
  // Set console baud rate
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  DS18B20.begin();
  DS18B20B.begin();

  timer.setInterval(5000L, sendTemps); // Temperature sensor polling interval (5000L = 5 seconds)
  timer.setInterval(5000L, monitorFridge);
}

void sendTemps()
{
  DS18B20.requestTemperatures(); // Polls the sensors
  DS18B20B.requestTemperatures();

  tempCong = DS18B20.getTempCByIndex(0); // Gets first probe on wire in lieu of by address
  tempResf = DS18B20B.getTempCByIndex(0);

  Blynk.virtualWrite(4, tempCong);
  Blynk.virtualWrite(5, tempResf);
}

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

void monitorFridge() {
  if (tempCong >= -8 && !sentNotice1)
  {
    //Blynk.notify("Temperatura alta!");
    Blynk.email("rodrigo.cavalheiro@gmail.com", "Congelados > Alerta de temperatura", "Câmara de congelados acima de -8C!");
    sentNotice1 = 1; // mark it sent so it doesnt loop and flood
  } 
  else if (tempCong < -8) 
  {
    sentNotice1 = 0;
  }
  if (tempResf >= 11 && !sentNotice2)
  {
    //Blynk.notify("Temperatura alta!");
    Blynk.email("rodrigo.cavalheiro@gmail.com", "Refrigerados > Alerta de temperatura", "Câmara de refrigerados acima de 11C!");
    sentNotice2 = 1; // mark it sent so it doesnt loop and flood
  } 
  else if (tempResf < 11 ) 
  {
    sentNotice2 = 0;
  }
}

you should add in some serial prints to see if/where the code is not working…

1 Like

No success at all… No email sent. Do you guys have any idea?

use serial prints to see where it is failing.

void monitorFridge() {
  if (tempCong &gt;= -8 && !sentNotice1)
  {
    //Blynk.notify("Temperatura alta!");
    Blynk.email("rodrigo.cavalheiro@gmail.com", "Congelados &gt; Alerta de temperatura", "Câmara de congelados acima de -8C!");
serial.Print(F("temp is high! just tried to send email"));
    sentNotice1 = 1; // mark it sent so it doesnt loop and flood
  } 
  else if (tempCong &lt; -8) 
  {
    serial.Print(F("temp is OK! no need to send email"));
sentNotice1 = 0;
  }
  if (tempResf &gt;= 11 && !sentNotice2)
  {
    //Blynk.notify("Temperatura alta!");
    Blynk.email("rodrigo.cavalheiro@gmail.com", "Refrigerados &gt; Alerta de temperatura", "Câmara de refrigerados acima de 11C!");
    sentNotice2 = 1; // mark it sent so it doesnt loop and flood
  } 
  else if (tempResf &lt; 11 ) 
  {
    sentNotice2 = 0;
  }
}

Hello!

I changed the code to include serial prints, tried to change the email but email still not working.

Serial monitor:

[19] Blynk v0.3.10 on Arduino Uno
[520] Connecting to Papa-Rica Wi-Fi
[3585] 
OK
[6727] 192.168.1.100
[6757] Connected to WiFi
temp is high! just tried to send email[14504] Login timeout
[26024] Login timeout
[36716] Login timeout
[46937] Ready (ping: 1589ms).

Even when I try to send a “Success login” notification or email on void setup() it completely ignores the command.
Do I have to call any library for notifications or email?

Output from last code:

[19] Blynk v0.3.10 on Arduino Uno
[525] Connecting to Papa-Rica Wi-Fi
[3592] 0018000902-AI03
[6731] 192.168.1.100
[6761] Connected to WiFi
temp is high! just tried to send email
[14529] Login timeout
[25542] Ready (ping: 1588ms).
[43947] Heartbeat timeout
[53080] Ready (ping: 1589ms).
temp is OK! no need to send email
temp is OK! no need to send email
temp is OK! no need to send email
temp is OK! no need to send email
temp is OK! no need to send email
temp is OK! no need to send email
temp is high! just tried to send email
[138557] Login timeout

Looks a bit like “flooding”?

Try changing the frequency from 5 seconds to 70 seconds…

Obvious question but have you set up email widget on the app fully?

Hi Dave!

I made it work correctly!
Next challenge (but I don’t know how to code): if temperature stays above X degrees for more than Y minutes…

Thanks!

that’s great, but how did you do it?!

that is hard, it is easier to see if temp is above X every Y minutes.

otherwise you have to start using an average or median to know if the temperature STAYS above X

in my HVAC code, i use runningMedian to smooth out my temps and know that when i look at the temps every X minutes, i know that the temps is not an aberration, so it is reliable enough to use to make decisions…

or more simply you can check temp every X/5 minutes and keep a count of how many times during X the temp is higher than Y - if it is higher than Y 5 times, then trigger your warnings…???

My code (didn’t change too much according to the last code):

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#define ONE_WIRE_BUS 10
#define TWO_WIRE_BUS 11

#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <TimeLib.h>
#include <SimpleTimer.h>

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);

OneWire twoWire(TWO_WIRE_BUS);
DallasTemperature DS18B20B(&twoWire);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "TOKEN";


// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Papa-Rica Wi-Fi";
char pass[] = "password";

//variables
float tempCong;
float tempResf;
boolean sentNotice1;
boolean sentNotice2;
SimpleTimer timer;
SimpleTimer timerFridge;

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

void setup()
{
  // Set console baud rate
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  DS18B20.begin();
  DS18B20B.begin();
  
  timer.setInterval(5000L, sendTemps); // Temperature sensor polling interval (5000L = 5 seconds)
  timerFridge.setInterval(10000L, monitorFridge);
}

void sendTemps()
{
  DS18B20.requestTemperatures(); // Polls the sensors
  DS18B20B.requestTemperatures();

  tempCong = DS18B20.getTempCByIndex(0); // Gets first probe on wire in lieu of by address
  tempResf = DS18B20B.getTempCByIndex(0);

  Blynk.virtualWrite(4, tempCong);
  Blynk.virtualWrite(5, tempResf);
}

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

void monitorFridge()
{
     if (tempCong >= -7 && !sentNotice1) 
        {
        Blynk.email("rodrigo.cavalheiro@gmail.com", "Congelados > Alerta de temperatura", "Câmara de congelados acima de -8C!");
        sentNotice1= 1; // mark it sent so it doesnt loop and flood
        }
        else if(tempCong < -7)
          {
          sentNotice1= 0;
          }
     
     if (tempResf >= 11 && !sentNotice2) 
        {
        Blynk.email("rodrigo.cavalheiro@gmail.com", "Refrigerados > Alerta de temperatura", "Câmara de refrigerados acima de 11C!");
        sentNotice2= 1; // mark it sent so it doesnt loop and flood
        } 
        else if(tempResf < 11 ) 
           {
           sentNotice2= 0;
           }
      
}

About your suggestion:

or more simply you can check temp every X/5 minutes and keep a count of how many times during X the temp is higher than Y - if it is higher than Y 5 times, then trigger your warnings

This is exactly what I want.
I’m working on it. If you have any advice, please share it!
Thank you!

If the temperature is over X, trigger the temperature timer.
|20°c 10secs|
|TRIGGERED| <=Not like this.
The temperature timer should check every D secs till It exceeds Y. (Where D is a constant integer lower than Y, 2 is recommended)
If it falls before Y, stop.
If it exceeds Y, send the e-mail.

3 posts were merged into an existing topic: Does Auth Token or Account Login have expiry