I would appreciate some assistance. I have got the BME280 to work, but when I include the Deep Sleep code, the BME280 sensor element does not run. I am attaching a screenshot of the (partial, but relevant) code).
Can you please answer some question so that I can better understand what is happening?
The sensor fails to initialize or the BME280 readings are not being printed?
Where are you getting the BME280 readings in your code? In the loop()?
Your code goes to deep sleep after reaching the loop(), so your sensor readings will never be printed.
Do you get any errors on the Serial Monitor?
The sensor readings are not displayed. The ‘deep sleep’ code runs in the setup function, and the sensor runs in the loop function. Also, if I am using code to display the readings in a web server, where do I run the deep sleep code so that the sensor readings are made and these can be read in the web server?
There is some gibberish in the serial monitor, but it also displays that the deep sleep boot count and the timer wake up and going to sleep instructions. But the sensor reading (obviously) does not display once deep sleep is activated.
In a sketch that uses deep sleep, all the code that you want to be executed should go before calling the deep sleep function. Whatever you write after that, won’t be executed because the ESP will be sleeping.
When the ESP32 is in deep sleep mode, the Wi-Fi is off. So, you can’t have a web server running while the ESP32 is in deep sleep.
Alternatively, you can send your sensor readings via MQTT, for example, to another ESP32 that is awake and running the web server.
I hope this helps. Let me know if you have more questions.
Thank you for your prompt replies. Much appreciated. We have got it working by placing the deep sleep code in a function and then calling it in the loop function after the sensor function call. However, while the sensor readings are now being displayed and the deep sleep works accordingly, we do get some gibberish Here is the link to the image of teh ‘gibberish’.
Can I assume that if we want to include the Web Server elements, these will have to be called as a seperate function before the deep sleep function call in the loop?