Very simple program and while testing the WiFi reconnect process the ESP reconnects to WiFi and Blynk every time except when power cycle occurs before WiFi is back up. If I disable and then enable Wifi on my router the ESP will reconnect. If I reboot my router the ESP reconnects.
It’s only when the ESP power is turned off and back on while WiFI is out that it never reconnects to blynk. As you can see from the serial print below the ESP reconnects to my WiFi but not to Blynk. I just get an endless series of “Connecting to blynk-cloud”. While this is going on I can “telnet” to blynk-cloud.com 80.
Any ideas?
[5040] Connecting to Murphylan2
[49547] Connected to WiFi
[49547] IP: 192.168.0.81
[49547]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.5.4 on ESP-12
[49554] Connecting to blynk-cloud.com:80
[54555] Connecting to blynk-cloud.com:80
The program:
#define BLYNK_HEARTBEAT 15
#define BLYNK_DEBUG
#define BLYNK_PRINT Serial
//debug options
bool debug = true;
bool blynkdebug = false;
const char* PgmId = "TestBlynkReconnect";
//const char* PgmNotes = "V=1 current Blynk Lib ";
const char* PgmNotes = "V=6.2 HeatControlMaster runs on ESP8266 this Master plus 2 temp sensors (outside temperture)";
//WiFi
char ssid[] = "Murphylan2";
char password[] = "shantihbaba";
char authtoken[] = "79b122f93b244987b60d8c1e0942ed05";
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
IPAddress staticIPAddr(192, 168, 0, 81);// IP address of this server
IPAddress gateway(192, 168, 0, 1);// gateway of your network
IPAddress subnet(255, 255, 255, 0);
void setup()
{
Serial.begin(115200);
delay(5000);
Serial.print("Program ");
Serial.println(PgmId);
bool isfirst = false;
WiFi.config(staticIPAddr, gateway, subnet);// forces use of a fixed IP Address);
Blynk.begin(authtoken, ssid, password);//starts wifi and Blynk
if (Blynk.connected()) {
if (debug) Serial.println("WiFi connected");
byte mac[6];
if (debug) Serial.println("IP address: ");
if (debug) Serial.println(WiFi.localIP());
if (debug) Serial.println("Mac Address: ");
WiFi.macAddress(mac);
if (debug) Serial.print(mac[0], HEX);
if (debug) Serial.print(":");
if (debug) Serial.print(mac[1], HEX);
if (debug) Serial.print(":");
if (debug) Serial.print(mac[2], HEX);
if (debug) Serial.print(":");
if (debug) Serial.print(mac[3], HEX);
if (debug) Serial.print(":");
if (debug) Serial.print(mac[4], HEX);
if (debug) Serial.print(":");
if (debug) Serial.println(mac[5], HEX);
}
}
void loop()
{
Blynk.run();
}