NodeMCU with Blynk goes offline and back online as frequent as 10 seconds

Hello everyone. Please I have a problem with my home automation system. I new to NodeMCU and Blynk. So far, I have followed up the instructions and created a project just to turn on and off four LEDs. I intend to expand this and use relay modules. In my Blynk app, I chose ESP8266 as my device, in my datastream, I created all four streams to be digital and not virtual pins (virtual didn’t work out) and as output pins. My project was successful and I savoured it for a day. Yesterday, for the love of it, I turned it on and tested it again. After 30 minutes, it kept going offline and online as shown on my desktop and phone app. I tried it today, it ran well for the first few minutes, yet now, it keeps repeating the offline and online issue. I have tried resetting it, uploading my code again and all that has been unfruitful. I have checked here an no one’s project is exactly similar to mine. Here is my code:

#define BLYNK_PRINT Serial

#define BLYNK_TEMPLATE_ID   "TMPLlnQxJk6j"
#define BLYNK_DEVICE_NAME   "Automation"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "I entered it";
char ssid[] = "DIEUDONNE-ANDROID";
char pass[] = "13111.PD";

void setup()
{

  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
}


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

Please edit your post and add triple backticks ( ``` ) before and after your sketch.

Thank you for the guidance. I am still trying to find my way around here.

You’re not using the right character, triple backticks look like this ( ``` )

Yay! thank you. Finally found them. First time using them.

Do you have anything that physically connected to the board like, sensors, modules, etc… ?

No I don’t for now. I intend to use switches for manual control but haven’t yet included them.

Are you supplying enough power to the board ?

Perhaps that is the issue. I am using my phone charger of 5 volts or just through my laptop’s USB port. Do you recommend I use a voltage higher than 5?

When you look at the data in your serial monitor, is the device rebooting when it goes offline in Blynk?

If you change this line:

to either 74880 or 115200 (it depends on your board, but usually 74880 will work) and set the serial monitor to the same baud rate, you will see boot messages from the board as well as the debug messages from Blynk.
If your board is rebooting then you’ll see a reason code, which will tell you why it’s rebooting.

I’ve never been a fan of digital datastreams, especially the way that they’ve been implemented in Blynk IoT. You’d be far better using virtual pins. More info here…

No! the NodeMCU needs 5v via the USB connector. It’s more about the current that the power supply can deliver, and whether or not the power is ripple-free. Also, you could have a problem with your USB cable, so try a different one.

Pete.

1 Like

Thank you very much for your kind reply PeterKnight.

In my serial monitor, what I see is, connecting to wifi, connected and then the cool Blynk symbol and a successful connection to Blynk plantform. Immediately after that, it starts reconnecting again after 10 seconds or less.

I used the 9600 baud rate. I will try a higher one as you have recommended.
With 115200, I get this:


wdt reset
load 0x4010f000, len 3460, room 16 
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4 
tail 4
chksum 0xc9
csum 0xc9
v000461b0
~ld
[66] Connecting to DIEUDONNE-ANDROID
[4289] Connected to WiFi
[4289] IP: 192.168.43.248
[4289] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.0.1 on ESP8266

[4296] Connecting to blynk.cloud:80
[4955] Ready (ping: 300ms).

 ets Jan  8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 3460, room 16 
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4 
tail 4
chksum 0xc9
csum 0xc9
v000461b0
~ld
[66] Connecting to DIEUDONNE-ANDROID

I used a 5.1 V, 2.1A capable charger, yet I got the same results. I will try using a different cable like you have suggested.

Concerning the digital pins I used, I only used them because I couldn’t have a any output using the Virtual pins. Perhaps it is because I thought D0 to be V0, D1, V1 and so on respectively. Perhaps I was wrong. I would love to have guidance on the Virtual pins and their corresponding pins on the NodeMCU please.

Your “Cause 4” reset is a watchdog timer issue, which is making the device reboot. Not sure why, but maybe something to do with the digital pins.
You could try deleting those datastreams and seeing if you have the same issue.

If you read the link to the virtual pin tutorial that I provided, you’ll realise that there is absolutely no link between virtual pins in Blynk and physical pins on the device.
You need to create that link yourself using pinMode statements, virtialWrite commands and virtual pin handler callback functions.
Sounds complex, but read the tutorial and you’ll see that it’s not really.

BTW, when you post serial output it’s far better to copy/paste it, and use triple backticks to format it correctly, rather than posting screenshots, as it’s impossible to quote pieces of text from a screenshot.

Pete.

Thank you very much. I will try all that you have recommended.
Forgive me for the screenshot. I am using my phone. I will correct that right away.

Greetings sir. I tried all that you recommended. It turns out the digital pins were the main problem after all. After I deleted the datastreams that I created using digital pins, my device became constantly online. I read through your explanation of virtual pins and used the knowledge to build my code. I wish to control four LEDs, using switches as well as the Blynk planform. After writing my code, I am told “Error compiling for board NodeMCU 1.0 (ESP-12E Module).”. Here is my code and I don’t know what I may have done wrong.

#define BLYNK_PRINT Serial

// device name info from app
#define BLYNK_TEMPLATE_ID "TMPLlnQxJk6j"
#define BLYNK_DEVICE_NAME "Automation"
"

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "Was entered";

char ssid[] = "DIEUDONNE-ANDROID";
char pass[] = "13111.PD";

//--------------------------------------------------------------------------------------------------------------------//

int switch1=12;
int led1=5;
int s1;

int switch2=13;
int led2=4;
int s2;

int switch3=15;
int led3=14;
int s3;

String s1_on="Switch 1 is ON";
String s2_on="Switch 2 is ON";
String s3_on="Switch 3 is ON";

String s1_off="Switch 1 is OFF";
String s2_off="Switch 2 is OFF";
String s3_off="Switch 3 is OFF";



void setup() 
{
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);
  
  pinMode(switch1,INPUT);
  pinMode(led1,OUTPUT);

  pinMode(switch2,INPUT);
  pinMode(led2,OUTPUT);
  
  pinMode(switch3,INPUT);
  pinMode(led3,OUTPUT);
  
}

BLYNK_CONNECTED()
    {
      Blynk.syncVirtual(V1); 
    }

BLYNK_CONNECTED()
    {
      Blynk.syncVirtual(V2); 
    }

BLYNK_CONNECTED()
    {
      Blynk.syncVirtual(V3); 
    }

BLYNK_WRITE(V1)
        {
          if(param.asInt() == 1)
              { 
                digitalWrite(led1,HIGH);  
              }
          else
              {
                digitalWrite(led1,LOW);      
              }
        }
BLYNK_WRITE(V2)
        {
          if(param.asInt() == 1)
              { 
                digitalWrite(led2,HIGH);  
              }
          else
              {
                digitalWrite(led2,LOW);      
              }
        }
BLYNK_WRITE(V3)
        {
          if(param.asInt() == 1)
              { 
                digitalWrite(led3,HIGH);  
              }
          else
              {
                digitalWrite(led3,LOW);      
              }
        }

void loop() 
{
  Blynk.run();
  
  s1=digitalRead(switch1);
  s2=digitalRead(switch2);
  s3=digitalRead(switch3);
  
  if (s1==HIGH)
      {
        digitalWrite(led1,HIGH);
        Serial.println(s1_on);
        Blynk.virtualWrite(V1,1);
      }
   else
      { 
        digitalWrite(led1,LOW);
        Serial.println(s1_off);
        Blynk.virtualWrite(V1,0);
      }
  if (s2==HIGH)
      {
        digitalWrite(led2,HIGH);
        Serial.println(s2_on);
        Blynk.virtualWrite(V2,1);
      }
   else
      { 
        digitalWrite(led2,LOW);
        Serial.println(s2_off);
        Blynk.virtualWrite(V2,0);
      }
   if (s3==HIGH)
      {
        digitalWrite(led3,HIGH);
        Serial.println(s3_on);
        Blynk.virtualWrite(V3,1);
      }
   else
      { 
        digitalWrite(led3,LOW);
        Serial.println(s3_off);
        Blynk.virtualWrite(V3,0);
      }
}

First of all you should clean your void loop.

Should I create a function out of the void loop to execute all that I have put in there? Or should it be in the void setup?

If you would like to execute the code once only put it in the setup, if you would like to execute it continually put it in a void function and call it using a timer.

Alright. Thank you. Please what is the syntax for putting it in a void function and being able to call it using a timer?
And will I I be calling it in the void loop? Because that’s what I have in mind.

Read this article

Thank you… Going through it now.