BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Re-connection issue with Blynk Edgent and NodeMCU

hello dear friends, i did not start a new topic because this topic was having relative issue which i am facing right now after using Blynk.Edgent example with my own code.
I am using ESP12E(8266) hardware and arduino ide for my project.

My first major problem is that :

  • When MCU is restarted and the internet is down due to any reason, it does try to connect the cloud and keep trying but it does not start the remaining code to run, however once it is connected to the cloud it starts running my code also

My second proble is that :

  • During running the code if internet goes down and the code tries to reconnect blynk.cloud it causes bigger delays than my needs and also keep trying after shorter intervals than my needs

I am not so much new to blynk and have little experience with CPP, i switched to new blynk two weeks ago and made many improvements after resolving many issues but this time no luck. I need you guys to just push me to right direction where i can solve these issues, thanks.

Screen shots of the parts where the code is hanging are attached, i also have tried this solution which you suggested @vshymanskyy but no luck :sweat:

I am using BlynkEdgent.run i remember that this issue was not existing when i was using old Blynk libraries 1.0



In images above you can see that code is working fine along with “blynk connecting cloud” but when it comes to “reconnect” once the connection is lost for some reason it makes several tries with shorter intervals than my needs as seen in the image below

but here is the issue when MCU is restarted and “wan cable” is unplugged from the router (just to create the case when no internet is available right after restart), it does try to connect cloud but but but it does not allow the remaining code to get started,
here is the image below.

I’ve moved your post to a new topic, as the one you’ve posted in was about Blynk Legacy.

I’s suggest you post the contents of your .ino file - correctly formatted with triple backticks.

I’d also suggest that you upgrade to the latest Blynk library, and re-create your project using the latest Edgent example file.

Also, why are you using Arduino OTA rather than Blynk.Air which is built-in to Edgent?

Pete.

Thanks Pete for your reply i always expected you would be the first one.

Ok, it is really helpful for other readers, your are really very intelligent about this sort of management.

I have not posted any content from .ino file yet, if you recommend, surely it would be presented in triple backticks.

I am already downloaded and using the latest version=1.0.0-beta.3 of Blynk library and the Edgent example is from new library.
I also have checked that by using old library this issue was removed and also the intervals of time (i surely need to modify them for more smooth running of my code) were also different for “connecting to cloud” function than in the newer blynk library.

because upto this point i am not successfull with Blynk.Air update therefore using Arduino OTA over my private wifi network for ease of uploading, later i would surely remove it and use Blynk.Air (there was an issue in that, another topic)

I think Pete wanted to say , you have to post your code , not your screenshot, nobody will read your screenshot.:stuck_out_tongue_winking_eye:

@Blynk_Coeur Dear friend, these screenshots are only for proof of the problem being faced, as i have no any part of code which deals with “MODE_CONNECTING_CLOUD”, it is only given by Blynk.Edgent therefore if they recommend i would post my “ConfigMode.h” file here in triple backticks, from Blynk.Edgent example which i am using successfully for all other features provided by Blynk.
also i am using plus plan from Blynk subscription offers, thanks for participation in this discussion.

1 Like

The latest version is 1.0.1 so the 1.0.0-beta.3 library you are using has been superseded twice, and the Edgent example has been modified/improved each time - hence why I recommended upgrading.

Which topic was that?
The only issues that I’ve seen reported are caused by people not incrementing the version number in their new sketch.

So what is the purpose of your first screenshot?
If the subsequent screenshots are meant to show the serial monitor output then I’d suggest that you select the text in the serial monitor using your mouse or CTRL-A then copy it using CTRL-C and paste it into your post - also using triple backticks at the beginning and end.

Pete.

2 Likes

Yes i checked and downloaded the latest version 1.0.1 and i have noticed the major changes in Edgent example, but i am facing still the same issue.

I have not started that topic yet as i will discuss it later once i get rid of this issue, do you mean library version number ?

