BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Offline problem after several hours

Hello everyone;
I have some issues about my new project. Im controlling four relays and using dht22 for humidity and temperature. Everything is good but after about 10 hours power on nodemcu, device goes offline and it doesn’t be online until I reset. Also device goes often offline and online in that 10 hours.

Details :
• Nodemcu Lolin V3
• I use Blynk server
• Blynk Library version is 0.6.1


#include <ESP8266WiFi.h>
#include <Wire.h>
#include <WiFiManager.h>
#include <DHT.h>
#include <EEPROM.h>
#include "RTClib.h"
RTC_DS1307 RTC;
#define BLYNK_PRINT Serial 
#include <SPI.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
BlynkTimer timer;
char auth[] = "auth is here";
#define DHTTYPE DHT11
uint8_t DHTPin = 0;
DHT dht(DHTPin, DHTTYPE);                

float temp;
float nem;
int istenen;

int relay1 = 15; //d8
int relay2 = 16; //0
int relay3 = 13; // d7
int relay4 = 12; //6

boolean relay1buton;
boolean relay2buton;
boolean relay3buton;
boolean relay4buton;

boolean rolekonum;
boolean oto;
int nemistenen;
int res;
int onboardled = 2;


void setup() {
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);

pinMode(onboardled, OUTPUT);

EEPROM.begin(512);
Serial.begin(115200);
delay(10);
WidgetLED led1(V1);

WiFiManager wifiManager;
wifiManager.setConnectTimeout(180);
wifiManager.autoConnect("Havalandırma");

  

pinMode(DHTPin, INPUT);



Wire.begin();
 RTC.begin();
  if (! RTC.isrunning()){
   // RTC.adjust(DateTime(2020, 01, 4, 17 ,07 ,00));
  }

Blynk.begin(auth, WiFi.SSID().c_str(), WiFi.psk().c_str());

while (WiFi.status() != WL_CONNECTED) {
delay(100);
}

nemistenen = 100;
oto = 0;
dht.begin();
led1.off();
digitalWrite(onboardled, LOW);

Blynk.virtualWrite(V21, 0);
Blynk.virtualWrite(V22, 0);
Blynk.virtualWrite(V23, 0);
Blynk.virtualWrite(V24, 0);
Blynk.virtualWrite(V15, 0);
Blynk.virtualWrite(V13, 100); 

timer.setInterval(5000L, sendUptime);
}

BLYNK_WRITE(V13)
{
  nemistenen = param.asInt(); // uygulamadan istenen nemin çekilmesi
}

BLYNK_WRITE(V15)
{
  oto = param.asInt(); // uygulamadan auto-manual geçişi yapılması
}
BLYNK_WRITE(V21)
{
  relay1buton = param.asInt(); // uygulamadan aç kapa yapılması
}

BLYNK_WRITE(V22)
{
  relay2buton = param.asInt(); // uygulamadan auto-manual geçişi yapılması
}
BLYNK_WRITE(V23)
{
  relay3buton = param.asInt(); // uygulamadan auto-manual geçişi yapılması
}
BLYNK_WRITE(V24)
{
  relay4buton = param.asInt(); // uygulamadan auto-manual geçişi yapılması
}

//_____________________________________________________________________________________

void sendUptime(){
temp = dht.readTemperature();
nem = dht.readHumidity();
Blynk.virtualWrite(V12, nem);  //V6 is for Temperature
Blynk.virtualWrite(V16, temp);
 
}

void loop() {
Blynk.run();
timer.run();
Serial.println(nemistenen);
if(Blynk.connected()){
    loop1();
}


if(!Blynk.connected()){
  loop2();
}

}
void loop1(){
Blynk.run();
WidgetLED led1(V1);
WidgetLED led2(V2);
WidgetLED led3(V3);
WidgetLED led4(V4);


if(relay2buton == 1){
  digitalWrite(relay2, HIGH); //relay2 = 2.röle relay3 = 4.röle relay4 = 1.röle 
  led2.on();
}
if(relay2buton == 0){
  digitalWrite(relay2, LOW);
  led2.off();
}


if(relay3buton == 1){
  digitalWrite(relay3, HIGH);
  led3.on();
}
if(relay3buton == 0){
  digitalWrite(relay3, LOW);
  led3.off();
}


if(relay4buton == 1){
  digitalWrite(relay4, HIGH);
  led4.on();
}
if(relay4buton == 0){
  digitalWrite(relay4, LOW);
  led4.off();
}




if(oto == 1){
if(nemistenen > nem){
  digitalWrite(relay1, LOW);
  led1.off();
}
if(nemistenen < nem) {
digitalWrite(relay1, HIGH);
led1.on();
 }
}

if(oto == 0){
if(relay1buton == 1){
    digitalWrite(relay1, HIGH);
    led1.on();
  }
  if(relay1buton == 0){
    digitalWrite(relay1, LOW);
    led1.off();
    }
  }
}

//_____________________________________________________________________________________
void loop2(){  
Blynk.run();
WidgetLED led1(V1);
WidgetLED led2(V2);
WidgetLED led3(V3);
WidgetLED led4(V4);
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);
relay2buton = 0;
relay3buton = 0;
relay4buton = 0;
nemistenen  = 100;
led1.off();
led2.off();
led3.off();
led4.off();
}

I think that your void loop, and the sub-loops that are called from it, are the issue.
You should read this:

Pete.

Thank you so much for reply sir. I think thats the point, I will fix it.