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

[ESP8266/D1Mini] HeartBeat Timeout

Hey together,

after finishing my project, i´ve tested the code and my ESP for one day.

After 1-2 minutes, the console send me the error “HeartBeat Timeout”…
Then it tries to reconnect constantly, but doesn´t work…
Can someone give me some tips or tell me what it is?

Thank u!

    14:28:35.019 -> ⸮⸮$⸮p⸮l⸮sd⸮⸮'⸮⸮cl`;⸮oadph⸮⸮[67] Connecting to SSID
14:28:39.400 -> [4405] Connected to WiFi
14:28:39.400 -> [4406] IP: 192.168.0.62
14:28:39.400 -> [4406] 
14:28:39.400 ->     ___  __          __
14:28:39.400 ->    / _ )/ /_ _____  / /__
14:28:39.400 ->   / _  / / // / _ \/  '_/
14:28:39.400 ->  /____/_/\_, /_//_/_/\_\
14:28:39.434 ->         /___/ v0.6.1 on ESP8266
14:28:39.434 -> 
14:28:39.434 -> [4412] Connecting to blynk-cloud.com:80
14:28:39.468 -> [4479] Ready (ping: 21ms).
14:28:41.440 -> Auto-Mode
14:31:59.576 -> Feuchte: 
14:31:59.576 -> 0%Autobetrieb startet
14:31:59.746 -> 1
14:31:59.746 -> Pumpe an
14:32:38.783 -> [243777] Heartbeat timeout
14:32:43.778 -> [248761] Connecting to blynk-cloud.com:80
14:32:48.769 -> [253762] Connecting to blynk-cloud.com:80
14:32:53.794 -> [258763] Connecting to blynk-cloud.com:80
14:32:58.785 -> [263764] Connecting to blynk-cloud.com:80

#define BLYNK_PRINT Serial    
#include <ESP8266WiFi.h>
#include <Blynk.h>
#include <BlynkSimpleEsp8266.h>
#define DRY_SOIL      50
BlynkTimer timer;
WidgetLED LED(V5);
char auth[] = "TOKEN";
char ssid[] = "SSID";
char pass[] = "PASS";
int feuchte;
int timerNr2;
int timerNr3;
//int timerNr4;
int manBTN;

//------------------------------------------------SETUP
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);    
  Blynk.begin( auth, ssid , pass );
  pinMode(5, OUTPUT);
  pinMode(A0, INPUT);
  timerNr2 = timer.setInterval(200000, startFeuchte);
  timer.disable(timerNr2);
  timerNr3 = timer.setInterval(200000, startAuto);
  timer.disable(timerNr3);
  //timerNr4 = timer.setTimer(6000, startPumpe, 1);
  //timer.disable(timerNr4);
}


//------------------------------------------------LOOP
void loop() {
  // put your main code here, to run repeatedly:
  Blynk.run();
  timer.run();
}


//------------------------------------------------Funktionen
void startFeuchte(){
  feuchteSenden();
}
//----------------------------------------------
void startAuto(){
  automatik();
}
//----------------------------------------------
/*
void startPumpe(){
  pumpenStart();
}
//----------------------------------------------
*/
BLYNK_WRITE(V10){
switch (param.asInt())
  { 
    case 1: { // Item 1
      Serial.println("Auto-Mode");
      timer.enable(timerNr2);
      timer.enable(timerNr3);
      break;
    }
    
    case 2: { // Item 2
      Serial.println("Manuell-Mode");
      digitalWrite(5, LOW);
      timer.enable(timerNr2);
      timer.disable(timerNr3);
      break;
    }    
  }
}
//----------------------------------------------
BLYNK_WRITE(V0){
  manBTN=param.asInt();
  if(manBTN==1){
    //pumpenStart();
    digitalWrite(5, HIGH);
    //LED.on();
  }
  else{
    digitalWrite(5, LOW);
    //LED.off();
  }
}
//----------------------------------------------
void feuchteMessen(void)
{
  int i = 0;
  feuchte = 0;
  for (i = 0; i < 10; i++)  //
  {
    feuchte += analogRead(A0); 
    delay(20);   
  }
  feuchte = feuchte / (i);
  feuchte = map(feuchte, 640, 220, 0, 100); 
}
//----------------------------------------------
void feuchteSenden(){
  Serial.println("Feuchte: ");
  Serial.print(feuchte);
  Serial.print("%");
  Blynk.virtualWrite(V4, feuchte);
}
//----------------------------------------------
void automatik(){
      Serial.println("Autobetrieb startet");
      feuchteMessen();
      Serial.println(feuchte);
      if(feuchte<50){
        digitalWrite(5, HIGH);
        Serial.println("Pumpe an");
        LED.on();
      }
      else{
        digitalWrite(5, LOW);
        Serial.println("Pumpe aus");
        LED.off();
      }
}
//---------------------------------------------- 
void pumpenStart(){
  digitalWrite(5, HIGH);
  //timer.enable(timerNr4);
}

There is something quite strange happening in your code which i cannot understand why you have done it

timerNr2 = timer.setInterval(200000, startFeuchte);
timer.disable(timerNr2);
//Thats OK//

void startFeuchte()
{
  feuchteSenden(); //??????
}

void feuchteSenden(){
  Serial.println("Feuchte: ");
  Serial.print(feuchte);
  Serial.print("%");
  Blynk.virtualWrite(V4, feuchte);
}

Why have put put a function within a function??
You could just do

timerNr2 = timer.setInterval(200000, feuchteSenden);
timer.disable(timerNr2);

void feuchteSenden(){
  Serial.println("Feuchte: ");
  Serial.print(feuchte);
  Serial.print("%");
  Blynk.virtualWrite(V4, feuchte);
}
//And delete void startFeuchte() altogether.

Hey

Yeah I know. But if I don’t do this, it don’t accept my code.
If I put the function in a function it works.
Idk why :man_shrugging:

What widget is V10?

V10 is Menu switch with Automatic and Manual option

What does that mean exactly?

Pete.

Weird.
When I first programmed it that way, IDE did not want to accept it.
Now I made it like that again, now it works.

But still the same problem…

And, there is a problem with this code…

  for (i = 0; i < 10; i++)  //
  {
    feuchte += analogRead(A0); 
    delay(20);   
  }
  feuchte = feuchte / (i);

10 readings will be taken (i=0 through to i=9) but the result will be divided by 9, not 10.

Pete,.

1 Like

What is this?

@PeteKnight
So I have to start with
for (i=1; i<10; i++)?
Or
feuchte = feuchte / 10

@proietti
Includes the Blynk library.

Either solution would work.

It’s not necessary.

Pete.

1 Like

Thank you again Pete.

Tomorrow I’ll change my D1mini and try it again.
Maybe it’s a hardware issue, because till yesterday it works fine and today it stuck…

I’ll give you tomorrow response, thanks for helping me.