Blynk.edgent often sending a Nan value of DHT sensor

Hey guys can u help me i used Wemos D1 Mini with latest version of library Blynk.
i used Blynk.edgent because i want to add provision feature on my project but some weird things came out, my DHT sending me a Nan value when i used it. but when i change with my old project without edgent fiture the problem is gone. so can yall help me how to handle that or maybe teach me how to make some provision thing that blynk can do.

#define BLYNK_TEMPLATE_ID "TMPLWiOwJ-Tk"
#define BLYNK_DEVICE_NAME "Wemos"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
//#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
#define USE_WEMOS_D1_MINI
#include <DHT.h>

#include "BlynkEdgent.h"
#define DHTPIN 2          // What digital pin we're connected to
#define DHTTYPE DHT11     // DHT 11
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
  Serial.begin(9600);
  edgentTimer.setInterval(1000L,sendSensor);
  BlynkEdgent.begin();
}

void loop() {
  BlynkEdgent.run();
  edgentTimer.run();
}

void sendSensor(){
  float temp = dht.readTemperature();
  float hum = dht.readHumidity();

  if(isnan(hum) || isnan(temp)){
    Serial.println("Error");
  }

  Blynk.virtualWrite(V0,hum);
  Blynk.virtualWrite(V1,temp);
}

that is my code when i used blynk edgent. simple but i cant find the problem.

Your sensor can’t read temperature every seconds !
It needs 3 seconds
Try to read every 5 seconds , it’s enough !

it still going… what happen about the blynk.edgent? is that something i can change inside of library? because when i used regular one using my own code, the sensor not giving me any problem even if i used 1sec for the interval.

This is your problem.

Read the “Defining your physical switch and LED” section of this tutorial…

Pete.

also, you should add a BlynkTimer object.

BlynkTimer edgentTimer;

Do you think that the temperature will change every seconds? :thinking::rofl:

A BlynkTimer object called edgentTimer is already defined in the Edgent sketch, so trying to re-define it will probably throw an error.

Rather than piggy-backing off the existing edgentTimer object it would be better to define a second BlynkTimer object called timer and use that.

Pete.

1 Like

well i confused now, so is that wrong when i used declaration of 2 as GPIO 2 which means that is PIN D4? because i already done what are you command, i change it into declaration 4 then i used PIN 2 because the picture says that and now my wemos start blinking but my temperature can send the value but it still giving me some nan problem but decreased, just 2 every 5 second maybe

i dont know if it’s not, because as i see it change probably every 2 seconds, and it just fine when i used 1 sec in my other program. That is why i slapped into it

If you want to check the temperature every second then I’d suggest that you choose a faster sensor. The DHT range of sensors are so inaccurate and slow that they are a joke.

In the meantime, increase your timer to 5 seconds and see what happens with your NAN readings.
Also, if you’re doing this on a breadboard or with a nest of DuPont jumper wires then try soldering the connections instead.

Pete.

2 Likes

But Mr Pete, why when i used PIN D4 for my sensor that problem getting bigger, but when i used D2 as my as my PIN that reduce my problem? you say GPIO4 (pin D2) for the LED right?

No. The internal LED on the D1 Mini and NodeMCU is connected to GPIO2 (the pin labelled D4) which is why the Edgent sketch assigns GPIO2 as the LED pin for these board types.

Pete.

i’am so sorry Mr.Pete i got hooked by this thread, and that right the default give me " 2 ".

i must look at this first.

i’m so sorry.