Power Module
The Power module provides functions to manage ESP32 power consumption, allowing you to implement low-power modes (light sleep) and configure wake-up sources.

This module is especially useful for IoT applications powered by battery or solar energy, where minimizing power consumption is crucial to extend device autonomy.
Usage
use Power
To use the Power module, you need to import it into your JARU program. Then, configure one or more wake-up sources and execute sleep() for the ESP32 to enter low-power mode.
Functions
wakeOnTimer
The wakeOnTimer(microseconds) function configures a timer as a wake-up source. The ESP32 will automatically wake up after the specified time.
use Power
// Wake up after 5 seconds (5,000,000 microseconds)
Power.wakeOnTimer(5000000)
Power.sleep()
println("Awakened by timer!")
Parameters:
microseconds: Time in microseconds before waking up (integer or float)
Returns: true if configuration was successful, false otherwise.
For times in seconds, multiply by 1,000,000. For example, 30 seconds = 30,000,000 microseconds.
wakeOnPin
The wakeOnPin(pin, level) function configures an RTC pin as a wake-up source. The ESP32 will wake up when the pin reaches the specified level.
use Power
// Wake up when pin 33 goes HIGH
Power.wakeOnPin(33, HIGH)
Power.sleep()
println("Awakened by pin!")
Parameters:
pin: GPIO pin number (must be a valid RTC pin)level: Level that triggers wake-up (HIGHorLOW)
Returns: true if configuration was successful, false otherwise.
Only certain GPIO pins can be used as RTC wake-up source (ext0). On standard ESP32, valid RTC pins are: 0, 2, 4, 12, 13, 14, 15, 25, 26, 27, 32, 33, 34, 35, 36, 37, 38, 39.
wakeOnGPIO
The wakeOnGPIO() function enables general GPIO wake-up. This option is less power-efficient than wakeOnPin(), but allows using more pins.
use Power
use GPIO
// First configure the pin with gpio_wakeup_enable
GPIO.pinmode(4, GPIO.INPUT)
// (Requires additional system-level configuration)
Power.wakeOnGPIO()
Power.sleep()
Returns: true if configuration was successful, false otherwise.
This function requires GPIOs to be previously configured with gpio_wakeup_enable() at the system level. It's more common to use wakeOnPin() for simple cases.
sleep
The sleep() function executes the ESP32 light sleep mode. The device will enter a low-power state until one of the configured wake-up sources is triggered.
use Power
// Configure timer wake-up
Power.wakeOnTimer(10000000) // 10 seconds
println("Entering sleep mode...")
Power.sleep()
println("Awakened!")
Returns: true if sleep executed successfully, false otherwise.
Light sleep maintains CPU and RAM state, so the program continues exactly where it left off. Deep sleep completely restarts the program. The Power module implements light sleep.
wakeReason
The wakeReason() function returns the cause of the last wake-up. This allows the program to take different actions depending on what triggered the wake-up.
use Power
// Check wake-up cause
var reason = Power.wakeReason()
if (reason == Power.WAKE_TIMER) then
println("Awakened by timer")
elif (reason == Power.WAKE_EXT0) then
println("Awakened by RTC pin")
elif (reason == Power.WAKE_GPIO) then
println("Awakened by GPIO")
else
println("Unknown reason or first boot")
end
Returns: An integer value corresponding to one of the wake-up cause constants.