Hi everyone,
This is my first post and I’m pretty new to blynk/nodemcu field.
I use nodemcu (ESP8266) with blynk code to control relays.
Nodemcu connects to a WiFi / router which is not subject to change, so I have to find a solution within the nodemcu itself.
Nodemcu connects to wifi network easily, but disconnects in matter of minutes (1-3), reconnects again, and keeps doing this constantly. Whenever I open the android app I see it changing online/offline status every minute or two. After a longer period of time (sometimes 10 days, sometimes 2 months) nodemcu goes offline and never comes back. Than it has to be restarted manually.
I assume the router might be the problem, but I cannot change neither the router nor its config.
What I would like is the nodemcu restarts itself once it does not connect to blynk server for longer than 10 minutes or so.
I did try to experiment with codes I found within this community, but had no luck so far
I am not a programmer and would appreciate very much if someone could help me with this.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "xxxxxxxxxx";
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxx";
void setup()
{
// Debug console
Serial.begin(9600);
WiFi.setSleepMode(WIFI_NONE_SLEEP);
WiFi.setAutoReconnect(true);
WiFi.persistent(true);
pinMode(16, OUTPUT); //D5 is GPIO 16
pinMode(5, OUTPUT); //D7 is GPIO 5
pinMode(4, OUTPUT); //D7 is GPIO 4
pinMode(0, OUTPUT); //D7 is GPIO 0
pinMode(14, OUTPUT); //D5 is GPIO 14
pinMode(12, OUTPUT); //D7 is GPIO 12
pinMode(13, OUTPUT); //D7 is GPIO 13
pinMode(2, OUTPUT); //D7 is GPIO 2
digitalWrite(16, HIGH); //Set GPIO 16 LOW
digitalWrite(5, HIGH); // Set GPIO 5 LOW
digitalWrite(4, HIGH); // Set GPIO 4 LOW
digitalWrite(0, HIGH); // Set GPIO 0 LOW
digitalWrite(14, HIGH); //Set GPIO 14 LOW
digitalWrite(12, HIGH); // Set GPIO 12 LOW
digitalWrite(13, HIGH); // Set GPIO 13 LOW
digitalWrite(2, HIGH); // Set GPIO 2 LOW
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
}