Hi,
I have an issue with a setup which consists of:
NodeMCU 1.0
DHT22 Sensor
Local Raspberry Blynk Server
Versions used:
Blynk library used: 0.3.7
Local Rpi server version: 0.16.2
The following program is from instructables, slightly modified:
If i let without the isnan() check of DHT22 read values, i get Nan for both temperature and humidity as well sometimes, and after a while i get only Nan-s on the virtual ports.
Hardware images:
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h >
#define DHTPIN 13 //pin gpio 13 in sensor
#define DHTTYPE DHT22 // DHT 22 Change this if you have a DHT11
DHT dht(DHTPIN, DHTTYPE);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxx"; // Put your Auth Token here. (see Step 3 above)
SimpleTimer timer;
void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, "xxx", "yyy", IPAddress(192,168,0,4));
// Setup a function to be called every 10 seconds
timer.setInterval(10000L, sendUptime);
}
void sendUptime()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
//Read the Temp and Humidity from DHT
float h = dht.readHumidity();
float t = dht.readTemperature();
//t or h sometimes is nan, do not send nan value to blynk
// h and t is nan bc. of the blynk libraty and not from the dht library!!!!!
// Test out to remove every blynk function call, and check serial port
if(isnan(h) || isnan(t))
{
Serial.print(F("Failed to read from DHT sensor!\r\n"));
}
else
{
Blynk.virtualWrite(10, t); // virtual pin
Blynk.virtualWrite(11, h); // virtual pin
Serial.print(F("Everything should be fine, reading transmitted\r\n"));
}
}
void loop()
{
Blynk.run(); //When i comment this line, seems like the readHumidity and ReadTemperature works each time
timer.run();
}
Connecting to the serialPort i saw the following messages:
Serial output with blynk.run() uncommented
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Failed to read from DHT sensor!
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Failed to read from DHT sensor!
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Failed to read from DHT sensor!
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Failed to read from DHT sensor!
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Failed to read from DHT sensor!
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Failed to read from DHT sensor!
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Failed to read from DHT sensor!
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Failed to read from DHT sensor!
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
…
*- After a while i get only
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
…
Serial output with Blynk.run() commented out
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
Everything should be fine, reading transmitted
…
For me it seems like for some reason the Blynk.run() influences the reading from the DHT22 sensor.