Delay happening while communicating between ESP8266 and Blynk

Hi, I am using ESP8266 NodeMCU for a project. For practice I made a simple circuit. Just connected D1 and D2 pins of NodeMCU with orange and red LEDs respectively, and I can control them with Blink web dashboard and mobile app as well. The only problem is that when I change the virtual pins value from web or mobile app, the actual LED’s state changes after some time. Sometimes, the LED turns ON/OFF immediately, sometimes it takes some time, and sometimes it takes a lot of time. Following is the code:

#include <BlynkSimpleEsp8266.h>

/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME ""
#define BLYNK_AUTH_TOKEN ""

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#define ORANGE_LED D1
#define RED_LED D2

// WiFi parameters to be configured
const char ssid[] = "";
const char pass[] = "";

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

  pinMode(ORANGE_LED, OUTPUT);
  pinMode(RED_LED, OUTPUT);

  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}

// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V0)
{
  Serial.println("V0 changed");
  if(param.asInt() == 1)
  {
    digitalWrite(ORANGE_LED, HIGH);
  }
  else
  {
    digitalWrite(ORANGE_LED, LOW);
  }
}

// This function is called every time the Virtual Pin 1 state changes
BLYNK_WRITE(V1)
{
  if(param.asInt() == 1)
  {
    digitalWrite(RED_LED, HIGH);
  }
  else
  {
    digitalWrite(RED_LED, LOW);
  }
}

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

Following are my settings in Arduino tools menu:

I don’t understand whether the problem is with my hardware, settings or code.

The code you’ve posted is missing this line…

#include <ESP8266WiFi.h>

I assume that a copy/paste issue, otherwise I don’t think it would work.

Most likely it’s an issue with the latency of your internet connection, but checking the ping time that appears in your serial monitor when you boot the device and connect to Blynk will give you a better idea.
Have you tried rebooting your router?

Also, what version of the ESP8266 core do you have installed via Tools > Board > Boards Manager?

Pete.

Hey Pete, thanks for replying. I have tried including and excluding the line:

#include <ESP8266WiFi.h>

It works exactly the same.

Also, this is my serial monitor output,
g

I am using my mobile data connection instead of internet router. My pc and mobile are also connected to the same network. When I change the virtual pin state in my cell phone, it appears on my pc instantly but the actual LED’s state changes after some time.

And I am using ESP8266 3.1.2 version installed via Boards manager.

When you post serial monitor output it’s far better to copy the text from your serial monitor and paste it into your forum post using triple backticks, the same way as you do with code.

Your 100ms ping time is quite long, and that’s probably caused by you using your phone as a mobile hotspot. There’s not much you can do unless you move to a proper internet connection.

Pete.

Ok thanks, I will take care next time.

What should be a good ping time?

I get a ping time of less than 10ms, but I’m in London and connecting to the London server, and using a reasonably fast broadband internet connection.

If you reboot your device 10 times over the period of a few minutes what sort of average ping do you see?

Pete.

Actually my WiFi router doesn’t connect with my esp8266 module. What could be the reason?

ESP devices are 2.4GHz only. Is your router set-up to be 5GHz only, or using the same SSID for 2.4 and 5GHz ?

Pete.

My router is setup at 2.4 GHz (B+G+N). Is it correct?

Yes, 802.11n+g+b is the correct mode.

Pete.

Then what else could be the reason?

Lots of things, but I’m not going to play “20 questions” when you haven’t bothered to share any details of code, serial monitor output, router setup etc.

Pete

Nevermind, the issue was with my wifi router ssid. There was a space character in the end, so I had to remove it. Now my esp8266 can connect with my wifi router and there is no delay in the communication. Thanks!

I need help with mine
image

I can’t connect to my phone, and its not working

Your screenshot shows that it’s connected.

I’d suggest that if you’re having problems then you start a new “Need help with my project” topic and provide all of the information that is listed here…

Also, when you’re posting terminal output, code or compiler error messages please don’t post screenshots, copy and paste the text and use triple backticks at the beginning and end.

Pete.