Thanks everyone for comments.
(1) After rebooting, the project has now run for 12 hours (previously it was about 6 hours), and still going. It is thus behaving differently to its consistent failure time with the DHT22. It could still be memory corruption, of course, but it may also be that my NodeMCU hardware. is flaky and that the consistent failure times before were chance.
(2) Costas, the push button is basically never used. It is just there to reset the limits if for any reason the values get corrupted. I have not pushed it during the runs when failure occurred, I agree this could be coded better, and will change it to set a flag, triggering it to reset the values on the next normal read.
(3) Marvin, busa, thanks for your data points indicating that projects can run for a long time without issues. That is tipping the balance away from a memory leak.
(3) Costas, I am using v2.3.0 of the BME Library, and while 3.0.0 rc may well be better, it won’t be responsible for the fault when using the DHT sensor, so is not really relevant to this discussion.
Costas, thank you for taking the time and trouble to replicate my setup. It seems to point to some hardware issue with my nodemcu v0.9 (either generically for such devices, or that just my device is bad).
Gunner: going back to an earlier point you made: the device is only 4m from the router, with only one pane of glass in between, so Wifi signal should be quite strong. Plus, the device appears connected even when I stop getting data. So I don’t think Wifi interference is the issue - surely in that case I would just lose a few readings. Anyway, the app shows connectivity is fine, and my LED is showing that the sensor is not returning values, which is why none are being sent to the server.
So going along the hardware line further:
- I believe my power supply is good. It is a genuine Samsung 2A power supply, so hopefully current draw will not be causing voltage drops.
- Whatever is causing the issue affects the NodeMCU irreversibly until the next reboot. I don’t just lose a few sensor values. Once the sensor stops sending values, I dont get any more. Something “locks up”. Whatever is locked up is not just i2C, as it also happens for the DHT22, yet the device apparently remains connected.
- Do any of the other pins need to be tied up or down to help reject interference?
- If there is interference, how could it work in such a way as to not be transient, but to cause a lock up (for example, maybe receiving an interrupt on some pin at the wrong time could be an issue).
Anyway, the key thing now is to replace the NodeMCU hardware, and see if the code runs without locking up. I’ll do that as soon as the replacement arrives.
Any further insight welcomed. Thanks again to all who are helping to resolve this.