Feedback on ESP32 Sleep options I'm working on (for now)

adafruit.io wippersnapper BETA support, discussions, and more!

Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Locked
User avatar
rgreer4
 
Posts: 1
Joined: Tue Jan 03, 2023 4:26 am

Feedback on ESP32 Sleep options I'm working on (for now)

Post by rgreer4 »

I know sleep is in the works on https://github.com/adafruit/Adafruit_Wi ... issues/327 and https://github.com/adafruit/Adafruit_Wi ... issues/191 and I really love the simplicity of WipperSnapper for datalogging with no code or custom front end -- but for some body mounted stuff, really need deep sleep.

Was thinking of implementing something like this via a fork for now, where sleep settings would be configured via a "sleep.json" file much like wifi secrets. (And then ideally most of this is replaced by device config in the adafruit interface once sleep implemented.)

In short, if enabled, the device would sleep after the first data update cycle completed. Additionally, would add a number of settings/changes to support wakeup options, and help manage a low power device that sleeps whenever possible, with the fastest network connection possible. I prefer the LiPo's strapped to my chest be...smaller.

My draft config file as a basic design doc:

Code: Select all

{
  "sleep_enable": true,

  "sleep_enable_pin_enabled": true,
  "sleep_enable_pin": "A0", 

  "sleep_initial_min_awake_seconds": 10,

  "sleep_mode_options": "deep",
  "sleep_mode": "deep",

  "sleep_wake_type_options": "timer|pin|both|none", 
  "sleep_wake_type": "both",

  "sleep_cycle_timer_seconds": 300,

  "sleep_wake_pin": "A0",
  "sleep_wake_pin_trigger_high": true,
  "sleep_wake_pin_pull": true,

  "powersave_disable_pixel_on_wake": true,
  "powersave_sleep_on_all_halts": true,
  "powersave_max_awake_seconds": 15,

  "powersave_wifi_sleep_on_failure": true,
  "powersave_wifi_override_max_retries": 1,
  "powersave_wifi_override_retry_ms": 4000,
  "powersave_wifi_override_check_ms": 100,
  "powersave_wifi_skip_ssid_scan": true,
  "powersave_wifi_fixed_channel": null,
  "powersave_wifi_fixed_bssid": null,

  "powersave_wifi_fixed_config_options": "if used, all are required",
  "powersave_wifi_fixed_config_local_ip": null,
  "powersave_wifi_fixed_config_gateway": null,
  "powersave_wifi_fixed_config_subnet": null,
  "powersave_wifi_fixed_config_dns1": null,
  "powersave_wifi_fixed_config_dns2": null,
  
  "powersave_mqtt_sleep_on_failure": true,
  "powersave_mqtt_override_max_retries": 1,
  "powersave_mqtt_override_server_ip": null,
}
Notes:
  • The "_options" elements are just comments.
  • Sleep enable pin on the device aside from the obvious, allows a fast update timeframe in WipperSnapper and a longer sleep time, which could be used to switch between slow and fast update times with a switch on the device.
  • Timer mode would attempt to keep the total awake+asleep time consistent so log entries have roughly the same intervals.
  • The bottom powersave_ section is an initial list of items the could save awake time, preferring low power consumption over reliability. Would include any potential long delays or retry loops, lookups that can be sped up with hard-coding, a hard awake time limit, etc.
It's just deep sleep, as light sleep would be more complex to add, and it doesn't save much or any power. Pin wake consumes 6-8x more power than Timer wake, at least on some boards.

Some of the powersave options are pretty important for a device that sleeps (especially wearable) as for example, currently failing to find the set WiFi SSD causes a 60 second powered delay until hitting the watchdog reset, and repeating forever. Simply adding sleep alone would have a lot of cases still stuck with power on.

Was just curious if this would be useful for anyone else, and if that feature set would be reasonably useful sleep functionality? It seems pretty straightforward to add in -- although also a bit messy to do in a manner that keeps the structure the same, so it's easy(er) to keep up to date.

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: Feedback on ESP32 Sleep options I'm working on (for now)

Post by brubell »

Hi, wow, thank you for your thoughts about this! As this is more firmware-focused and less support-focused, would it be possible for you to cross-post your thread to either if the GitHub issues you linked (https://github.com/adafruit/Adafruit_Wi ... issues/191)? I can track discussion revolving around the firmware better over there and don't want to drop anything.

You put a lot of thought into this and I want to address everything!

As a note, we were/are likely going to implement this on the Adafruit IO website, exposing options so a user can configure sleep modes. It may be a frontend element that tells a device to write a configuration to a file on its file system that's saved between runs. On my roadmap, displays will be implemented next (Officially), then sleep modes. I am currently thinking about displays, and I haven't yet thought deeply about sleep modes yet.
In short, if enabled, the device would sleep after the first data update cycle completed
I like it. However, I have differing thoughts about how timer wake/sleep will be implemented. In Adafruit IO, components sending data to IO may update at different intervals. Consider a Feather ESP32v2 with a BME280 and LiPo battery monitor reporting back to Adafruit IO. The BME280's value could be sent every 15 minutes while the battery monitor sends data every hour. We'll likely need some "smart math" to handle these cases.

Sleep enable pin on the device aside from the obvious, allows a fast update timeframe in WipperSnapper and a longer sleep time, which could be used to switch between slow and fast update times with a switch on the device.
I was mostly considering sleep based on Timer rather than Pin wake. What is your use case for pin wake?
The bottom powersave_ section is an initial list of items the could save awake time, preferring low power consumption over reliability. Would include any potential long delays or retry loops, lookups that can be sped up with hard-coding, a hard awake time limit, etc.
I haven't considered this but I'm not sure if bypassing some of our reliability checks at bootup is a good idea, especially for long-term/long-running devices. I can do power profiling around this with my nordic ppk2 when I get to it. I agree with disabling pixels on wake and cutting power to the I2C/pixels pin(s) (on newer Adafruit boards this is possible).
Simply adding sleep alone would have a lot of cases still stuck with power on.
I am not sure what you mean here - we use a Watchdog timer to reset devices that fail during the boot process.
Was just curious if this would be useful for anyone else, and if that feature set would be reasonably useful sleep functionality? It seems pretty straightforward to add in -- although also a bit messy to do in a manner that keeps the structure the same, so it's easy(er) to keep up to date.
I'm very into this, WipperSnapper is open source and we accept pull requests.

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Adafruit IO Wippersnapper Beta”