Deep Sleep

API Reference


class DeepSleepComponent : public Component

This component allows setting up the node to go into deep sleep mode to conserve battery.

To set this component up, first set when the deep sleep should trigger using set_run_cycles and set_run_duration, then set how long the deep sleep should last using set_sleep_duration and optionally on the ESP32 set_wakeup_pin.

Public Functions

void set_sleep_duration(uint32_t time_ms)

Set the duration in ms the component should sleep once it’s in deep sleep mode.

void set_wakeup_pin(const GPIOInputPin &pin)

Set the pin to wake up to on the ESP32 once it’s in deep sleep mode.

Use the inverted property to set the wakeup level.

void set_wakeup_pin_mode(WakeupPinMode wakeup_pin_mode)
void set_ext1_wakeup(Ext1Wakeup ext1_wakeup)
void set_run_cycles(uint32_t cycles)

Set the number of loop cycles after which the node should go into deep sleep mode.

void set_run_duration(uint32_t time_ms)

Set a duration in ms for how long the code should run before entering deep sleep mode.

void setup()

Where the component’s initialization should happen.

Analogous to Arduino’s setup(). This method is guaranteed to only be called once. Defaults to doing nothing.

void dump_config()
void loop()

This method will be called repeatedly.

Analogous to Arduino’s loop(). setup() is guaranteed to be called before this. Defaults to doing nothing.

float get_loop_priority() const

priority of loop().

higher -> executed earlier

Defaults to 0.

The loop priority of this component

float get_setup_priority() const

priority of setup().

higher -> executed earlier

Defaults to 0.

The setup priority of this component

void begin_sleep_(bool manual = false)

Helper to enter deep sleep mode.

template <typename T>
EnterDeepSleepAction<T> *make_enter_deep_sleep_action()
template <typename T>
PreventDeepSleepAction<T> *make_prevent_deep_sleep_action()
void prevent_deep_sleep()

Protected Attributes

optional<uint64_t> sleep_duration_
optional<GPIOPin *> wakeup_pin_
WakeupPinMode wakeup_pin_mode_ = {WAKEUP_PIN_MODE_IGNORE}
optional<Ext1Wakeup> ext1_wakeup_
optional<uint32_t> loop_cycles_
uint32_t at_loop_cycle_ = {0}
optional<uint32_t> run_duration_
bool next_enter_deep_sleep_ = {false}
bool prevent_ = {false}
template <typename T>
class EnterDeepSleepAction : public Action<T>

Public Functions

EnterDeepSleepAction(DeepSleepComponent *deep_sleep)
void play(T x)

Protected Attributes

DeepSleepComponent *deep_sleep_
template <typename T>
class PreventDeepSleepAction : public Action<T>

Public Functions

PreventDeepSleepAction(DeepSleepComponent *deep_sleep)
void play(T x)

Protected Attributes

DeepSleepComponent *deep_sleep_