Telegram crashes

Hello all,

I have a problem with the following code below.
Every time Blynk sends a telegram, it will be rebooted. If the Telegram line (bot.sendMessage(“XXXX”, String(counter)):wink: is commented, the serial monitor is nicely showing the detection.

I am using a Wemos D1 mini lite

What am I doing wrong?


/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  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
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  You’ll need:
   - Blynk App (download from AppStore or Google Play)
   - ESP8266 board
   - Decide how to connect to Blynk
     (USB, Ethernet, Wi-Fi, Bluetooth, ...)

  There is a bunch of great example sketches included to show you how to get
  started. Think of them as LEGO bricks  and combine them as you wish.
  For example, take the Ethernet Shield sketch and combine it with the
  Servo example, or choose a USB sketch and add a code from SendData
  example.
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h> 
#include <BlynkSimpleEsp8266_SSL.h>
#include <WiFiClientSecure.h>
#include <TelegramBot.h>

// Initialize Telegram BOT
const char BotToken[] = "XXXX";
WiFiClientSecure net_ssl;
TelegramBot bot (BotToken, net_ssl);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XXXX";
int counter = 0;
int buzzer = 0;
BlynkTimer timer;
int doorbell=0;
int doorbell_detect=0;

void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  doorbell = doorbell + 1;
  if (buzzer=1){
  counter = counter + 1;
  Serial.println(counter);
    if (counter >=5){
      digitalWrite(D5, LOW);
    }
  }
}


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

BLYNK_WRITE(V0) {
  if (param.asInt()) {
    digitalWrite(D5, HIGH);
    counter = 0;
    Serial.print("counter reset");
    buzzer = 1;
  }
}



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", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
  timer.setInterval(1000L, myTimerEvent);

   // Setup notification button on pin D6
  pinMode(D6, INPUT);
  doorbell_detect=0;
  // Attach pin D6 interrupt to our handler
  attachInterrupt(digitalPinToInterrupt(D6), notifyOnButtonPress, CHANGE);

}


void notifyOnButtonPress()
{
  // Invert state, since button is "Active LOW"
  int isButtonPressed = !digitalRead(D6);
  //Serial.println(isButtonPressed);
  if (isButtonPressed) {
    if (doorbell >= 15){
      doorbell = 0;
      doorbell_detect=1;
      Serial.println("Doorbell detected"); 
      bot.sendMessage("XXXX", String(counter));
    } 
  }
}

void loop()
{
  Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
    timer.run(); // Initiates BlynkTimer
    notifyOnButtonPress();
}

Perhaps you should be running this function call in a timer as well? Instead of in the void loop() where if you press the button this function is called hundreds/thousands of times a second = disconnection :wink:

than I get this:

Exception (29):
epc1=0x4020e36e epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000004 depc=0x00000000

ctx: cont 
sp: 3fff0b90 end: 3fff1520 offset: 01a0

