Blynk stops working after a moment

This happened to me a few months back, and it was the reason I momentarily stopped using blynk. Recently I went back to using the app, and it’s happening again.
Basically what I’m trying to do is access info from a DHT22 sensor, which I’m storing in virtual pins.
I’m having my arduino connected to a computer through USB. Tried it with two different computers, one running windows and one OSX.
What happens is that for the first minute or so everything works perfectly. Blynk shows me all the info I expect it to. But after that, it get’s stuck. So the temperature and humidity stop updating after a while. I thiught this was rather weird, but it just keeps happenning to me, and I can’t find anyone who’s had the same problem before me.

Do you get any error message?
Also, if you could provide us the code you are using it might be helpful.

I don’t get any error messages. The displays on the blynk app simply stop updating.
The code is this:

#include <SoftwareSerial.h>
#include "DHT.h"
#include <Time.h>

SoftwareSerial DebugSerial(10, 11);

#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleStream.h>

#define DHTPIN 2
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);


char auth[] = "---";

void setup() {
  // put your setup code here, to run once:
  DebugSerial.begin(9600);

  Serial.begin(9600);
  Blynk.begin(auth, Serial);

  pinMode(8, OUTPUT);

  dht.begin();
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(2000);

  float luminosity = analogRead(0);

  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);

  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  float hi = (dht.computeHeatIndex(f, h) - 32)/1.800;

  Blynk.virtualWrite(1, t);
  Blynk.virtualWrite(2, h);
  Blynk.virtualWrite(3, luminosity);
  Blynk.virtualWrite(4, hi);

  Blynk.run();
}

@AugustoQ one you have flooded the Blynk servers with your bad code you are locked out.
Study SimpleTimer.

1 Like

As @Costas said you are flooding and getting disconnected. You have to remove the Blynk.virtualWrite() from inside the Void loop()
You could try using something like this:

#include <SoftwareSerial.h>
#include "DHT.h"
#include <Time.h>
#include <SimpleTimer.h>
SoftwareSerial DebugSerial(10, 11);

#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleStream.h>

#define DHTPIN 2
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

SimpleTimer timer;

char auth[] = "---";

void setup() {
  // put your setup code here, to run once:
  DebugSerial.begin(9600);

  Serial.begin(9600);
  Blynk.begin(auth, Serial);

  pinMode(8, OUTPUT);
  timer.setInterval(1000L, BlynkUpdate); 
  dht.begin();
}

Void BlynkUpdate()
{
  Blynk.virtualWrite(1, t);
  Blynk.virtualWrite(2, h);
  Blynk.virtualWrite(3, luminosity);
  Blynk.virtualWrite(4, hi);
} 
void loop() {
  // put your main code here, to run repeatedly:
  delay(2000);

  float luminosity = analogRead(0);

  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);

  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  float hi = (dht.computeHeatIndex(f, h) - 32)/1.800;

  Blynk.run();
  timer.run();
}

But you need <SimpleTimer.h> library.

2 Likes

@AugustoQ I added one line at the end of the code. I forgot the timer.run(). Without it the timer wont work.

1 Like

@AugustoQ we also have a bunch of examples showing how to work with Blynk. Here is example for DHT :

Just keep the last 2 lines of the loop in the sketch by @AndreSepulveda. Everything else in a function called by SimpleTimer and don’t use delay() in ESP sketches other than delay(1).

@pavel maybe mod the libraries to count the number of lines in loop and if more than 2 crash the compiler. With a link to the PUSH data example as a compiler error.

Many new Blynkers are not reading the docs. Perhaps on the library page, which many don’t read, and the Getting Started page just a short statement why delays are not used in Blynk and ESP sketches, why almost all sketches have just 2 lines in the loop and that SimpleTimer is vital if they want their sketches to work.

2 Likes

@vshymanskyy what if we check for virtualWrites in void loop and give an error? Is it possible?

love it!!!

so many newbies fail at step one.

No it is not possible…