Is there anything that would cause a DHT11 to report accurately (as accurate as it can) then the next update cycle to be at -5. Does -5 mean no data? I have three functions pollDHT11, pollDS18B20 and publish. Is this a timing issue or a code problem? It showed up when I got the DS18B20 working but that is also the same time I broke everything out of the loop into functions that called based on the SampleInterval defined.
Sample Interval for DHT and DS18B20 are both 2 Seconds and the metricpublish rate is once per minute
void metricpush(){
Serial.print("Metric Push!");
//sprintf(strwatertemp, "Water Temperature: %2.2f Fahrenheit (Chip Name: %s)", waterfahrenheit, ds18b20.getChipName());
sprintf(strairtemp, "Air Temp %2.2f, Water Temperature: %2.2f", (DHT.getFahrenheit()), waterfahrenheit);
//Serial.print(strairtemp); //Output Publish String for Verification
Spark.publish("tempdata", strairtemp, PRIVATE);
MetricnextPublishTime = millis() + Metric_Publish_Rate;
} //End of metricpush function
//Updates DHT11 Air Temp/Humidity Sensor Data
void getairtemp(){
if (!bDHTstarted) { // start the sample
Serial.print("\n");
Serial.print(n);
Serial.print(": Retrieving information from sensor: ");
DHT.acquire();
bDHTstarted = true;
airtemp = (DHT.getFahrenheit(), 2);
} //End of DHTstarted IF
if (!DHT.acquiring()) { // has sample completed?
// get DHT status
int result = DHT.getStatus();
Serial.print("Read sensor: ");
switch (result) {
case DHTLIB_OK:
Serial.println("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;
}
Serial.print("Humidity (%): ");
Serial.println(DHT.getHumidity(), 2);
Serial.print("Temperature (oC): ");
Serial.println(DHT.getCelsius(), 2);
Serial.print("Air Temperature: ");
Serial.println(DHT.getFahrenheit(), 2);
Serial.print("Temperature (K): ");
Serial.println(DHT.getKelvin(), 2);
Serial.print("Dew Point (oC): ");
Serial.println(DHT.getDewPoint());
Serial.print("Dew Point Slow (oC): ");
Serial.println(DHT.getDewPointSlow());
n++; // increment DHT Sample counter
bDHTstarted = false; // reset the sample flag so we can take another
DHTnextSampleTime = millis() + DHT_SAMPLE_INTERVAL; // set the time for next sample
} // End of Air Temp/Humidity
} //End of getairtemp Function
//Updates DS18B20 Water Temp Sensor Data
void getwatertemp(){
if(!ds18b20.search()){
Serial.println("No more addresses.");
Serial.println();
ds18b20.resetsearch();
watercelsius = ds18b20.getTemperature();
waterfahrenheit = ds18b20.convertToFahrenheit(watercelsius);
DS18B20nextSampleTime = millis() + DS18B20_SAMPLE_INTERVAL;
Serial.print(watercelsius);
}
}//End of Water Temp Collection