blynkkk / blynk-library

Blynk library for IoT boards. Works with Arduino, ESP32, ESP8266, Raspberry Pi, Particle, ARM Mbed, etc.
https://blynk.io
MIT License
3.81k stars 1.38k forks source link

Heartbeat Timeout and Login issues while using Static IP #446

Closed coderxx closed 3 years ago

coderxx commented 5 years ago

Blynk library version: [0.5.4] IDE: [Arduino] IDE version: [1.8.8] Board type: [NodeMCU Amica ESP8266 with CP2102] Additional modules: [null]

Scenario, steps to reproduce

[What you are trying to achieve and you can't?] Setup my NodeMCU with a Static IP to my router and use the App.

#define BLYNK_PRINT Serial
#define BLYNK_DEBUG        // Optional, this enables more detailed prints

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

// Your WiFi credentials.
// Set password to "" for open networks.
char auth[] = "myauthcode";
char ssid[] = "myhomessid";
char pass[] = "mynetworkpassword";

// Mac address should be different for each device in your LAN. Not required.
//byte arduino_mac[] = { HEX, HEX, HEX, HEX, HEX, HEX };
IPAddress device_ip  (192, 168,   1,  5);
IPAddress dns_ip     (  8,   8,   8,   8);
IPAddress gateway_ip (192, 168,   1,   1);
IPAddress subnet_mask(255, 255, 255,   0);

void setup()
{
  // Debug console
  Serial.begin(9600);

  //Disconnect any previous connections.
  WiFi.disconnect();

  //Print status debug info before any modifications for comparison
  WiFi.printDiag(Serial);

  // Setup WiFi network by setting WiFi mode to just a Client
  WiFi.mode(WIFI_STA);

  //Send credentials first
  WiFi.begin(ssid, pass);
  delay(1000);

  //Set config in the form of static ip, gateway, subnet and dns. Doesn't work without dns being explicitly set.
  WiFi.config(device_ip, gateway_ip, subnet_mask, dns_ip);
  delay(500);

  //Print diagnosis after modifications
  WiFi.printDiag(Serial);

  //Check registered static IP
  Serial.println(WiFi.localIP());

  //Check the SSID set on the firmware
  Serial.println(WiFi.SSID());

  //Check the Wifi status
  Serial.println(WiFi.status());

  // Setup Blynk
  Blynk.config(auth);
  while (Blynk.connect() == false) {
    Serial.print(“Still trying to connect…”)
  }

}

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

Expected Result

[What are you expecting to happen as the consequence of above reproduction steps?] I control my LEDs on my NodeMCU with 3 buttons and it works fine.

Actual Result

[What actually happens after the reproduction steps? Include the error output or a link to a gist if possible.]

As you can see it works initially for a few seconds and then the ping starts to go higher and times out.

18:01:13.026 ->     ___  __          __
18:01:13.026 ->    / _ )/ /_ _____  / /__
18:01:13.060 ->   / _  / / // / _ \/  '_/
18:01:13.095 ->  /____/_/\_, /_//_/_/\_\
18:01:13.128 ->         /___/ v0.5.4 on NodeMCU
18:01:13.161 -> 
18:01:13.161 -> [23985] Connecting to blynk-cloud.com:80
18:01:18.036 -> [28986] Connecting to blynk-cloud.com:80
18:01:18.110 -> [29078] Ready (ping: 44ms).
18:02:30.414 -> [101382] Heartbeat timeout
18:02:32.416 -> [103385] Connecting to blynk-cloud.com:80
18:02:35.475 -> [106434] Login timeout
18:02:37.475 -> [108434] Connecting to blynk-cloud.com:80
18:02:40.536 -> [111482] Login timeout
18:02:42.530 -> [113482] Connecting to blynk-cloud.com:80
18:02:45.574 -> [116529] Login timeout
18:02:47.561 -> [118529] Connecting to blynk-cloud.com:80
18:02:48.662 -> [119609] Ready (ping: 1035ms).
18:03:08.034 -> [138996] Heartbeat timeout
18:03:12.715 -> [143682] Connecting to blynk-cloud.com:80
18:03:15.069 -> [146037] Ready (ping: 2284ms).

Update: When I uncomment #include <BlynkSimpleEsp8266.h> it seems to work well with only a 54ms ping. This I could repeat up to 7-8 times and was able to reproduce exact behaviour.

cziter15 commented 5 years ago

Same here. I've checked everything, from power supply to every sketch line as they suggest on forums. It doesn't even matter if I turn off power management.

pieman64 commented 5 years ago

@coderxx why are you trying to run without #include <BlynkSimpleEsp8266.h> and are you saying with it included the sketch works fine?

Permpol commented 4 years ago

I use esp32. I has same problem.