/* ESP & Blynk */
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define BLYNK_PRINT Serial
/* Blynk credentials */
char auth[] = "hgffffffffffffffffffff";
/* WiFi credentials */
char ssid[] = "zzzzzzzzz";
char pass[] = "xxxxxxxxx";
/* TIMER */
#include <SimpleTimer.h>
SimpleTimer timer;
/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include<DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
int temp_0;
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
DS18B20.begin();
timer.setInterval(1000L, getSendData);
Serial.println(" ");
Serial.println("tst");
if(temp_0 > 26){
Blynk.email("qqqqqqqq@gmail.com", " Alert", "Temp 26C!");
Blynk.notify(" Alert - Temp 26C!");
}
}
void loop()
{
timer.run();
Blynk.run();
}
/***************************************************
* Send Sensor data to Blynk
**************************************************/
void getSendData()
{
DS18B20.requestTemperatures();
temp_0 = DS18B20.getTempCByIndex(0);
Serial.print("Temp_0: ");
Serial.print(temp_0);
Blynk.virtualWrite(10, temp_0); //virtual pin V10
}
Please properly format your posted code…
If you format your code correctly, I’ll explain why it doesn’t work.
Pete.
did you add email widget on your phone?
This is in your setup()
… but that is not going to do any good there It should be in the getSendData()
function, after reading the sensor.
However, you have no provision that prevents it from constantly sending every second until the temperature drops below 26… thus your email and notifications will get blocked to prevent spamming.
Yes, I did
Yes, I did it
Thanks
Thank you very much for your prompt response
Yes! I moved it to getSendData()
and it works! I received email and notifications. But you are right it sends every second. I should find some way to delay alerts like every 20min
thanks again