Blynk push notification button sketch is not working with esp8266

I have created a project using esp8266. It will show a notification when the door is open. I have coded from blynk example. But after uploading the code to the device,it starts automatically again and again. I can see, uour device is connected on blynk. May be, it restarts. Sometimes, it is disconnected.
I have used the code below.

[Unformatted portion of code removed by moderator]

#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[] = "4k1JfmpomK69_N1LP8goni8DVSVs7F4r";

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

void notifyOnButtonPress()
{
 // Invert state, since button is "Active LOW"
 int isButtonPressed = !digitalRead(2);
 if (isButtonPressed) {
   Serial.println("Button is pressed.");

   // Note:
   //   We allow 1 notification per 5 seconds for now.
   Blynk.notify("Yaaay... button is pressed!");

   // You can also use {DEVICE_NAME} placeholder for device name,
   // that will be replaced by your device name on the server side.
   //Blynk.notify("Yaaay... {DEVICE_NAME}  button is pressed!");
 }
}

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

 Blynk.begin(auth, ssid, pass);
 pinMode(2, INPUT_PULLUP);
 // Attach pin 2 interrupt to our handler
 attachInterrupt(digitalPinToInterrupt(2), notifyOnButtonPress, CHANGE);
}

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

Help me please. It is urgernt.

Ohh bro, You are using interrupted without IRAM_ATTR

#define BLYNK_PRINT Serial

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

char ssid[] = "Safwan";
char pass[] = "@2255222";

char auth[] = "4k1JfmpomK69_N1LP8goni8DVSVs7F4r";

volatile bool switchPinChanged = false;
volatile int switchPinValue = 0;

#define SWITCH_PIN 2

IRAM_ATTR void checkSwitchPin()
{
  switchPinValue = !digitalRead(SWITCH_PIN);
  switchPinChanged = true;
}

void notifyOnButtonPress()
{
  if (switchPinChanged)
  {
    Serial.println("Button is pressed.");
    Blynk.notify("Yaaay... button is pressed!");
    switchPinChanged = false;
  }
}


void setup()
{
  Serial.begin(9600);

  pinMode(SWITCH_PIN, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(SWITCH_PIN), checkSwitchPin, CHANGE);

  Blynk.begin(auth, ssid, pass);
}

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

Use this

@Kayyum_Uddin ,brother it shows in blynk that my device is connected and after a while it shows my device is disconnected. I uploaded the code you have written.

@Kayyum_Uddin
bro.
Can you fix the code please. In my project, i have to connect two wires from magnetic reed switch. 1 in D1 and 1 in GND of esp8266.
When the switch is far from the magnet it will send me a notification. But with this code it sends me a notification when i supply power on the module. It sends wrong notification. It automatically sends a notification after 10 or 16 seconds that the door is open but i did not even open it.

My code:

[Unformatted code removed by moderator]

I could not use that one on my project
I have to connect my reed switch on esp8266
can you help?

help me please!
Can you fix the code please. In my project, i have to connect two wires from magnetic reed switch. 1 in D1 and 1 in GND of esp8266.
When the switch is far from the magnet it will send me a notification. But with this code it sends me a notification when i supply power on the module. It sends wrong notification. It automatically sends a notification after 10 or 16 seconds that the door is open but i did not even open it.

My code:

[Unformatted code removed by moderator]

@Kayyum_Uddin

Watch this, please!

Code is correct the issue with your hardware

@Kayyum_Uddin
I forgot to say.
I used two devices for the same blynk account.
is it problem?

May be, because I already face this scenario long time ago. When one device disconnect second device automatically disconnect

The above thread marked as solve by me even the problem not solve because I frustrated no one provide me solution

@Kayyum_Uddin but why does it show I opened the door though i did not open?
I changed my account and it is not disconnected.

@kirohan please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

@kirohan please do not tag Blynk developers in posts like this.
If you do this again your account will be suspended.
Please treat this as your one and only warning on this issue.

Pete.

Oh sorry.

Your unformatted code has been removed because you didn’t edit your posts as requested.

Pete.