Blynk 2.0 reconnection issue

Blynk 2.0 is not reconnecting back to Wi-Fi, I have to manually reset the board in case of Wi-Fi failure.

Using this simple sketch


// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLDEPBI4tz"
#define BLYNK_DEVICE_NAME "test wifi"

#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
//#define USE_WEMOS_D1_MINI

#define LedPin1 D5
bool toggleState_1 = LOW;

#include "BlynkEdgent.h"

BLYNK_WRITE(V0) {
  toggleState_1 = param.asInt();
  digitalWrite(LedPin1, toggleState_1);
}

void setup()
{
  Serial.begin(115200);
  delay(100);
  
  pinMode(LedPin1, OUTPUT);
  
  BlynkEdgent.begin();
}

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

Serial Monitor

[387] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.1.0 on ESP8266

 #StandWithUkraine    https://bit.ly/swua


[393] --------------------------
[396] Product:  test wifi
[398] Firmware: 0.1.0 (build Aug 25 2022 17:41:37)
[403] Token:    vOfd - •••• - •••• - ••••
[408] Device:   ESP8266 @ 80MHz
[411] MAC:      E8:9F:6D:88:4A:EA
[414] Flash:    4096K
[416] ESP core: 3.0.2
[418] ESP SDK:  2.2.2-dev(38a443e)
[421] Boot Ver: 6
[423] Boot Mode:1
[425] FW info:  468896/1626112, MD5:13eb3148dd56dfee89e2916c068a3d7b
[632] Free mem: 31016
[632] --------------------------

>[632] INIT => CONNECTING_NET
[634] Connecting to WiFi: HOME
[4753] Using Dynamic IP: 192.168.29.130
[4753] CONNECTING_NET => CONNECTING_CLOUD
[4865] Current time: Thu Aug 25 12:12:33 2022
[4865] Connecting to blynk.cloud:443
[6011] Ready (ping: 11ms).
[6164] CONNECTING_CLOUD => RUNNING
[67211] RUNNING => CONNECTING_NET
[67211] Connecting to WiFi: HOME
[117216] Connecting to WiFi: HOME
[167227] Connecting to WiFi: HOME
[217234] Connecting to WiFi: HOME
[267240] Connecting to WiFi: HOME

Kindly help.

Have you tried rebooting your router and any additional wireless access points?

Pete.

When the esp device is connected i had rebooted my router, afterwards the esp device won’t reconnect back to blynk unless I reset the esp device manually.

The legacy version used to get connected automatically to blynk.

The Legacy version wasn’t running this sketch though was it?
Have you tried your Legacy sketch with the addition of the Blynk Template ID, Device name and Blynk IoT Auth token?

Pete.

I am not talking about this sketch, I am talking about any blynk sketch in general.
No, I haven’t tried this in legacy sketch.

I want to to make the sketch with blynk.edgent and that is what I am doing, but there seems to be a reconnection problem.

The problem is that your device isn’t connecting to your WiFi.
Why this is is difficult to say, based on the info you’ve provided so far.

It could be your router, or WAP, that’s rejecting the connection request. It could be a signal strength issue, it could be an issue with your device or it’s power supply.

Edgent stores the WiFi credential in EEPROM, and rebooting the device causes these to be re-read. It could be that the data that has been read is being corrupted or amended after use, but there so evidence of this is happening with the code you’ve posted.

Eliminating Edgent would narrow-down the possibilities.
Turning-on debugging in the IDE may also shed some light on what’s happening.

Pete.

is there any way that the sketch can be used without wifi provisioning, just like the old fashioned hard coded credentials way.

Are you talking about the Edgent sketch, or your Legacy sketch?

Pete.

using legacy sketches with blynk iot app and blynk dashboard web interface.

Yes. I suggested this in post #4 but you dismissed the suggestion.

How to do this is explained in the documentation…

https://docs.blynk.io/en/getting-started/activating-devices/manual-device-activation

Pete.

#include <BlynkSimpleEsp8266.h>
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "xxxx"
#define BLYNK_DEVICE_NAME "xxxx"

char auth[] = "xxxx";

#define LedPin1 D5
bool toggleState_1 = LOW;

BLYNK_WRITE(V1) {
  toggleState_1 = param.asInt();
  digitalWrite(LedPin1, toggleState_1);
}

void setup()
{
  Serial.begin(115200);
  delay(100);
  
  pinMode(LedPin1, OUTPUT);
  
  Blynk.begin(auth, "HOME",  "xxxx");
}

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

this is the sketch i am using but nothing is happening in the serial monitor. do i need to use the rest files like edgent, settings as well for this one, currently i am only using the main ino file

(note : xxxx is only used here, in the actual code everything is properly filled.)

Do you mean that you are seeing no serial output at all?
If so then check your port, baud rate and connections.

For the 1.x.x version of the Blynk library to compile the sketch so that it will connect to the IoT cloud server rather than the Legacy cloud server then these two lines of code need to be at the very top of your sketch…

It also make sense (to me at least) to copy all three lines of firmware configuration code from the Device screen and paste them at the top of your sketch. This then gives you the Auth token with the variable name BLYNK_AUTH_TOKEN which you can then use directly in your Blynk.begin() command rather than the variable name of Auth.

Pete.

if i use blynk.begin() where should i be entering the credentials, for now i have used this sketch and still nothing happens, the serial monitor is showing some gibberish texts upon reset and nothing else.

#define BLYNK_TEMPLATE_ID "xxxx"
#define BLYNK_DEVICE_NAME "xxxx"
#define BLYNK_AUTH_TOKEN "xxxx"

#include <BlynkSimpleEsp8266.h>
#define BLYNK_PRINT Serial

#define LedPin1 D5
bool toggleState_1 = LOW;

BLYNK_WRITE(V1) {
  toggleState_1 = param.asInt();
  digitalWrite(LedPin1, toggleState_1);
}

void setup()
{
  Serial.begin(115200);
  delay(100);
  
  pinMode(LedPin1, OUTPUT);
  
  Blynk.begin(BLYNK_AUTH_TOKEN, "HOME", "xxxx");
}

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

i have also tried pre provisioning in the edgent sketch which works fine but still it doesn’t connect after router restart without resetting the board

#define BLYNK_TEMPLATE_ID "xxxx"
#define BLYNK_DEVICE_NAME "xxxx"
#define BLYNK_AUTH_TOKEN "xxxx"

#define BLYNK_WIFI_SSID "xxxx"
#define BLYNK_WIFI_PASS "xxxx"

used these lines on top of my sketch with BlynkEdgent.begin() in setup and BlynkEdgent.run() in loop

update : it seems the problem is with my router only as connecting the device with mobile hotspot is working file, the device id reconnecting automatically after hotspot restart.

thank you for the assistance since there is nothing more that can be done.