Code stopped in case of CONNECTING_CLOUD failure

Hello everyone
My simple code (blinking inbuilt LED) works fine.
But if the router looses connection to WAN, ESP8266 is restarting after error and connects successful to WIFI.
Up to this time everything is OK and the inbuilt LED is blinking, but stops, when trying to connect to cloud.
What must I do to keep up code in case of lost WAN?
This problem does not occure when WIFI connection is lost.

Chris

19:21:46.760 -> [1468376] Heartbeat timeout
19:21:47.035 -> [1468681] RUNNING => CONNECTING_CLOUD
19:21:47.035 -> [1468692] Current time: Mon Mar 28 17:21:46 2022
19:21:47.035 -> [1468693] Connecting to blynk.cloud:443
19:21:47.081 -> [1468703] Connection failed
19:21:52.088 -> [1473705] Current time: Mon Mar 28 17:21:51 2022
19:21:52.088 -> [1473706] Connecting to blynk.cloud:443
19:21:52.268 -> [1473911] Connection failed
19:21:57.055 -> [1478712] Current time: Mon Mar 28 17:21:56 2022
19:21:57.099 -> [1478712] Connecting to blynk.cloud:443
19:21:57.099 -> [1478725] Connection failed
19:22:02.102 -> [1483722] Current time: Mon Mar 28 17:22:01 2022
19:22:02.102 -> [1483722] Connecting to blynk.cloud:443
19:22:02.102 -> [1483731] Connection failed
19:22:07.099 -> [1488723] Current time: Mon Mar 28 17:22:06 2022
19:22:07.099 -> [1488724] Connecting to blynk.cloud:443
19:22:07.099 -> [1488733] Connection failed
19:22:12.090 -> [1493733] Current time: Mon Mar 28 17:22:11 2022
19:22:12.090 -> [1493734] Connecting to blynk.cloud:443
19:22:12.090 -> [1493745] Connection failed
19:22:17.088 -> [1498742] Current time: Mon Mar 28 17:22:16 2022
19:22:17.088 -> [1498742] Connecting to blynk.cloud:443
19:22:17.133 -> [1498752] Connection failed
19:22:22.084 -> [1503743] Current time: Mon Mar 28 17:22:21 2022
19:22:22.129 -> [1503743] Connecting to blynk.cloud:443
19:22:22.129 -> [1503749] Connection failed
19:22:27.129 -> [1508751] Current time: Mon Mar 28 17:22:27 2022
19:22:27.129 -> [1508751] Connecting to blynk.cloud:443
19:22:27.129 -> [1508760] Connection failed
19:22:32.136 -> [1513761] Current time: Mon Mar 28 17:22:32 2022
19:22:32.136 -> [1513761] Connecting to blynk.cloud:443
19:22:32.136 -> [1513771] Connection failed
19:22:37.135 -> [1518763] Current time: Mon Mar 28 17:22:37 2022
19:22:37.135 -> [1518763] Connecting to blynk.cloud:443
19:22:37.135 -> [1518773] Connection failed
19:22:42.135 -> [1523773] Current time: Mon Mar 28 17:22:42 2022
19:22:42.135 -> [1523773] Connecting to blynk.cloud:443
19:22:42.135 -> [1523782] Connection failed
19:22:47.037 -> [1528686] Timeout
19:22:47.037 -> [1528687] CONNECTING_CLOUD => ERROR
19:22:57.035 -> [1538687] Restarting after error.
19:22:57.170 -> 
19:22:57.170 ->  ets Jan  8 2013,rst cause:2, boot mode:(3,6)
19:22:57.170 -> 
19:22:57.170 -> load 0x4010f000, len 3460, room 16 
19:22:57.170 -> tail 4
19:22:57.170 -> chksum 0xcc
19:22:57.170 -> load 0x3fff20b8, len 40, room 4 
19:22:57.170 -> tail 4
19:22:57.170 -> chksum 0xc9
19:22:57.170 -> csum 0xc9
19:22:57.170 -> v00071ed0
19:22:57.170 -> ~ld
19:22:57.442 -> [290] 
19:22:57.442 ->     ___  __          __
19:22:57.442 ->    / _ )/ /_ _____  / /__
19:22:57.488 ->   / _  / / // / _ \/  '_/
19:22:57.488 ->  /____/_/\_, /_//_/_/\_\
19:22:57.488 ->         /___/ v1.0.1 on ESP8266
19:22:57.488 -> 
19:22:57.488 -> [292] --------------------------
19:22:57.488 -> [295] Product:  Wasser
19:22:57.488 -> [297] Hardware: 1.0.0
19:22:57.488 -> [299] Firmware: 0.1.0 (build Mar 28 2022 18:55:14)
19:22:57.488 -> [303] Token:    ...Ycse
19:22:57.488 -> [306] Device:   ESP8266 @ 80MHz
19:22:57.488 -> [308] MAC:      3C:61:05:D3:C9:05
19:22:57.488 -> [311] Flash:    4096K
19:22:57.488 -> [313] ESP core: 3.0.2
19:22:57.488 -> [315] ESP SDK:  2.2.2-dev(38a443e)
19:22:57.488 -> [319] Boot Ver: 6
19:22:57.488 -> [320] Boot Mode:1
19:22:57.488 -> [322] FW info:  466640/1630208, MD5:2d1a3148d39161d533f45f0942f02614
19:22:57.717 -> [534] Free mem: 32736
19:22:57.717 -> [534] --------------------------
19:22:57.717 -> [534] INIT => CONNECTING_NET
19:22:57.717 -> [535] Connecting to WiFi: willi
19:23:06.437 -> [9277] Using Dynamic IP: 192.168.2.114
19:23:06.437 -> [9277] CONNECTING_NET => CONNECTING_CLOUD
#define BLYNK_TEMPLATE_ID "TMPLd7qM4v8A"
#define BLYNK_DEVICE_NAME "Wasser"
#define BLYNK_FIRMWARE_VERSION        "0.1.0"
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
//#define BLYNK_DEBUG
#define APP_DEBUG
#define USE_NODE_MCU_BOARD
#include "BlynkEdgent.h"

