Widget Email

Hello everyone, I’m having a problem with my project with ARDUINO UNO and I can not solve it.

I set a PIN DIGITAL (ex. PIN 2) that when it is HIGH send me an email, but the problem is when this PIN becomes HIGH, Arduino send me an email but then becomes increasingly ONLINE and therefore unusable.

Can someone help me?

Thanks so much !!

I think you are going to have to provide more details for this phrase.

When Arduino sends the email, it quickly becomes offline … that it disconnect from the Server Blynk and no longer communicates with the sensors and the APP.

@gabriel85 disconnections from the server are almost always due to badly written sketches.

If you would like to post a formatted sketch then maybe someone will spot the problem in your sketch.

I would guess that you are breaking the 15 second rule for sending emails and hence the server drops you.

#include <Blynk.h>
#define BLYNK_PRINT Serial
/* Set this to a bigger number, to enable sending longer messages */
//#define BLYNK_MAX_SENDBYTES 128

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

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

#define W5100_CS  10
#define SDCARD_CS 4


IPAddress server_ip (46, 101, 143, 225);

// Mac address should be different for each device in your LAN
byte arduino_mac[] = { 0xAB, 0xED, 0xAF, 0xEB, 0xDE, 0xBD };      
IPAddress arduino_ip ( 192,   168,   1,  13);
IPAddress dns_ip     (  8,   8,   8,   8);
IPAddress gateway_ip ( 192,   168,   1,   1);
IPAddress subnet_mask(255, 255, 255,   0);



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("your_email@mail.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);

  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

  Blynk.begin(auth);

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

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

Please go back and edit your post @gabriel85

Copy this example to format your code correctly.

```cpp
CODE
```

1 Like

I’m sorry, but … how can I do it?

Sorry…can you help me, plese?

Just edit your post, select the code and click this icon:

This will not work. Follow my example above.

1 Like

Or let @Pavel do it :+1:

Now Pavel, can you correct ALL the others?? my OCD like tendencies are acting up :stuck_out_tongue_winking_eye:

Just kidding of course :wink:

1 Like

thanks guys…now i try :wink:

#include <Blynk.h>
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

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

#define W5100_CS  10
#define SDCARD_CS 4

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("your_email@mail.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);

  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

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

  // 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();
}

this is my code…

could someone help me solve this problem?

I see you are using a physical button press, and on an interrupt… you might be experiencing button bounce, effectively trying to email multiple times in a single press… and possibly on both rising and falling signals (I haven’t used interrupts enough to be sure on that one).

Either way… not good. Don’t need to use interrupt unless really required for timing precision and use some form of debouncing routine in your code. As referenced here: https://www.arduino.cc/en/Tutorial/Debounce

1 Like

this definetly works for me!
(unfortunatley i always have to use this method, because my ` button on my keyboard is broken :frowning: )

It’ll fail if you use a single ` in your code anywhere and also won’t colour c++ syntax correctly.

I’ve been asking the devs to mod the forum (Discourse) code to fix the issue

yeah, probably you’re right. but as i can not use that button, i can never have any ` in my code :slight_smile: this is why it always works for me :))

my —> ``` <— button :wink:

Use the on screen keyboard provided by your OS assuming you run Windows :wink: