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

Sending multiple gmails with Wemos D1 R1

esp8266

#1

Hello, my project is working but after pressing the button that is connected to d2 and sending 1 email it does not send another one even if I press again how can I make it so it sends a email every time I press the button?
From what I can see from the Value display widget D2 is on high and when I press it goes to low and stay on low maybe this is the problem?


#define BLYNK_PRINT Serial
/* Set this to a bigger number, to enable sending longer messages */
//#define BLYNK_MAX_SENDBYTES 128

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

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

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

void emailOnButtonPress()
{
  // *** WARNING: You are limited to send ONLY ONE E-MAIL PER 15 SECONDS! ***

  // 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
  {
    Serial.println("Button is pressed."); // This can be seen in the Serial Monitor
    Blynk.email("Subject: Button Logger", "You just pushed the button...");

    // Or, if you want to use the email specified in the App (like for App Export):
    //Blynk.email("Subject: Button Logger", "You just pushed the button...");
  }
}

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

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

  // 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("Subject: Button Logger", "You just pushed the button...");

  // Setting the button
  pinMode(2, INPUT_PULLUP);
  // Attach pin 2 interrupt to our handler
  attachInterrupt(digitalPinToInterrupt(2), emailOnButtonPress, CHANGE);
}

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


#2

From your code, it seems that you are using an ESP8266/NodeMCU device.

The pin labelled D2 on your board is not GPIO2, it’s GPIO4. Your pinmode and interrupt declarations expect the physical switch to be connected to GPIO2, and as you’re using a pull-up on the pin, the other side of the switch should be connected to GND.

You also really need a timer and a flag to ensure that you don’t exceed the one email request per 15 seconds limit.

Pete.


#3

Hello, I am new to arudino coding and have a project in school to do and would like to send a notification when the force sensor detects that a object is lifted from it, i’m using a Wemos D1 R1 here is the code that I have right now but is not working could anyone help me fix it?

#define BLYNK_PRINT Serial
/* Set this to a bigger number, to enable sending longer messages */
//#define BLYNK_MAX_SENDBYTES 128

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

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

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

void emailOnButtonPress()
{
  // *** WARNING: You are limited to send ONLY ONE E-MAIL PER 15 SECONDS! ***

  // Let's send an e-mail when you press the button

  int isButtonPressed = AO; // Invert state, since button is "Active LOW"

  if (isButtonPressed=LOW) // You can write any condition to trigger e-mail sending
  {
    Serial.println("Button is pressed."); // This can be seen in the Serial Monitor
    Blynk.email("jordandaudu@gmail.com", "Subject: Button Logger", "You just pushed the button...");

    // Or, if you want to use the email specified in the App (like for App Export):
    //Blynk.email("Subject: Button Logger", "You just pushed the button...");
  }
}

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

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

  // 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("jordandaudu@gmail.com", "Subject", "My Blynk project is online.");

  // Setting the button
  pinMode(AO, INPUT_PULLUP);
  // Attach pin A0 interrupt to our handler
  attachInterrupt(digitalPinToInterrupt(A0), emailOnButtonPress, CHANGE);
}

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

#4

@JordanXcraft Please don’t create multiple topics for same issue :frowning: … I merged them both here.


#5

Once again, you’re doing odd things with your choice of pins.
A0 is an analogue pin, and most people use strain gauges with an amplifier chip which turns the analogue readings into a 2 wire digital signal.
If you’re not using an amplifier then it depends on what circuitry you’re using to get an appropriate signal level onto your ESP8266. Rather than using an interrupt in this situation, you’ll probably need to sample the value that you’re getting from your analogue input on a regular basis and evaluate the readings to create a changeover point where you send an email once that point is reached.

Pete.