vladak / shield

code for ESP32 Adafruit Feather to get various sensor readings and publish them to MQTT broker
2 stars 0 forks source link

avoid the time.sleep() #6

Closed vladak closed 1 year ago

vladak commented 1 year ago

Currently the code sleeps for a bit after it is done collecting and sending the data so that it is possible to break into REPL via the web workflow on the ESP32 V2. This should be avoided to conserve the battery.

As suggested on the forums, one way might be to use the button on the ESP32 board to detect the request to exit the program without entering deep sleep.

vladak commented 1 year ago

Also, before the button handling is done, consider the possibility of using light sleep as described on https://learn.adafruit.com/adafruit-esp32-feather-v2/power-management , perhaps there is a way how to switch to that from CicruitPython.

vladak commented 1 year ago

There is alarm.light_sleep_until_alarms() which works like this:

If CircuitPython is connected to a host computer, the connection will be maintained, and the microcontroller may not actually go into a light sleep. This allows the user to interrupt an existing program with ctrl-C, and to edit the files in CIRCUITPY, which would not be possible in true light sleep. Thus, to use light sleep and save significant power, it may be necessary to disconnect from the host.

This would not enable the web workflow during the light sleep (so to upload files would be possible only if connected to host via USB after breaking from the "light sleep"), however should conserve much more power than time.sleep() when disconnected from the host.