>>>stack>>>
3fff0d30:  00820000 00000082 3fff8444 4021b646  
3fff0d40:  3fff0414 3fff86c4 3fff8444 4021b840  
3fff0d50:  3fffbafc 00000208 3fffbafc 40100670  
3fff0d60:  00000104 0000a0b8 00001417 00000042  
3fff0d70:  00000040 00000082 3fffa224 4021bb59  
3fff0d80:  00800000 00000080 00000000 00000041  
3fff0d90:  00000040 0000003f 3fff5ddc 00000041  
3fff0da0:  3fffb6e4 3fffa224 3fff5ddc 3fff8bc4  
3fff0db0:  3fffbbf8 ffffffff 3fff86c4 402068b0  
3fff0dc0:  00000040 3fff86c4 3fffa224 3fff86c4  
3fff0dd0:  00000040 3fff86c4 3fffa224 4021c693  
3fff0de0:  3fff8764 0000003f 3c68f607 00000001  
3fff0df0:  3fff86c4 3fffa20c 3fffa224 00000001  
3fff0e00:  00000010 3fff86c4 0000000f 4021c8e8  
3fff0e10:  3fff5ddc 3fff89a4 0000000f 00000001  
3fff0e20:  00000001 3fff5dc4 3fff65ca 4021b6ec  
3fff0e30:  00000100 3fff8734 3fff6587 00000000  
3fff0e40:  00000100 3fff8734 3fff6587 4021db01  
3fff0e50:  3fff0e80 00000000 000000d0 00000030  
3fff0e60:  df1f12d5 3fff5de8 3fff5dd0 00000004  
3fff0e70:  3fff6581 3fff5e4c 3fff6581 4021876c  
3fff0e80:  c3020303 9688e93d d004223e cc01b9e6  
3fff0e90:  58801972 ff0aedcb a852e5ab d2f218d1  
3fff0ea0:  6970312f 7c69bd3e 7af817c4 12d5d654  
3fff0eb0:  3fff6581 00000004 3fff5e4c 40218c01  
3fff0ec0:  ed7fa74a 2c09e9c7 ad799967 402159ac  
3fff0ed0:  fa6b2c23 3fffc6fc 3fff0500 40211509  
3fff0ee0:  00000000 00000004 00000004 40204537  
3fff0ef0:  00000006 00001246 00000064 40206870  
3fff0f00:  0000004a 00000000 00000026 00000004  
3fff0f10:  3fff6581 00000004 3fff5e4c 00000004  
3fff0f20:  3fff6581 00000004 3fff5e4c 40218574  
3fff0f30:  0eb2b1b0 00000000 00000000 00000027  
3fff0f40:  0000005c 3fff6581 3fff5e4c 40218950  
3fff0f50:  00000010 3fff65b4 3fff5e4c 401004d8  
3fff0f60:  3fff0fb0 0000000e 00000010 00000000  
3fff0f70:  00000000 3fff24ec 3fff5e4c 01000000  
3fff0f80:  3fff0fb0 3fff295c 3fff5e4c 402186dc  
3fff0f90:  3fff0104 3fff295c 3fff0104 3fff5aac  
3fff0fa0:  00008a35 3fff295c 3fff0104 40204d3c  
3fff0fb0:  3fff0104 00000000 3fff5a74 40203f42  
3fff0fc0:  3fff5a74 00003a98 3fff1458 3fff00f8  
3fff0fd0:  000001bb 3fff0104 3ffe939a 3fff00f8  
3fff0fe0:  000001bb 3fff0104 3ffe939a 40204ea1  
3fff0ff0:  3ffe9618 dca79a95 3ffe9618 dca79a95  
3fff1000:  3fff14b0 3fff1458 3fff00f8 40205348  
3fff1010:  3fff2924 00000023 3fff00f8 402053f8  
3fff1020:  0000007d 00000000 3fff1458 4020630d  
3fff1030:  3fff1070 3fff14b0 3fff1458 402063cc  
3fff1040:  3fff1070 3fff1094 3fff1464 3fff00f8  
3fff1050:  3fff1070 3fff14b0 3fff1464 40205c47  
3fff1060:  3ffe9538 3fff1070 000003e8 00000037  
3fff1070:  3fff1060 3fff1078 3fff1094 3ffe94b6  
3fff1080:  00000002 3fff1088 37373834 38303839  
3fff1090:  ffff0039 00000000 3ffe948c 00000002  
3fff10a0:  3fff10a4 3f003132 3fff1b1c 00000001  
3fff10b0:  40233d3e 3ffedb98 3fff1b1c 3ffedb98  
3fff10c0:  00000002 00000000 00000020 40100ec6  
3fff10d0:  3ffea402 40232d07 3ffedb98 3fff2a8a  
3fff10e0:  00000000 40226397 3ffef018 a4247ff5  
3fff10f0:  00000000 00000002 00000000 3ffedb98  
3fff1100:  3fff2a8a 40104456 3fff1edc 3fff28cc  
3fff1110:  ec7e1d7e cd289c6a dd16feea aca8d66b  
3fff1120:  22265c9d 80000000 00000000 00000000  
3fff1130:  00000000 00000000 00000000 00000000  
3fff1140:  00000000 00000000 40233be3 00000000  
3fff1150:  ffffffff 00000000 3ffea551 00000000  
3fff1160:  c3bc5b83 18e106ed abf0289b 6cfed4b9  
3fff1170:  73b9f885 80000000 00000000 00000000  
3fff1180:  00000000 00000000 00000000 00000000  
3fff1190:  00000000 00000000 00000000 000002a0  
3fff11a0:  d098e630 e83fa4a8 b093a57d 78cc6512  
3fff11b0:  370cb85b 61274afa f198ca24 6e1975f6  
3fff11c0:  637f5995 334edd18 bd15a117 3766790e  
3fff11d0:  0884ca86 b865d29b 2cccaa34 1d4432f1  
3fff11e0:  76239087 1ee36d2d 4f9d1d80 b15d8cc2  
3fff11f0:  a1e7aba9 f18de02f 1eed6a8e c3e8636d  
3fff1200:  b3891054 084d476a 73c82af8 1bae6e07  
3fff1210:  1bc518e3 4ec8557a bf587c74 b71448a5  
3fff1220:  89ff9053 3157b5e2 554da8e8 a5032573  
3fff1230:  00000005 00000000 00000020 40100ec6  
3fff1240:  3ffea405 401042c3 3ffede40 89336161  
3fff1250:  40101be1 3ffede40 a3d595fb 0a6103fa  
3fff1260:  00007fff 02188022 3ffee8c8 40101db2  
3fff1270:  3ffeaca4 00000000 00000000 adb00ac4  
3fff1280:  00007fff 02188022 401021f2 00000100  
3fff1290:  7fffffff 3ffeaca4 3ffeaca4 00000001  
3fff12a0:  00000001 00000080 00000000 1a1b0783  
3fff12b0:  00007fff 02188022 00000000 4000050c  
3fff12c0:  3fffc278 40101f8c 3fffc200 00000022  
3fff12d0:  3ffeacb0 00000080 00000005 00000000  
3fff12e0:  402044c1 00000030 00000014 ffffffff  
3fff12f0:  40204995 3fff316c 3fff3cf1 00000005  
3fff1300:  00000005 00000000 00000020 40100ec6  
3fff1310:  3ffea405 401042c3 3ffede40 00000005  
3fff1320:  40101be1 3ffede40 01860017 00000030  
3fff1330:  00007fff 021a1023 3ffee8c8 40101db2  
3fff1340:  3ffeacb0 00000000 00000000 00000005  
3fff1350:  00007fff 021a1023 401021f2 00000100  
3fff1360:  7fffffff 3ffeacb0 3ffeacb0 00000001  
3fff1370:  00000001 00000080 0000001f 40104ee9  
3fff1380:  4000050c 021a1023 00000000 4000050c  
3fff1390:  3fffc278 40101f8c 3fffc200 00000022  
3fff13a0:  3ffeacbc 00000023 00000001 00000001  
3fff13b0:  4000e235 00000030 00000010 ffffffff  
3fff13c0:  00000000 00000000 0000001f 40104ee9  
3fff13d0:  00000000 00000000 0000001f 3fff0414  
3fff13e0:  00000010 00000010 00000000 4010053d  
3fff13f0:  33323130 37363534 62613938 66656463  
3fff1400:  6a696867 6e6d6c6b 7271706f 3fff04f4  
3fff1410:  00000010 3fff14c8 3fff14c8 4020628f  
3fff1420:  3fff1470 00000002 3fff14c8 402062db  
3fff1430:  3ffefeac 00000009 3fff14c8 4020630d  
3fff1440:  3ffefc60 3fff0434 3fff14c8 40206439  
3fff1450:  3fff1470 3fff14bc 3fff5a3c 0000002f  
3fff1460:  00000023 3fff2924 0000002f 00000023  
3fff1470:  3fff1464 3fff0434 3fff14bc 4020630d  
3fff1480:  3fff14c8 00000000 3fff14bc 4020635a  
3fff1490:  3ffe8a4f 3fff0144 3fff0434 3fff04f4  
3fff14a0:  3ffefc60 3fff0434 3fff00f4 4020256d  
3fff14b0:  00000000 3fff0144 3fff0120 3fff6154  
3fff14c0:  0000000f 00000009 3fff290c 0000000f  
3fff14d0:  00000002 3fff0434 3fff04ec 40204f48  
3fff14e0:  00000000 3ffefeac 3ffefeac 4020511c  
3fff14f0:  3fffdad0 00000000 3fff04ec 4020355c  
3fff1500:  3fffdad0 00000000 3fff04ec 40206844  
3fff1510:  feefeffe feefeffe 3fff0500 40100710

This is bad code, you should be using == not =

Probably bad use of attachInterrupt()

I don’t think so, if I want to send the telegram message via the pushbutton buzzer, it ends up in reboots as well

Push button buzzer works fine without telegram

if (buzzer==1){
  counter = counter + 1;
  Serial.println(counter);
    if (counter >=5){
      digitalWrite(D5, LOW);
      bot.sendMessage("XXX", String(counter));