The purpose of first screenshot was to ensure you that i am using only BlynkEdgent.run and not anything other in the loop. I also have removed Arduino OTA functions.
Ok i will follow your instructions about the subsequent presentation of serial monitor messages here and i would avoid the screenshots and surely will use the triple backticks.

Hello Pete after updating the libraries i am still facing the same issue,

  • I am just unable to run my code when “blynk.run” (inside the Blynk.Edgent) seeks for the connection to blynk.cloud only for the first time when MCU is powered up or restarted, please help me pointing the location of the problem in blynk 1.0.1 library i am figuring it out since last four days continuously but still no luck.
    Just removing blynk.run from here solves the problem, but everybody knows it can’t be removed permanently as it is also responsible for connecting again.

void enterConnectCloud() 
 {BlynkState::set(MODE_CONNECTING_CLOUD);

  Blynk.config(configStore.cloudToken, configStore.cloudHost, configStore.cloudPort);
  Blynk.connect(0); 

  Serial.println("i am in connecting cloud mode");

  unsigned long timeoutMs = millis() + WIFI_CLOUD_CONNECT_TIMEOUT;
  
  while ((timeoutMs > millis()) && (!Blynk.isTokenInvalid()) && (Blynk.connected() == false))
         {delay(10);
          
          // Blynk.run();
          app_loop();
          
          if (!BlynkState::is(MODE_CONNECTING_CLOUD)) 
             {Blynk.disconnect();
              return;}}

So am I to assume that…

translates to “I had an issue with that, which I will document in a separate topic” as opposed to “Someone has raised an issue about that in another topic”?

I mean the BLYNK_FIRMWARE_VERSION in the .ono file…

#define BLYNK_FIRMWARE_VERSION "0.1.0"

If this isn’t incremented then the Blynk.Air update won’t be applied because Blynk.Air sees the firmware as either older or the same version as the existing firmware.

The way to do that is with copied and pasted code, rather than screenshots. As @Blynk_Coeur said:

BTW, you need triple backticks at the beginning and end of your code.

Have you also started a brand new sketch, using the 1.0.1 version of the EDGENT_ESP8266 example?

But that was with an old version of the library and the Edgent example.

I’d avoid messing-around with the .h files, other than Settings.h if I were you.

Pete.

2 Likes

Yes Pete, as i am not good at English but your translation is quite exact now :kissing_heart:

Ok, we will discuss it later when i would try the Blynk.Air again, thanks for pre-suggestion.

I got it, i will follow this in my next posts also

Yes off course all files are brand new now

alright it is very logical, its interesting you give very reasonable logic.

Me too wanted the same, but just for troubleshooting it was necessary Pete. to check where the problem is laying, and it is the exact location which i pointed, should we say it a bug now ?

Posting your serial output would be a good start.

Pete.

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

i am in connecting net mode
[21003] Using Dynamic IP: 192.168.1.101
i am in connecting cloud mode1





Its right there no further move but if i power my ESP when the “internet” is available then this is the output below …

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

i am in connecting net mode
[20109] Using Dynamic IP: 192.168.1.101
i am in connecting cloud mode1
[30609] Current time: Sun Oct 10 14:52:03 2021
[30610] Connecting to blynk.cloud:443
[33077] Ready (ping: 23ms).

Current time: 0:0:33	1 1 1970
[34077] Time sync: OK
[39573] Time sync: OK
Current time: 19:52:14	10 10 2021





there should run my part of code even at the time of "first power on, no internet case"

as every thing works fine in “during running_mode, internet come/go case”, i mean it does not block/hang at re-connect if it has connected for first time, issue is only for the first time power on, no internet case or restart when no internet case.

You’ve clearly made some changes to the Edgent example sketch to produce these messages…

If these are changes to the .h files then I’d suggest you create an upload a new sketch, based on the latest Edgent example, and post the output that this produces.

If these messages are produced elsewhere in your sketch then I’d suggest that you post this .ino file in full (redacting the credentials as you see fit).

Pete.

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.