void setup(){
  pinMode(D0,OUTPUT);//blinken
  digitalWrite(D0,HIGH);
  pinMode(D1,OUTPUT);//Rel1
  digitalWrite(D1,HIGH);
  pinMode(D5,OUTPUT);//Rel2
  digitalWrite(D5,HIGH);
  pinMode(D6,OUTPUT);//Rel3
  digitalWrite(D6,HIGH);
  pinMode(D7,OUTPUT);//Rel4
  digitalWrite(D7,HIGH);
  pinMode(D2,INPUT);//Temp
  Serial.begin(115200);
  timer.setInterval(500L,blinken);
  BlynkEdgent.begin();}


void blinken(){
  if(digitalRead(D0)==LOW){digitalWrite(D0,HIGH);}//blinken
  else{digitalWrite(D0,LOW);}
  }


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

First of all, BlynkEdgent.begin and BlynkEdgent.run are both blocking functions.

Second,

To use timer you have to define a BlynkTimer object first, then add a function in the void loop to call it.
I recommend you to read this very useful article

The restart is called by this piece of code at the end of the ConfigMode.h tab…

void enterError() {
  BlynkState::set(MODE_ERROR);
  
  unsigned long timeoutMs = millis() + 10000;
  while (timeoutMs > millis() || g_buttonPressed)
  {
    delay(10);
    app_loop();
    if (!BlynkState::is(MODE_ERROR)) {
      return;
    }
  }
  DEBUG_PRINT("Restarting after error.");
  delay(10);

  restartMCU();
}

If you want to edit this to perform differently then you could - at your own risk.

Pete.

Thank you very much John
“An improved version of SimpleTimer (referred to as BlynkTimer) is included within the Blynk library, so doesn’t need to be included separately.”

Any code is executed when ESP8266 is connected to cloud,
or disconnected to WIFI (and therefore disconnected to cloud).
But code is not executed, when connected to WIFI and disconnected to cloud.

Chris

@PeteKnight
Thank you very much Pete

I think there is a bug in blynk:
19:23:06.437 -> [9277] CONNECTING_NET => CONNECTING_CLOUD
stopping code is the bug.

Change in ConfigMode.h can delay or avoid this problem,
but this is not really a solution.
I think the restart is implemented in purpose by the developer of blynk.

The code is not interrupted when WIFI is disconnected.
ESP8266 restarts every 30 seconds, but LED is blinking all the time.

