Closed PurpleAir closed 5 years ago
This may be a fix? https://github.com/adafruit/Adafruit_BME680/pull/22
Something else that is happening, the library when installed using Arduino is not the latest code. I had to manually copy and paste the raw files into it to get the updates that are in here with a fix that seems to solve my problem, ie the implementation of remainingReadingMillis().
In the function int Adafruit_BME680::remainingReadingMillis(void)
Instead of int remaing_time = (millis() - _meas_start) - (int)_meas_period;
It should be int remaing_time = (_meas_start + (int)_meas_period) - millis();
tested it and looks ok for me, will be merged soon. thanks! 👍
I am not sure if this will survive a millis() rollover. Are you @hoffmannjan ?
After implementing this sensor, we experienced a strange, seemingly random behavior. Sometimes, the sensor would initialize and provide readings like expected, other times it would take 60 seconds to provide the first reading, then would be ok after that, other times, it would initiate a delay that was in the hundreds of thousands of seconds so it would just grind everything to a halt for an indefinite period.
After some debugging and running the sample that worked perfectly every time, it turns out that the NTP time sync we use causes this problem. It is something to do with the way you calculate the delay. It could also be a problem with (or if) the millis() rollover were to happen between beginning and ending the reading (see https://arduino.stackexchange.com/questions/12587/how-can-i-handle-the-millis-rollover).
My "quick fix" was to only permit small delays of less than 1 second as follows in three places:
This may work, but it is not a good solution. Would be better to fix the timing properly so these high delays do not happen. It is also not really "async" as implemented since you cannot safely call any of the functions from a ticker or other type of interrupt based function since you use delay().