[SOLVED] Your ESP8266 went offline

Continuing the discussion from Notify Example Sketch - Esp8266 resets?:

I am having a similar problem.

My code seems to work well until I try to add some way to notify or text that the Garage Door is open.
When I add the notify or text(email) statements then I get errors such as “Your ESP8266 went offline.” or “Your ESP 8266 has been disconnected.”

I am trying to limit the number of notification / email-texts by using the SimpleTimer statement. I am not sure if i am using it correctly.

Any help would be appreciated.

Thank you,

Dave D²

/*   ********************************************************************************************
          Garage Door Opener with Alerts by D²
 *   ********************************************************************************************
*/

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

boolean detection = false;

// Set this to the correct auth number!
char auth[] = "xxxxxxxxxxxxxxxxxxxxxx";

SimpleTimer timer;

 int status = 0;                 // Door status:  0 = Closed, 1 = Open

void setup()
{
  pinMode(14, INPUT_PULLUP);  // Garage Door Magnetic Sensor

  pinMode(4, OUTPUT);       // Pin Connected to the Reed Relay to operate the garage door

  Serial.begin(9600);

  Blynk.begin(auth, "12345", "abcdefg");

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


   // Setup a function to be called every second
  timer.setInterval(1000L, garageMagSensor);   
  }


  // Notify immediately on startup
  Blynk.notify("D² Tech Garage Door Controller has started!");
}

// ========{ Garage Door Reed Switch Monitoring Loop }==================
void garageMagSensor ()
{
  int reedSW = digitalRead(14);   // GPIO14
  //int status = 0;                 // Door status:  0 = Closed, 1 = Open

  if ((status == 0) && (reedSW == 1)) //the door was closed and now it has been opened
  {
    //Blynk.email("5165551212@vtext.com", "GARAGE DOOR OPEN!", "Garage door has been opened at..."); //Sends a txt message
    Blynk.notify("Your garage door has been opened");
    status == 1;     //     the door is now open
  }

if ((status == 1) && (reedSW == 1)) // the door was open and it is still open
{status == 1;
}

if ((status == 0) && (reedSW == 0)) // the door was closed and it is still closed
{ status == 0;
}

  if ((status == 1) && (reedSW == 0)) // the door was open but now it is closed
  {
    status == 0;
  }
 
}

// ==============( Void Loop  ) ====================================

void loop()
{
  garageMagSensor();
  Blynk.run();
  timer.run(); // Initiates SimpleTimer
 yield();
}

I think I see your problem. You are calling garageMagSensor() from the loop, this is probably where it goes wrong. Since you have a timer, remove it from the loop. I’m not sure what yield() does, but you might wanna remove that too since I can’t seem to locate that function in your sketch.

Thank you for that reply. I did some changes, including what you said and i got it working!

@drdhdmd please pass the correct one after the change you made, thank you.

My Garage Door Monitor / Operator was working great until recently.

Then it just stopped. The Blynk App on my Android phone kept saying,…
“Your ESP8266 is not in network”.

I thought I finally figured out that the problem was because of the new Blynk server so I updated the libraries in my Arduino IDE but I am still getting the same error. Back to the drawing board, I suppose.

Here is the code that used to work…

/*   ********************************************************************************************
          Garage Door Opener with Alerts by D²
 *   ********************************************************************************************
*/

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

boolean detection = false;

// Set this to the correct auth number!
char auth[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";

SimpleTimer timer;

int status = 0;                 // Door status:  0 = Closed, 1 = Open

void setup()
{
  pinMode(14, INPUT_PULLUP);  // Garage Door Magnetic Sensor
  pinMode(4, OUTPUT);         // Pin Connected to the Reed Relay

  Serial.begin(9600);
  Blynk.begin(auth, "xxxxxx", "xxxxxxxxxxxxxxxxx");
  
   // Setup a function to be called every minute
timer.setInterval(60000L, garageMagSensor);

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


  // Notify immediately on startup
  Blynk.notify("D² Tech Garage Door Controller has started!");
}




// ========{ Garage Door Reed Switch Monitoring Loop }==================
void garageMagSensor()
{

int reedSW = digitalRead(14);   // GPIO14
if (reedSW == 1)
{
//
//  digitalWrite (4, HIGH);
//  Blynk.notify("Your garage door has been opened");
//}else{
// digitalWrite( 4,LOW);
//}
//
// 
////digitalWrite(4,HIGH);
////delay (100);
////digitalWrite(4,LOW);
////
//
//
  int reedSW = digitalRead(14);   // GPIO14
  //int status = 0;                 // Door status:  0 = Closed, 1 = Open
 


  if ((status == 0) && (reedSW == 1)) //the door was closed and now it has been opened
  {
    //Blynk.email("5162630411@vtext.com", "GARAGE DOOR OPEN!", "Garage door has been opened at..."); //Sends a txt message
    Blynk.notify("Your garage door has been opened");
    status == 1;     //     the door is now open
  }

if ((status == 1) && (reedSW == 1)) // the door was open and it is still open
{status == 1;
}

if ((status == 0) && (reedSW == 0)) // the door was closed and it is still closed
{ status == 0;
}

  if ((status == 1) && (reedSW == 0)) // the door was open but now it is closed
  {
    status == 0;
  } 
}
}
// ==============( Void Loop  ) ====================================

void loop()
{
  //garageMagSensor();
  Blynk.run();
  timer.run(); // Initiates SimpleTimer
//yield();
}

Do I have to uninstall the old Blynk library?

Do I have to change the #includes?

1 Like

While the code above did work, it was sometimes a bit slow. That is, sometimes it would notify as soon as the garage door was opened and sometimes there would be a delay. I presume this is because the logic to notify that the door was opened is in a 60 second loop. I would like to send a notify right away and then repeat in 60 seconds. Can you help with this?

Thank you again!

OK, so I seem to have fixed the, “out of network” problem by deleting the “blynk-library-master” folder that was in my Arduino Folder

Now onto the immediate notification modification…

Push notifications are limited to 1/minute

Yes, I understand that, but there should be a way to Push Notify, once immediately after detecting the door opening, then start the timer to continue notification once a minute.

That is what I am working on now.

BTW, Are you you located in NYC? I work in NYC and would love to meet you and buy you a beer, or whatever you like to drink…

Another question is why do I need to get the Blynk server involved at all?

In my Blynk App, on my Android phone I can see the status of the Door change from Low to High when the Door is opened.

Why can’t I use that change on the phone itself to send some type of notification or message to the Adroid phone system itself? Or can I??

Does your esp8266 connect to your router or your phone?

My esp8266 connects to my router, then to my phone via the Blynk App.

Pm me your contact details. We can definitely get some drinks. :slight_smile:

1 Like

Did something happen to the Blynk servers over the past month or so?

My program was working very well, giving notifications every 60 seconds when my garage door was open.

Now I am getting notifications almost exactly every 15 seconds. I have not made any changes to the software.

Seems strange

@drdhdmd you have some bad code in your sketch.

Blynk recently reduced the time allowed between messages from 60s to 15s so your code has always tried to send too frequently. You need to find your bug as it might be trying to send every 1ms.

Well that makes sense.
I will have to dig into it again.
Thank you for such a speedy reply!