1
void Sensor_value()
{   server.handleClient();
    humidity = dht.readHumidity();
    temperature = dht.readTemperature();     
 }

I want to make condition if temperature = null and Humidity= null that means the sensor fails to take reading so I want to return and take value again

Coder9390
  • 472
  • 4
  • 21
  • both functions readHumidity() and readTemperature() have float as return type. NULL is a value of type pointer, so you will never get NULL as a result from these functions. I think the library returns NAN if it fails to read from the sensor – Lefteris E Jul 03 '21 at 10:36

1 Answers1

1

The way to do this is:

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;
}

See https://www.hackster.io/MisterBotBreak/how-to-use-temperature-and-humidity-dht-sensors-9e5975 and https://stackoverflow.com/questions/40874880/getting-nan-readings-from-dht-11-sensor.

NULL should only be used with pointers.

Michel Keijzers
  • 12,759
  • 7
  • 37
  • 56