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

Blynk went offline problem

I made a huge project, I worked about 3 months. Now all work but there is one very big problem. I used delays and now my programm works for about 2 hours and then Blynk went down and don’t go up. Only way is reset arduino. But I need this projects to work for months not for hours. Also I try to make delay of 10sec in 5 delays with 2sec and between delay Blynk.run but that didn’t help. Down I will paste code. I saw maybe solution is SimpleTimer but I really can’t understand that. If here is someone who would help me to change every delay with simpletimer. Or how to reset arduino to recconect or somethinh. Every help is good. Thank you!


/*
 * Program made by: Marin Francuz
 */

#define BLYNK_PRINT Serial

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

char auth[] = "6f473fd8288140579170b62271416c5a";      //Blynk token
char ssid[] = "IFrancuz23";    //WiFI Name
char pass[] = "francuz000112";       //WiFi Password   

///////////////////////////////////////////////////////////////////////////////////////////

int automanual = D5;
int agregatpaljenje = D7;
int agregatgasenje = D2;
int onoffstanje = D3;
int onoff;

WidgetLCD lcd(V3);
WidgetLED ledON(V5);
WidgetLED ledOFF(V6);

//////////////////////////////////////////////////////////////////////////////////////

float vout = 0.0;                                         //OCITANJE NAPONA S AKUMULATORA
float vin = 0.0;
float R1 = 100000.0; // resistance of R1 (100K)
float R2 = 10000.0; // resistance of R2 (10K)
int value = 0.0;
int a[5] = {};

//////////////////////////////////////////////////////////////////////////////////////

void setup()
{
  pinMode(automanual, INPUT);
  pinMode(onoff, INPUT);
  pinMode(agregatpaljenje, OUTPUT);
  pinMode(agregatgasenje, OUTPUT);
  digitalWrite(agregatpaljenje, LOW);
  digitalWrite(agregatgasenje, LOW);
  digitalWrite(automanual, LOW);
  Serial.begin(9600);
  //Blynk.begin(auth, ssid, pass);
  Blynk.begin(auth, ssid, pass, "blynk.croatianmakers.hr", 8080);
}

BLYNK_WRITE(V0) {
  onoff = param.asInt();   //button stanje agregata
  Serial.print("Button: ");
  Serial.println(onoff);
}

/////////////////////////////////////////////////////////////////////////////////

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

void rucno() {
  if (digitalRead(automanual) == 1) {    //rucno
     Serial.println("RUCNO");
     lcd.clear();
     Blynk.syncVirtual(V0);
     while (digitalRead(automanual) == 1) {
          Serial.println("U 2. stupnju RUCNE kontrole");
          stanjerucno();
          Blynk.syncVirtual(V0);
          if ((onoff) == 1) {
           paljenje();
             }
          if ((onoff) == 0) {
           gasenje();
             }
         }
    }
}

void automatski() {
  if (digitalRead(automanual) == 0) {    //automatski
    Serial.println("AUTOMATSKI");
    stanje(); 
      if ((vin) > 5) {
        stanje();
        gasenje();
        lcd.print(0, 1, "Agregat:  OFF     ");
        }
      if ((vin) <= 5) {
        paljenje();
        if (digitalRead(onoffstanje) == 1) {
          int k=1;
          int trajanje = 2700;
          lcd.print(0, 1, "                   ");
          while (k <= 2700) {
            stanje();
            delay(1000);
            Blynk.run();
            trajanje = trajanje-1;
            lcd.print (0, 1, "Preostalo: ");
            int trajanje1 = trajanje/60;
            int ispis = float(trajanje1);
            lcd.print (11, 1, ispis);
            lcd.print (13, 1, "min");
            rucno();
            if(digitalRead(onoffstanje) == 0) {
              k=2701;
            }
            if(digitalRead(onoffstanje) == 1) {
              //
            }
            k++;
          }
          gasenje();
          stanje();
        }
      }
  }
}

void paljenje () {
  digitalWrite(agregatgasenje, LOW);
  delay(100);
    if ((digitalRead(onoffstanje)) == 0) {
      digitalWrite(agregatpaljenje, HIGH);
      delay(2500);
      digitalWrite(agregatpaljenje, LOW);
      Blynk.run();
      delay(5000);
      Blynk.run();
      delay(5000);
      if ((digitalRead(onoffstanje)) == 1) {
        Blynk.notify ("Agregat upaljen!");
      }
      if ((digitalRead(onoffstanje)) == 0) {
        Blynk.notify("!!! UPOZORENJE !!! Agregat se nije upalio, ukoliko ne dode potvrdna informacija da je upaljen pogledajte sta se dogada!");
      }
    }
    if ((digitalRead(onoffstanje)) == 1) {
      digitalWrite(agregatpaljenje, LOW);
    }
}

void gasenje () {
     if ((digitalRead(onoffstanje)) == 0) {
      digitalWrite(agregatgasenje, LOW);
      digitalWrite(agregatpaljenje, LOW);    
      }
     if ((digitalRead(onoffstanje)) == 1) {
      digitalWrite(agregatgasenje, HIGH);
      digitalWrite(agregatpaljenje, LOW);    
      delay(1000);
      Blynk.run();
      delay(2500);
      Blynk.run();
      delay(2500);
      Blynk.run();
      delay(1000);
      digitalWrite(agregatgasenje, LOW);
      Blynk.run();
      delay(1000);
      Blynk.run();
      delay(2000);
        if ((digitalRead(onoffstanje)) == 0) {
          Blynk.notify("Agregat ugasen!");
        }
        if ((digitalRead(onoffstanje)) == 1) {
            Blynk.notify ("!!! UPOZORENJE !!! Agregat se nije ugasio, ukoliko ne dode potvrdna informacija da je ugasen pogledajte sta se dogada!");
    }
  }
}

void stanje() {

  value = analogRead(A0);                        
  vout = (value * 3.3) / 1024.0;                 
  vin = vout / (R2 / (R1 + R2));

  lcd.print (1, 0, "Napon : ");
  lcd.print (10, 0, vin);

  if ((digitalRead(onoffstanje)) == 0) {
     Blynk.virtualWrite(V0, 0);
     ledON.off();
     ledOFF.on();
  }
  if ((digitalRead(onoffstanje)) == 1) {
     Blynk.virtualWrite(V0, 1);
     ledON.on();
     ledOFF.off();
  }
  Blynk.syncVirtual(V0);
}

void stanjerucno () {

  value = analogRead(A0);                        
  vout = (value * 3.3) / 1024.0;                 
  vin = vout / (R2 / (R1 + R2));

  lcd.print (1, 0, "Napon : ");
  lcd.print (10, 0, vin);
  lcd.print (0, 1, "Agregat: ");


  if ((digitalRead(onoffstanje)) == 0) {
     ledON.off();
     ledOFF.on();
     lcd.print (10, 1, "OFF");
  }
  if ((digitalRead(onoffstanje)) == 1) {
     ledON.on();
     ledOFF.off();
     lcd.print (10, 1, "ON!");
  }
}


I may not understand your overview …
But it seems like working is complete. Stop …
Do you check for a missing void loop?