You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The way the waiting is done in that function presents two problems.
If the wayiting time is rather long and the sensor slow to respond, the missing Particle.process() might cause the cloud connection to drop.
But the main issue is this part
Since those two lines will be execeuted within the same millisecond in almost every case, the millis() > start will almost always be false because they will be equal causing to drop out of the wait immediately before the acutal measurement will be finished.
But in fact that condition is superfluous all together - as are other wrap round "precautions" - as unsigned integer calculation will be tolerant to such conditions.
So a (for me) working implementation of that function would look like this
intPietteTech_DHT::acquireAndWait(uint32_t timeout) {
acquire();
uint32_t start = millis();
uint32_t wrapper;
while(acquiring() && (timeout == 0 || ((millis()-start) < timeout))) Particle.process();
if (acquiring())
{ // if we are still acquiring, we've had a timeout// ---- most likely not needed, but haven't thought into it too deeply ;-) ----if (millis() < start) // millis counter wrapped
{
wrapper = (~start)+1; // Compute elapsed seconds between "start" and counter-wrap to 0
timeout -= wrapper; // Subtract elapsed seconds to 0 from timeout
}
// ----------------------------------------------------------------------------
_status = DHTLIB_ERROR_RESPONSE_TIMEOUT;
}
returngetStatus();
}
The text was updated successfully, but these errors were encountered:
Removing millis() > start && corrected my issues using a timeout parameter in the acquireAndWait function as well. When using any timeout value an initial read error of not started (DHTLIB_ERROR_NOTSTARTED) would be thrown and no subsequent reads return a value (though no errors).
The if (acquiring()) section changed by @ScruffR makes sense as well, plus the status DHTLIB_ERROR_RESPONSE_TIMEOUT is getting set which isn't being done in the current release version.
@brettski, which release version do yo refer to?
Since this repo seems to have gone stale (no issue reports addressed for a long time), I took the liberty to get the "Particle ownership" to the library transferred to the Particle Elite repo. https://build.particle.io/libs/PietteTech_DHT/0.0.5
@ScruffR I am using the one from this repository, I wasn't aware of the version you linked. I may add that one into my project and retest. I actually didn't know about those libraries. Thanks for the information!
The way the waiting is done in that function presents two problems.
If the wayiting time is rather long and the sensor slow to respond, the missing Particle.process() might cause the cloud connection to drop.
But the main issue is this part
Since those two lines will be execeuted within the same millisecond in almost every case, the
millis() > start
will almost always befalse
because they will be equal causing to drop out of the wait immediately before the acutal measurement will be finished.But in fact that condition is superfluous all together - as are other wrap round "precautions" - as unsigned integer calculation will be tolerant to such conditions.
So a (for me) working implementation of that function would look like this
The text was updated successfully, but these errors were encountered: