cesanta / mongoose-os

Mongoose OS - an IoT Firmware Development Framework. Supported microcontrollers: ESP32, ESP8266, CC3220, CC3200, STM32F4, STM32L4, STM32F7. Amazon AWS IoT, Microsoft Azure, Google IoT Core integrated. Code in C or JavaScript.
https://mongoose-os.com
Other
2.51k stars 429 forks source link

Automatic power saving esp32 when idle. #541

Open Harvie opened 4 years ago

Harvie commented 4 years ago

Hello, i am using mongoose os on ESP32 based power sensitive project.

Is there any chance to change mongoose behaviour in such way that it would automaticaly bring esp32 to some kind of low-power (sleep or low CPU clock frequency) mode until there is event or interrupt handled and automaticaly turn the power back on, once something starts to happen again...

Kinda similar to how my laptop increases power when i start compiling the mongoose project and later when it's done, the everything gets cool again and fan turns off.

Our device has temperature sensor to measure ambient temperature, but it gets affected by heat from esp32. We tried to address this issue in mechanical design, but it is still thrown off by couple of degrees C.

DrBomb commented 4 years ago

All the esp-idf methods are available when you compile for the esp32. Here's some pages that might do what you need:

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/sleep_modes.html https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/power_management.html

Of course, none of these power modes are supported by mongoose. Feel free to let us know your results.

Harvie commented 4 years ago

I will try the following to see if that will work... Hopefully it will be helpful without any further code modifications... But we can't really tell unless we test this.

build_vars:
  ESP_IDF_SDKCONFIG_OPTS: >
    ${build_vars.ESP_IDF_SDKCONFIG_OPTS}
    CONFIG_PM_ENABLE=y
    CONFIG_PM_DFS_INIT_AUTO=y
    CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
Harvie commented 3 years ago

Turns out that configuration in previous post actualy does something. Because it downscaled CPU clock to such extent that it actualy broken the UART timing during low-load scenarios. Which means it works! Also @rojer provided his expertise and fixed the UART problem by reconfiguring it to use independent clock source ( #556 ), so thanks to him, we can now have both power saving mode and reliable UART at the same time. yay!

kargarisaac commented 2 years ago

I have the same goal. I use deep sleep mode and wake it up every hour to measure sth and send data via mqtt and again go to deep sleep mode. I wonder if there is anything else I can do to use less power. Should I go for arduino to have this capability or adding the above configs to mos.yml does the job?