Using an ESP8266 (nodemcu hardware, running as ESP8266 standalone)) connected by Wifi, with just a DHT22 temperature probe connected. Blynk library version 0.5.0. Adafruit DHT Library 1.5.0. Blynk App 2.18.1 running on Android. Connected to Blynk’s servers.
My program simply sends temperature and humidity values to the server once a second, together with any newly reached maxima and minima in those values.
The problem is that the code runs fine for a few days, and then I stop receiving any data updates on my phone - even though it shows the sensor/ESP8266 are still connected. This is repeatable, and happens after the same length of time each time.
I suspect a memory leak or a counter overflowing inside the library, or similar issue, as my own code is simple. See below.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
char auth[] = "<secret>";
char ssid[] = "<secret>";
char pass[] = "<secret>";
#define DHTPIN D4 // What digital pin DHT22 is connected to
#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
static float t, tmin, tmax, h, hmin, hmax;
BLYNK_WRITE(V0) // Button to reset limits
{
h = dht.readHumidity();
t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
hmin = h; Blynk.virtualWrite(V1, h); // hmin
hmax = h; Blynk.virtualWrite(V2, h); // hmax
tmin = t; Blynk.virtualWrite(V3, t); // tmin
tmax = t; Blynk.virtualWrite(V4, t); // tmax
// Also update current value
Blynk.virtualWrite(V5, h); // h
Blynk.virtualWrite(V6, t); // t
}
BLYNK_WRITE(V1) { hmin = param.asFloat(); } // For data coming from server
BLYNK_WRITE(V2) { hmax = param.asFloat(); }
BLYNK_WRITE(V3) { tmin = param.asFloat(); }
BLYNK_WRITE(V4) { tmax = param.asFloat(); }
void sendSensor()
{
h = dht.readHumidity();
t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
if(h<hmin || isnan(hmin)) {hmin=h; Blynk.virtualWrite(V1, h);}
if(h>hmax || isnan(hmax)) {hmax=h; Blynk.virtualWrite(V2, h);}
if(t<tmin || isnan(tmin)) {tmin=t; Blynk.virtualWrite(V3, t);}
if(t>tmax || isnan(tmax)) {tmax=t; Blynk.virtualWrite(V4, t);}
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
dht.begin();
Blynk.syncVirtual(V1,V2,V3,V4); // Get old limits from server
timer.setInterval(10L * 1000L, sendSensor); // Set timer to send data every 10 s
}
void loop()
{
Blynk.run();
timer.run();
}