I have a device using BoronLTE that wakes up every few hours and send Temp/Hum data out to the cloud…however unfortunately I am getting -5 for both Temp/Hum after waking from sleep cycle…the sensor readings are perfectly good when reading without going to sleep…any help is troubleshooting is appreciated!
#define DHTTYPE DHT22
#define DHTPIN D4
PietteTech_DHT DHT(DHTPIN, DHTTYPE);
void temperatureHumidity(){
pinMode(D3, OUTPUT);
digitalWrite(D3, HIGH);
delay(1500);
DHT.begin();
int result = DHT.acquireAndWait();
switch (result) {
case DHTLIB_OK:
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println("Error\n\r\tChecksum error");
break;
case DHTLIB_ERROR_ISR_TIMEOUT:
Serial.println("Error\n\r\tISR time out error");
break;
case DHTLIB_ERROR_RESPONSE_TIMEOUT:
Serial.println("Error\n\r\tResponse time out error");
break;
case DHTLIB_ERROR_DATA_TIMEOUT:
Serial.println("Error\n\r\tData time out error");
break;
case DHTLIB_ERROR_ACQUIRING:
Serial.println("Error\n\r\tAcquiring");
break;
case DHTLIB_ERROR_DELTA:
Serial.println("Error\n\r\tDelta time to small");
break;
case DHTLIB_ERROR_NOTSTARTED:
Serial.println("Error\n\r\tNot started");
break;
default:
Serial.println("Unknown error");
break;
}
}
********************* Sleep Code
void sleep(){
SystemSleepConfiguration config;
config.mode(SystemSleepMode::ULTRA_LOW_POWER)
.duration(60min);
System.sleep(config);
System.reset();
}
I don’t know the root cause on why you get the error on the first reading but for a DS18B20 temperature sensor. However, on a DS18B20 sensor, I had something similar. So I now use logic that simply reads it again if the measurement is invalid. Either your DHT22 library has something similar or you could implement something similar. For example… here is the code snippet of the DS18B20 temperature reading to read up to 4 times if earlier attempts return invalid data.
float _temp;
int i = 0;
do {
_temp = ds18b20.getTemperature();
} while (!ds18b20.crcCheck() && MAXRETRY > i++);
if (i < MAXRETRY) {
celsius = _temp;
fahrenheit = ds18b20.convertToFahrenheit(_temp);
Log.info("Temperature %.2f C %.2f F ", celsius, fahrenheit);
}
else {
celsius = fahrenheit = NAN;
Log.info("Invalid reading");
}
In this case… the variable MAXRETRY is set to 4. So basically, try reading the sensor up to 4 times until a valid measurement is returned. If it was me, I’d do something similar for your DHT22 sensor. Hope that helps! A few google searching might get you some examples. In this case, looks like the library itself might have a retry count built into it that you may need to increase? Not sure. I’ll let you do the further investigation in the library you use.