Notify Example Sketch - Esp8266 resets?

I have a standalone ESP8266-12 on a breadboard powered by a 3.3V regulator whose input is a 5vdc 1A wallwart. Bypass (.1ufd) cap on the regulator’s pins and over 1000ufd electrolytic on the power rail.

The ‘Running for x minutes’ Notifications are being received and all seems to function well until I ground GPIO5, mimicing a switch closure. I assume the ESP8266 resets before the ‘yaaay’ Notification is sent since I do’t net the Notification on my iphone. Eventually I get the ‘Your ESP8266 went offline’ Notification. Nearly always, a reset is required to get things running again.

I would appreciate some help in pointing out where I am going wrong. Thanks - Scotty

Below is the Blynk Log:
c_ÇÏRSöâFjSöfJSúfîþ[220] Blynk v0.2.4
[220] Connecting to XXXXXXXX
[6586] Connected to WiFi
[6587] Connecting to cloud.blynk.cc:8442
[13224] Connecting to cloud.blynk.cc:8442
[13257] <msg 2,1,32
<cdc8cbb4a2c0490ebf73790f9e9752fd
[13273] >msg 0,1,200
[13273] Ready!
[13273] Roundtrip: 1ms
[13273] <msg 14,2,14
<Device started
[13365] >msg 0,2,200
[23326] <msg 6,3,0
<
[23342] >msg 0,3,200
[33341] <msg 6,4,0
<
[33357] >msg 0,4,200
[43358] <msg 6,5,0
<
[43377] >msg 0,5,200
[53378] <msg 6,6,0
<
[53392] >msg 0,6,200
[63393] <msg 6,7,0
<
[63409] >msg 0,7,200
[73325] <msg 14,8,22
<Running for 1 minutes.
[73410] <msg 6,9,0
<
[73425] >msg 0,8,200
[73425] >msg 0,9,200
[83425] <msg 6,10,0
<
[83440] >msg 0,10,200
[93441] <msg 6,11,0
<
[93457] >msg 0,11,200
[103458] <msg 6,12,0
<
[103472] >msg 0,12,200
[113473] <msg 6,13,0
<
[113489] >msg 0,13,200
[123490] <msg 6,14,0
<
[123506] >msg 0,14,200
[133325] <msg 14,15,22
<Running for 2 minutes.
[133417] >msg 0,15,200
[143379] <msg 6,16,0
<
[143395] >msg 0,16,200
[151068] Button is pressed.
[151069] <msg 14,17,27
<Yaaay… button is pressed!
[153740] Sent 0/32
<—†þ‚‚ƒ,�ƒ††‡ŽŽû‡e–Šú�úcþ[218] Blynk v0.2.4
[218] Connecting to XXXXXXXX

The sketch is below: (sorry folks, made many attempts to use code tags but couldn’t get it to work properly)

/**************************************************************
  • 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.

  • Simple push notification example
  • App dashboard setup:
  • Push widget
  • Connect a button to pin 5 and GND…
  • Pressing this button will also push a message! :wink:

**************************************************************/
#define BLYNK_DEBUG
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
//#include <Ethernet.h>
//#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>

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

SimpleTimer timer;

void setup()
{
Serial.begin(9600);
Blynk.begin(auth, “XXXXXXXX”, “xxxxxxxx”);

while (Blynk.connect() == false) {
// Wait until connected
}

// Notify immediately on startup
Blynk.notify(“Device started”);

// Setup a function to be called every minute
timer.setInterval(60000L, notifyUptime);

// Setup notification button on pin 5
pinMode(5, INPUT_PULLUP);
// Attach pin 5 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(5), notifyOnButtonPress, CHANGE);
}

void notifyUptime()
{
long uptime = millis() / 60000L;

// Actually send the message.
// Note:
// We allow 1 notification per minute for now.
Blynk.notify(String("Running for “) + uptime + " minutes.”);
}

void notifyOnButtonPress()
{
// Invert state, since button is “Active LOW”
int isButtonPressed = !digitalRead(5);
if (isButtonPressed) {
BLYNK_LOG(“Button is pressed.”);

Blynk.notify("Yaaay... button is pressed!");

}
}

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

As described happens to me!

It may be some electrical/hardware issue… Can’t tell anything as for now ;(

Same, works fine without notify code/widget and resets frequently with notify code/widget. No physical changes made.

Ok. This seems to work:


   /**************************************************************
   * 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.
   *
   **************************************************************
   * Simple push notification example
   *
   * App dashboard setup:
   *   Push widget
   *
   * Connect a button to pin 5 and GND...
   * Pressing this button will also push a message! ;)
   *
   **************************************************************/
  #define BLYNK_DEBUG
  #define BLYNK_PRINT Serial
  #include <SPI.h>
  #include <ESP8266WiFi.h>
  #include <BlynkSimpleEsp8266.h>
  //#include <Ethernet.h>
  //#include <BlynkSimpleEthernet.h>
  #include <SimpleTimer.h>
  
  boolean detection = false;
  
  // You should get Auth Token in the Blynk App.
  // Go to the Project Settings (nut icon).
  char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
  
  SimpleTimer timer;
  
  void setup()
  {
    Serial.begin(9600);
    Blynk.begin(auth, "XXXXXXXX", "xxxxxxxx");
  
    while (Blynk.connect() == false) {
      // Wait until connected
    }
  
    // Notify immediately on startup
    Blynk.notify("Device started");
  
    // Setup a function to be called every minute
    timer.setInterval(60000L, notifyDetection);
  
    // Setup notification button on pin 5
    pinMode(5, INPUT_PULLUP);
    // Attach pin 5 interrupt to our handler
    attachInterrupt(digitalPinToInterrupt(5), Detection, FALLING);
  }
  
  /*void notifyUptime()
  {
    long uptime = millis() / 60000L;
  // Actually send the message.
    // Note:
    //   We allow 1 notification per minute for now.
    Blynk.notify(String("Running for ") + uptime + " minutes.");
  }*/
  
  void Detection()
  {
    // Quick, in and out interrupt routine
    detection = true;
  }
  
  void notifyDetection()
  {
    if (detection) {
      BLYNK_LOG("Presense Detected.");
      Blynk.notify("Presense Detected!");
      detection = false;
    }
  }
  
  void loop()
  {
    Blynk.run();
    timer.run();
  }

In my experience with Arduino, I understand that an interrupt routine shoud be very quick; no non essential code within the routine. I wonder if the original code with that interrupt routine could have been the problem.

Now there is a delay in receiving the Notification. I suppose that is due to the ‘timer.setInterval(60000L, notifyDetection);’ code.

Does anyone know what happens if Notifications are sent more frequently than once a minute? Are they dumped, ignored?

If not then I suppose in most cases the delay could be eliminated if it was coded to be sent immediately if it had not been sent in the previous 61 seconds.

note: Also changed interrupt trigger to FALLING.

  • Scotty

wrap your code by pressing this magic button (Backtick`) 3 times (before the code and after it):

This makes your code readable with highlighted syntax, like this:

//comment goes here
void helloWorld() {
   String message =  "hello" + "world";
}

You can at least select the code and press </> button in the top menu: