Re-connection issue with Blynk Edgent and NodeMCU

Yes off course i only added these two lines in the ConfigMode.h to tell me and you where the code gets blocked
Ok i remove them and again re-produce with the fresh new Blynk.Edgent example …

I ensure you i did not add these messages anywhere else as i m also going to post .ino file in full.

and i could not understand this sentence.

Like this…

// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID           "REDACTED"
#define BLYNK_DEVICE_NAME           "REDACTED"

Pete.

1 Like

this is my .ino file down below with no any changes in Blynk.Edgent example but now i can tell you (forgot to mention before) that my ESP restarts and now you can see no further move (again reminding no internet case when rebooted/restarted),

as i have unplugged the “wan cable” from my internet router it should have run my part of code (edgentTimer.run) though but you can see when it enters in CONNECTING_NET => CONNECTING_CLOUD after restart in the absence of internet it stucks/hangs/blocks at this mode where i have already told you dear Pete.


#define BLYNK_TEMPLATE_ID             "TMPL8tPPCuZk"
#define BLYNK_DEVICE_NAME             "Watch ME"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
//#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD

#include "BlynkEdgent.h"
#include <WidgetRTC.h>

WidgetRTC rtc;

void RequestTime();
void ClockDisplay();

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

  setSyncInterval(10 * 60);
  Blynk.sendInternal("rtc", "sync");
  
  BlynkEdgent.begin();
  edgentTimer.setInterval(1000L, RequestTime);
  edgentTimer.setInterval(1000L, ClockDisplay);
  }

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

void RequestTime() 
 {
  Blynk.sendInternal("rtc", "sync");
  }

void ClockDisplay()
 {
  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentDate = String(day()) + " " + month() + " " + year();
  
  Serial.print("\n");
  Serial.print("Current time: ");
  Serial.print(currentTime);
  Serial.print("\t");
  Serial.print(currentDate);
  Serial.println();

  Blynk.virtualWrite(V0, currentTime);
  Blynk.virtualWrite(V1, currentDate);
  }
 

and here is the most fresh fresh fresh output of serial monitor below


[167531] Current time: Sun Oct 10 15:53:14 2021
[167532] Connecting to blynk.cloud:443

Current time: 0:2:51	1 1 1970
[171301] Ready (ping: 14ms).
[171489] CONNECTING_CLOUD => RUNNING
[171515] Configuration stored to flash

Current time: 0:2:52	1 1 1970
[172310] Time sync: OK

Current time: 20:53:20	10 10 2021
[173322] Time sync: OK

Current time: 20:53:21	10 10 2021
[174907] Time sync: OK

Current time: 20:53:21	10 10 2021
[175331] Time sync: OK

Current time: 20:53:22	10 10 2021
[176307] Time sync: OK

Current time: 20:53:24	10 10 2021
[177757] Time sync: OK

Current time: 20:53:25	10 10 2021
[179056] Time sync: OK

Current time: 20:53:25	10 10 2021

Current time: 20:53:26	10 10 2021
[181354] Time sync: OK
[181358] Time sync: OK

Current time: 20:53:29	10 10 2021
[181739] Time sync: OK

Current time: 20:53:29	10 10 2021
[182329] Time sync: OK

Current time: 20:53:30	10 10 2021
[183936] Time sync: OK

Current time: 20:53:31	10 10 2021
[184315] Time sync: OK

Current time: 20:53:31	10 10 2021
[185308] Time sync: OK

Current time: 20:53:33	10 10 2021
[186320] Time sync: OK

Current time: 20:53:33	10 10 2021
[187316] Time sync: OK

Current time: 20:53:35	10 10 2021

Current time: 20:53:36	10 10 2021
[189770] Time sync: OK
[189773] Time sync: OK

Current time: 20:53:37	10 10 2021
[190309] Time sync: OK

Current time: 20:53:38	10 10 2021

Current time: 20:53:39	10 10 2021
[193016] Time sync: OK
[193017] Time sync: OK

Current time: 20:53:40	10 10 2021
[193893] Time sync: OK

Current time: 20:53:41	10 10 2021

Current time: 20:53:42	10 10 2021
[196225] Time sync: OK
[196226] Time sync: OK

Current time: 20:53:43	10 10 2021
[196633] Time sync: OK

Current time: 20:53:44	10 10 2021
[197350] Time sync: OK

Current time: 20:53:45	10 10 2021
[198374] Time sync: OK

Current time: 20:53:45	10 10 2021
[199320] Time sync: OK

Current time: 20:53:47	10 10 2021
[200798] Time sync: OK

Current time: 20:53:48	10 10 2021
[201323] Time sync: OK

Current time: 20:53:48	10 10 2021
[202312] Time sync: OK

Current time: 20:53:50	10 10 2021
[203338] Time sync: OK

Current time: 20:53:50	10 10 2021
[204329] Time sync: OK

Current time: 20:53:52	10 10 2021
[205880] Time sync: OK

Current time: 20:53:52	10 10 2021
[206839] Time sync: OK

Current time: 20:53:53	10 10 2021
[207332] Time sync: OK

Current time: 20:53:54	10 10 2021
[208308] Time sync: OK

Current time: 20:53:55	10 10 2021
[209309] Time sync: OK

Current time: 20:53:57	10 10 2021
[210879] Time sync: OK

Current time: 20:53:58	10 10 2021
[211327] Time sync: OK

Current time: 20:53:59	10 10 2021
[212869] Time sync: OK

Current time: 20:53:59	10 10 2021
[213828] Time sync: OK

Current time: 20:54:0	10 10 2021
[214309] Time sync: OK

Current time: 20:54:2	10 10 2021
[215312] Time sync: OK

Current time: 20:54:3	10 10 2021
[216926] Time sync: OK

Current time: 20:54:4	10 10 2021
[217329] Time sync: OK

Current time: 20:54:4	10 10 2021
[218318] Time sync: OK

Current time: 20:54:6	10 10 2021

Current time: 20:54:7	10 10 2021
[220473] Time sync: OK
[220984] Time sync: OK

Current time: 20:54:8	10 10 2021
[221329] Time sync: OK

Current time: 20:54:8	10 10 2021
[222310] Time sync: OK

Current time: 20:54:10	10 10 2021
[223316] Time sync: OK

Current time: 20:54:11	10 10 2021

Current time: 20:54:12	10 10 2021
[225697] Time sync: OK
[225700] Time sync: OK

Current time: 20:54:13	10 10 2021
[226310] Time sync: OK

Current time: 20:54:14	10 10 2021
[227335] Time sync: OK

Current time: 20:54:15	10 10 2021
[228789] Time sync: OK

Current time: 20:54:16	10 10 2021
[230310] Time sync: OK

Current time: 20:54:17	10 10 2021
[231064] Time sync: OK

Current time: 20:54:18	10 10 2021
[231528] Time sync: OK

Current time: 20:54:19	10 10 2021
[233204] Time sync: OK

Current time: 20:54:19	10 10 2021
[233396] Time sync: OK

Current time: 20:54:22	10 10 2021

Current time: 20:54:23	10 10 2021
[235518] Time sync: OK
[235520] Time sync: OK

Current time: 20:54:23	10 10 2021
[236880] Time sync: OK

Current time: 20:54:23	10 10 2021
[237316] Time sync: OK

Current time: 20:54:24	10 10 2021
[238310] Time sync: OK

Current time: 20:54:25	10 10 2021
[239308] Time sync: OK

Current time: 20:54:27	10 10 2021
[241138] Time sync: OK

Current time: 20:54:28	10 10 2021
[241384] Time sync: OK

Current time: 20:54:29	10 10 2021
[242408] Time sync: OK

Current time: 20:54:30	10 10 2021

Current time: 20:54:31	10 10 2021
[244660] Time sync: OK
[244662] Time sync: OK

Current time: 20:54:32	10 10 2021

Current time: 20:54:34	10 10 2021

Current time: 20:54:35	10 10 2021
[248347] Time sync: OK
[248348] Time sync: OK
[248350] Time sync: OK

Current time: 20:54:35	10 10 2021
[248757] Time sync: OK

Current time: 20:54:36	10 10 2021
[249475] Time sync: OK

Current time: 20:54:38	10 10 2021

Current time: 20:54:39	10 10 2021

Current time: 20:54:40	10 10 2021

Current time: 20:54:41	10 10 2021

Current time: 20:54:42	10 10 2021

Current time: 20:54:43	10 10 2021

Current time: 20:54:44	10 10 2021

Current time: 20:54:51	10 10 2021
[269071] Current time: Sun Oct 10 15:54:55 2021
[269071] Connecting to blynk.cloud:443
[285030] Connection failed
[285031] RUNNING => CONNECTING_CLOUD

Current time: 20:55:12	10 10 2021
[285047] Current time: Sun Oct 10 15:55:11 2021
[285055] Connecting to blynk.cloud:443
[301000] Connection failed

Current time: 20:55:28	10 10 2021
[301016] Current time: Sun Oct 10 15:55:27 2021
[301016] Connecting to blynk.cloud:443
[316917] Connection failed

Current time: 20:55:44	10 10 2021
[316933] Current time: Sun Oct 10 15:55:43 2021
[316934] Connecting to blynk.cloud:443
[332850] Connection failed

Current time: 20:56:0	10 10 2021
[332865] Current time: Sun Oct 10 15:55:59 2021
[332865] Connecting to blynk.cloud:443
[348755] Connection failed

Current time: 20:56:16	10 10 2021
[348760] Timeout
[348761] CONNECTING_CLOUD => ERROR

Current time: 20:56:16	10 10 2021

Current time: 20:56:17	10 10 2021

Current time: 20:56:18	10 10 2021

Current time: 20:56:19	10 10 2021

Current time: 20:56:20	10 10 2021

Current time: 20:56:21	10 10 2021

Current time: 20:56:22	10 10 2021

Current time: 20:56:23	10 10 2021

Current time: 20:56:24	10 10 2021

Current time: 20:56:25	10 10 2021
[358764] Restarting after error.
?⸮T!⸮⸮Dt9⸮0
>[389] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.0.1 on NodeMCU

[412] --------------------------
[448] Product:  Watch ME
[475] Firmware: 0.1.0 (build Oct 10 2021 20:49:02)
[529] Token:    ...UF7D
[555] Device:   NodeMCU @ 80MHz
[589] MAC:      98:F4:AB:B3:D9:FC
[626] Flash:    4096K
[650] ESP core: 2.7.4
[674] ESP SDK:  2.2.2-dev(38a443e)
[711] Boot Ver: 31
[732] Boot Mode:1
[752] FW info:  464016/1630208, MD5:ac9b48a9abceb923a6d3d292fbac608b
[961] Free mem: 30864
[961] --------------------------
[961] INIT => CONNECTING_NET
[988] Connecting to WiFi: IjSpNet03315357072

Current time: 0:0:1	1 1 1970

Current time: 0:0:2	1 1 1970
[3461] Using Dynamic IP: 192.168.1.104
[3461] CONNECTING_NET => CONNECTING_CLOUD

after another restart while sitting on the same chair for the past 15 hours continuously with water and bread (absolutely with no internet for ESP) hahaha

>[385] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.0.1 on NodeMCU

[409] --------------------------
[444] Product:  Watch ME
[471] Firmware: 0.1.0 (build Oct 10 2021 21:21:44)
[526] Token:    ...UF7D
[552] Device:   NodeMCU @ 80MHz
[586] MAC:      98:F4:AB:B3:D9:FC
[622] Flash:    4096K
[646] ESP core: 2.7.4
[670] ESP SDK:  2.2.2-dev(38a443e)
[708] Boot Ver: 31
[729] Boot Mode:1
[748] FW info:  464016/1630208, MD5:35c6288425b2747de1941c5eec1c68d1
[958] Free mem: 31608
[958] --------------------------
[958] INIT => CONNECTING_NET
[985] Connecting to WiFi: IjSpNet03315357072

Current time: 0:0:1	1 1 1970

Current time: 0:0:2	1 1 1970

Current time: 0:0:4	1 1 1970
[4919] Using Dynamic IP: 192.168.1.104
[4919] CONNECTING_NET => CONNECTING_CLOUD

at this time i unplugged the wan cable (to re-create the absence of internet) you can see connection failure but after it restarts the whole thing you can see … where it ends …


    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.0.1 on NodeMCU

[412] --------------------------
[448] Product:  Watch ME
[475] Firmware: 0.1.0 (build Oct 10 2021 20:49:02)
[529] Token:    ...UF7D
[555] Device:   NodeMCU @ 80MHz
[589] MAC:      98:F4:AB:B3:D9:FC
[626] Flash:    4096K
[650] ESP core: 2.7.4
[674] ESP SDK:  2.2.2-dev(38a443e)
[711] Boot Ver: 31
[732] Boot Mode:1
[752] FW info:  464016/1630208, MD5:ac9b48a9abceb923a6d3d292fbac608b
[961] Free mem: 30864
[961] --------------------------
[961] INIT => CONNECTING_NET
[988] Connecting to WiFi: IjSpNet03315357072

Current time: 0:0:1	1 1 1970

Current time: 0:0:2	1 1 1970
[3461] Using Dynamic IP: 192.168.1.104
[3461] CONNECTING_NET => CONNECTING_CLOUD

These are Legacy commands.

I’d change this from once every second to once every hour.

Also, I’d declare my own BlynkTimer object rather than piggy-backing on the edgentTimer object,

As for the rest of what you’ve posted, across two posts, it would take hours to try to make sense of the data and your comments. What you post needs to be concise and relevant, and have an understandable commentary running alongside it if you want others to try to unpick what exactly your issue is.

Pete.

Ok, i have also removed them but still the same issue,

It was just to re-create and show you what and where the issue was as per your suggestions,

i would not like it too but you have seen i just re-produced the issue with fresh .ino files therefore no need to relate anything from the previous posts and replies

I think the language barrier is the cause of misunderstanding, after all those steps have been taken which were recommended by you,

specially after this line :point_up_2:

I am still expecting you would point to some logic where the code is hanging/blocking, it is crystal clear in my last above replies as all those steps were taken under your directions, please tell me what point is not understandable at least.

It is also a good suggestion unfortunately has been tried and no luck, also the piggy-backing timer works fine. BTW i did not understand the word “piggy-backing”
as the edgentTimer always run during the different mode changes therefore can’t be neglected/left so easily, also the edgentTimer is itself a Blynktimer object therefore it is not problematic in any case.

again repeating blynk.run() in the config.h is blocking the code when “power on but no internet case”, should we declare it the a bug in blynk library dear Pete ?

@PeteKnight Hello Pete, i still have the same issue can you please suggest me something further

I’ve taken a step back from this topic because you haven’t taken on board my suggestion to present your aims and the issues you are facing in a clear and concise manner.
All I’m seeing is lots of serial output without any corresponding commentary, and repeated comments that you’re simply doing what I’ve asked you to do.

I’ll happily come back to it if you start from the beginning and explain the issue in detail and document what problems you are encountering, with updated code and focussed and well documented serial output which relates to that code and demonstrates these issues.

Pete.

From what I understand, BLYNK Edgent is blocking. That is, without internet it just keeps on trying to connect, and will not allow other parts of the program to run.

Someone please correct me if this has changed, or if I am wrong about this.

I tried a sketch with some offline actions and it worked very well without internet connection.

Well that is good to hear. I may have to give it another try when I get some time. I currently use WIFImanager, and have been for some time.

I will send you the sketch

@John93 Hello John, did you even first of all powered your device when internet was not available ???

@PeteKnight Well, you have taken a step back but you did not point the un-understandable point in my code and serial output i just request you to re-create the problem by using simple code which i have posted. There is only one simple problem

  • That simple code is not executing when i power my ESP12E when internet is not available, that’s it.

I am wondering what part of serial outputs are not understandable in my previous posts, its quite weird, i need your help seriously bro. I’ve mentioned the problem, the piece of code and the serial output, what can i give further more?

I don’t think I could be much clearer about the fact that dumping hundreds of lines of serial output into the topic without any commentary isn’t helping others to understand what point you are trying to demonstrate with each of these pieces of information.

It won’t. Blynk.begin is a blocking function. The solution is to manage the WiFi connection yourself, then use Blynk.config and Blynk.begin to establish the connection to the Blynk server in a non-blocking way if the connection can’t be made.
Blynk.run (or BlynkEdgent.run) will also force Blynk to try to re-connect each time it’s called, so a Blynk.connected test is needed to avoid this slowing down the code execution.

Pete.

@Hashmi123

What do you mean exactly ?

@John93 i mean that first of all just make sure that your device has no internet access and then power it up and show me the serial output.

@PeteKnight I told you that i am facing the stopping of code execution at Blynk.run() inside this function void enterConnectCloud() and specifically i would say its a Blynk.connect() inside the Blynk.run() which is cause of stopping the code execution.
Its important, i am using BlynkEdgent.begin() and BlynkEdgent.run() therefore it was assumed that no more blocking will be faced due to newly upgraded Blynk.Edgent libraries,

I would like to try this suggestion also and soon will show you the output, however i supposed these tasks were now taken care completely by the Blynk.Edgent

and so far for this, i am tell you this Blynk.connected test is being very well carried out by Blynk.Edgent, here you can see in Configmode.h file :point_down:

while ((timeoutMs > millis()) && (!Blynk.isTokenInvalid()) && (Blynk.connected() == false))
         {
          delay(10);
          
          Blynk.run();
          app_loop();

          
          if (!BlynkState::is(MODE_CONNECTING_CLOUD)) 
             {Blynk.disconnect();
              return;}
           }

There isn’t a Blynk.Edhent library as such. All of the “library” files are contained within the sketch, so you have full visibility of what they do and when.

As you can see when you look at the .h tabs within the example file, Blynk.Edgent is simply a wrapper for the underlying Blynk library files, which have changed very little since Blynk Legacy.

Yes, this will try to execute Blynk.run every time it’s called and Blynk.connected is false. When using Blynk.config every time Blynk.run is called when Blynk.connected is false, a re-connection attempt to the server will be made. This has a default timeout of 30 seconds, so calling it constantly will in effect block all code execution when a connection is not possible…

Try reading this topic from here:

Pete.

In Settings.h the new timeout is 60 seconds …

but in connecting cloud mode Blynk.run() is called in while loop thats why it is blocking …

please suggest me a way out of this situation …

We seem to be having a conversation about the same issue in two different places. Maybe you should choose one place and stick to it, and try to phrase your questions/comments way that are easier to follow.

I think we’re talking about two different timeouts here. I’m referring to the default that is applied if you don’t specify a timeout period in the Blynk.connect() command.

Pete.