10:06:25.193 -> [272767] RUNNING => CONNECTING_CLOUD
10:06:25.193 -> [272773] Current time: Tue Mar 29 08:06:25 2022
10:06:25.193 -> [272773] Connecting to blynk.cloud:443
10:06:25.193 -> [272774] Connection failed
10:06:30.205 -> [277778] Current time: Tue Mar 29 08:06:30 2022
10:06:30.205 -> [277778] Connecting to blynk.cloud:443
10:06:30.205 -> [277779] Connection failed
10:06:35.193 -> [282783] Current time: Tue Mar 29 08:06:35 2022
10:06:35.193 -> [282783] Connecting to blynk.cloud:443
10:06:35.193 -> [282784] Connection failed
10:06:40.201 -> [287788] Current time: Tue Mar 29 08:06:40 2022
10:06:40.201 -> [287789] Connecting to blynk.cloud:443
10:06:40.201 -> [287789] Connection failed
10:06:45.235 -> [292794] Current time: Tue Mar 29 08:06:45 2022
10:06:45.235 -> [292794] Connecting to blynk.cloud:443
10:06:45.235 -> [292794] Connection failed
10:06:50.224 -> [297799] Current time: Tue Mar 29 08:06:50 2022
10:06:50.224 -> [297799] Connecting to blynk.cloud:443
10:06:50.224 -> [297800] Connection failed
10:06:55.218 -> [302804] Current time: Tue Mar 29 08:06:55 2022
10:06:55.218 -> [302804] Connecting to blynk.cloud:443
10:06:55.218 -> [302804] Connection failed
10:07:00.211 -> [307809] Current time: Tue Mar 29 08:07:00 2022
10:07:00.256 -> [307810] Connecting to blynk.cloud:443
10:07:00.347 -> [307946] Connection failed
10:07:05.251 -> [312814] Current time: Tue Mar 29 08:07:05 2022
10:07:05.251 -> [312814] Connecting to blynk.cloud:443
10:07:05.342 -> [312941] Connection failed
10:07:10.246 -> [317819] Current time: Tue Mar 29 08:07:10 2022
10:07:10.246 -> [317820] Connecting to blynk.cloud:443
10:07:10.382 -> [317936] Connection failed
10:07:15.236 -> [322827] Current time: Tue Mar 29 08:07:15 2022
10:07:15.236 -> [322827] Connecting to blynk.cloud:443
10:07:15.370 -> [322931] Connection failed
10:07:20.264 -> [327832] Current time: Tue Mar 29 08:07:20 2022
10:07:20.264 -> [327832] Connecting to blynk.cloud:443
10:07:20.355 -> [327926] Connection failed
10:07:25.207 -> [332774] Timeout
10:07:25.207 -> [332775] CONNECTING_CLOUD => ERROR
10:07:35.230 -> [342783] Restarting after error.
10:07:35.321 -> 
10:07:35.321 ->  ets Jan  8 2013,rst cause:1, boot mode:(3,7)
10:07:35.321 -> 
10:07:35.321 -> load 0x4010f000, len 3460, room 16 
10:07:35.321 -> tail 4
10:07:35.321 -> chksum 0xcc
10:07:35.321 -> load 0x3fff20b8, len 40, room 4 
10:07:35.321 -> tail 4
10:07:35.321 -> chksum 0xc9
10:07:35.321 -> csum 0xc9
10:07:35.321 -> v00071ed0
10:07:35.321 -> ~ld
10:07:35.594 -> [288] 
10:07:35.640 ->     ___  __          __
10:07:35.640 ->    / _ )/ /_ _____  / /__
10:07:35.640 ->   / _  / / // / _ \/  '_/
10:07:35.640 ->  /____/_/\_, /_//_/_/\_\
10:07:35.640 ->         /___/ v1.0.1 on ESP8266
10:07:35.640 -> 
10:07:35.640 -> [290] --------------------------
10:07:35.640 -> [292] Product:  Wasser
10:07:35.640 -> [295] Hardware: 1.0.0
10:07:35.640 -> [297] Firmware: 0.1.0 (build Mar 28 2022 18:55:14)
10:07:35.640 -> [301] Token:    ...Ycse
10:07:35.640 -> [303] Device:   ESP8266 @ 80MHz
10:07:35.640 -> [306] MAC:      3C:61:05:D3:C9:05
10:07:35.640 -> [309] Flash:    4096K
10:07:35.640 -> [311] ESP core: 3.0.2
10:07:35.640 -> [313] ESP SDK:  2.2.2-dev(38a443e)
10:07:35.640 -> [316] Boot Ver: 6
10:07:35.640 -> [318] Boot Mode:1
10:07:35.640 -> [320] FW info:  466640/1630208, MD5:2d1a3148d39161d533f45f0942f02614
10:07:35.866 -> [531] Free mem: 32736
10:07:35.866 -> [531] --------------------------
10:07:35.866 -> [531] INIT => CONNECTING_NET
10:07:35.866 -> [533] Connecting to WiFi: willi
10:08:05.867 -> [30547] CONNECTING_NET => ERROR
10:08:15.867 -> [40549] Restarting after error.

Chris