I have now converted completely to the Piettetech library.
I have discovered that it is not a good idea to call
On anything where you can’t conveniently hit the reset button as there are definitely conditions under which it will never return.
I didn’t delve deeply into exactly what those conditions are, but they occurred frequently enough in my environment that I chose to develop different code to resolve the situation.
I’ve replaced it with the following code:
for(i=0; i<5; i++)
{
// Retry up to 5 times
result = DHT.acquire();
if (result == DHTLIB_ERROR_ACQUIRING)
{
System.sleep(SLEEP_MODE_DEEP, 2); // Reset system and try again in 2 seconds.
delay(2000);
}
startup = millis();
// Wait up to 5 seconds for acquisition. Accept short wait if millis counter wrap.
while (millis() >= startup && startup+5000 > millis() && DHT.acquiring())
{
Serial.print(".");
Spark.process();
delay(1000);
}
Serial.print((millis() >= startup) ? "M" : "m");
Serial.print((startup+5000 > millis()) ? "T" : "t");
Serial.println(DHT.acquiring() ? "A" : "a");
result = DHT.getStatus();
if (result == DHTLIB_OK) break; // Got a valid sample.
Serial.print("Failed result: ");
Serial.println(result);
}
In my environment, a millis() counter wrap is extremely unlikely since I go into Deep Sleep quite frequently and the counter is reset on wakeup. There are more robust ways to deal with counter-wrap issues, but they complicate the code and since it’s so unlikely to occur in this application it doesn’t seem worth the effort.
I’ve had reasonable luck with the 15 second awake time and I’m happy to report that my two photons have been reliably gathering data since last night with no further hangs, dropouts, or noticeable unhanded exceptions occurring since that time. You can see the results here
The Photon is collecting the Attic data. The Living Room and Back Yard are being collected by Adafruit ESP8266 boards with DS18B20 sensors. The other variables are being collected by the server polling the Thermostat.
(this is a stepping-stone application for the truly remote sensor deployments I’ll be doing supporting equipment installations on remote mountain tops).
Thanks for all the help getting me to this point.