Hello all, I am new to this. I am using an ESP8266 - 12e and it works great with the standalone, Now i want to get a working Emailer setup on one of them. The plan is to put a PIR in my garage, and every time someone is in there it will email me. are there working examples out there ?
thanks
Thanks Dmitriy, I tried the following code. It gets an error when compiling "
exit status 1
âemailOnButtonPressâ was not declared in this scope`
/**************************************************************
- Blynk is a platform with iOS and Android apps to control
- Arduino, Raspberry Pi and the likes over the Internet.
- You can easily build graphic interfaces for all your
- projects by simply dragging and dropping widgets.
- Downloads, docs, tutorials: http://www.blynk.cc
- Blynk community: http://community.blynk.cc
- Social networks: http://www.fb.com/blynkapp
-
http://twitter.com/blynk_app
- Blynk library is licensed under MIT license
- This example code is in public domain.
- This example runs directly on ESP8266 chip.
- You need to install this for ESP8266 development:
- https://github.com/esp8266/Arduino
- Please be sure to select hte right ESP8266 module
- in the Tools -> Board menu!
- Change WiFi ssid, pass, and Blynk auth token to run
**************************************************************/
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = âYourAuthTokenâ;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, âssidâ, âpassâ);
while (Blynk.connect() == false) {
// Wait until connected
}
// Send e-mail when your hardware gets connected to Blynk Server
// Just put the recepientâs âe-mail addressâ, âSubjectâ and the âmessage bodyâ
Blynk.email("your_email@mail.com", âSubjectâ, âMy Blynk project is online.â);
// Setting the button
pinMode(2, INPUT_PULLUP);
// Attach pin 2 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(2), emailOnButtonPress, CHANGE);
}
void emailOnButtonPress()
{
// *** WARNING: You are limited to send ONLY ONE E-MAIL PER MINUTE! ***
// Letâs send an e-mail when you press the button
// connected to digital pin 2 on your Arduino
int isButtonPressed = !digitalRead(2); // Invert state, since button is âActive LOWâ
if (isButtonPressed) // You can write any condition to trigger e-mail sending
{
BLYNK_LOG(âButton is pressed.â); // This can be seen in the Serial Monitor
Blynk.email("your_email@mail.com", âSubject: Button Loggerâ, âYou just pushed the buttonâŚâ);
}
}
void loop()
{
Blynk.run();
}
You donât need to use exactly this sketch. It is just example as you have ESP8266. Just add email command within your ESP code, thatâs it.
@ryan_blynk with the very latest Arduino / ESP8266 the functions need to be in a SPECIFIC order so move void emailOnButtonPress() function before void setup(). It should then compile.
I did that, now it is telling me
Arduino: 1.6.7 (Windows 10), Board: âGeneric ESP8266 Module, Serial, 80 MHz, 40MHz, DIO, 115200, 512K (64K SPIFFS), ckâ
ESP8266_email_1:38: error: expected constructor, destructor, or type conversion before â(â token
pinMode(2, INPUT_PULLUP);
^
ESP8266_email_1:40: error: expected constructor, destructor, or type conversion before â(â token
attachInterrupt(digitalPinToInterrupt(2), emailOnButtonPress, CHANGE);
^
C:\Users\ryanm\Desktop\ESP8266_email_1\ESP8266_email_1.ino: In function âvoid emailOnButtonPress()â:
ESP8266_email_1:76: error: a function-definition is not allowed here before â{â token
{
^
ESP8266_email_1:78: error: expected â}â at end of input
}
^
exit status 1
expected constructor, destructor, or type conversion before â(â token
This report would have more information with
âShow verbose output during compilationâ
enabled in File > Preferences.
/**************************************************************
- Blynk is a platform with iOS and Android apps to control
- Arduino, Raspberry Pi and the likes over the Internet.
- You can easily build graphic interfaces for all your
- projects by simply dragging and dropping widgets.
- Downloads, docs, tutorials: http://www.blynk.cc
- Blynk community: http://community.blynk.cc
- Social networks: http://www.fb.com/blynkapp
-
http://twitter.com/blynk_app
- Blynk library is licensed under MIT license
- This example code is in public domain.
- This example runs directly on ESP8266 chip.
- You need to install this for ESP8266 development:
- https://github.com/esp8266/Arduino
- Please be sure to select hte right ESP8266 module
- in the Tools -> Board menu!
- Change WiFi ssid, pass, and Blynk auth token to run
**************************************************************/
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = âYourAuthTokenâ;
// Setting the button
pinMode(2, INPUT_PULLUP);
// Attach pin 2 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(2), emailOnButtonPress, CHANGE);
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, âssidâ, âpassâ);
while (Blynk.connect() == false) {
// Wait until connected
}
// Send e-mail when your hardware gets connected to Blynk Server
// Just put the recepientâs âe-mail addressâ, âSubjectâ and the âmessage bodyâ
Blynk.email("your_email@mail.com", âSubjectâ, âMy Blynk project is online.â);
}
void emailOnButtonPress()
{
// *** WARNING: You are limited to send ONLY ONE E-MAIL PER MINUTE! ***
// Letâs send an e-mail when you press the button
// connected to digital pin 2 on your Arduino
int isButtonPressed = !digitalRead(2); // Invert state, since button is âActive LOWâ
if (isButtonPressed) // You can write any condition to trigger e-mail sending
{
BLYNK_LOG(âButton is pressed.â); // This can be seen in the Serial Monitor
Blynk.email("your_email@mail.com", âSubject: Button Loggerâ, âYou just pushed the buttonâŚâ);
}
void loop()
{
Blynk.run();
}
@ryan_blynk are your two includeâs as shown below as they are invisible if you donât format the sketch with the </> icon?
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
Think you messed up when you moved the function but without the sketch being formatted it is hard to tell. This is what you need, compiles fine.
//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
void emailOnButtonPress()
{
// *** WARNING: You are limited to send ONLY ONE E-MAIL PER MINUTE! ***
// Let's send an e-mail when you press the button
// connected to digital pin 2 on your Arduino
int isButtonPressed = !digitalRead(2); // Invert state, since button is "Active LOW"
if (isButtonPressed) // You can write any condition to trigger e-mail sending
{
BLYNK_LOG("Button is pressed."); // This can be seen in the Serial Monitor
Blynk.email("your_email@mail.com", "Subject: Button Logger", "You just pushed the button...");
}
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, "ssid", "pass");
while (Blynk.connect() == false) {
// Wait until connected
}
// Send e-mail when your hardware gets connected to Blynk Server
// Just put the recepient's "e-mail address", "Subject" and the "message body"
Blynk.email("your_email@mail.com", "Subject", "My Blynk project is online.");
// Setting the button
pinMode(2, INPUT_PULLUP);
// Attach pin 2 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(2), emailOnButtonPress, CHANGE);
}
void loop()
{
Blynk.run();
}
Thank you it works great now.