-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add deepsleep module for battery application #4456
base: main
Are you sure you want to change the base?
Conversation
thank you for contributing! |
Thank you for the feedback! I didn’t notice an existing deep-sleep module in the repository when I started working on this. My goal was to create a module specifically focused on managing sleep when the battery voltage is low, while adding multiple wake-up methods, including touch wake-up and preset wake-up. Additionally, I included configurable IO pin settings to achieve optimal power efficiency. I’ll look into integrating these features with the existing deep-sleep module to ensure better compatibility and functionality for users. @DedeHai |
the PR for the deep-sleep UM was pending for quite some time, I wanted to run some more long-term tests but finally I got it merged just about after you opened this PR. |
The deep-sleep UM primarily uses a wakeup timer as its trigger source from deep-sleep status. Shouldn't this functionality be distinct from the battery UM? Regarding pullup/pulldown configuration: it works well for some pins like 12, 13, 14, 15, and 27, but not reliably for others like 25 and 26. Is there any way we can override or influence this "feature" in the IDF? |
how did you figure that?
deep sleep has nothing to do with battery UM, so dont know what you mean.
did you test to disable pullup/down successfully? |
if (presetWake) {
Unlike the battery usermod, the deep-sleep usermod supports preset delays, highlighting their distinct functionalities."
I found that hold mode(rtc_gpio_hold_en) performs reliably on IO25, but it doesn't seem to work consistently on IO26. Do you have any insights into why this happens? |
I thought you were referring to the existing deep-sleep UM, its a bit confusing both are called that :)
I dont know what you mean by that.
I do not unfortunately. you need to dig though the IDF code and the espressif forum as well as the datasheet to see if there is a hardware bug, IDF bug or if that is a feature. So to sum up:
|
Add only the touch option and preset wakeup timer |
|
Are you referring to this line:
I have successfully run this code on the ESP32. However, I cannot test it on the ESP32-C3 as I don’t have this board. |
Thanks for your feedback. I forgot that this function is used in another part of my repository's main branch for the user info UI, and it is useful for other users. I will add this to the WLED repository now.
I found this code for esp32 c3 |
if you do: add a #define users wanting debug info can use to add it. the wake-up cause is of no use to normal users. |
done |
What does draft status mean in this repository? |
draft means not finished and not ready to merge |
what sleps are needed to complete the pull request? |
fix the ones I marked |
What problems need to be fixed now? Do I need to fix them? |
see inline comments. |
After pushing the latest commit, I believe I have resolved all the issues you raised. If there's anything you're still not satisfied with, please let me know. |
there is plenty of unresolved comments |
Or do you mean the conversations? I believe I have resolved all the issues you mentioned. If not, please let me know or show them to me again |
I have no idea, maybe you disabled inline comments in github? that is beyond my knowledge I am afraid. |
@DedeHai your comments are marked "pending" - it means you may need to finish your review for the comments to be published. |
@softhack007 thanks, that may have been it. interesting, I never had to do that before... |
Added a commit for ESP32-C3 and ESP32-S2 development boards |
thanks for the update, I will look at it in more detail soon. |
#endif | ||
|
||
WiFi.disconnect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not needed, it is shut down in deep sleep.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read that it is best practice to do this to avoid timeouts on connected clients, may be useful if sleep time is short, so keep it.
@@ -66,7 +66,8 @@ enum struct PinOwner : uint8_t { | |||
UM_LDR_DUSK_DAWN = USERMOD_ID_LDR_DUSK_DAWN, // 0x2B // Usermod "usermod_LDR_Dusk_Dawn_v2.h" | |||
UM_MAX17048 = USERMOD_ID_MAX17048, // 0x2F // Usermod "usermod_max17048.h" | |||
UM_BME68X = USERMOD_ID_BME68X, // 0x31 // Usermod "usermod_bme68x.h -- Uses "standard" HW_I2C pins | |||
UM_PIXELS_DICE_TRAY = USERMOD_ID_PIXELS_DICE_TRAY // 0x35 // Usermod "pixels_dice_tray.h" -- Needs compile time specified 6 pins for display including SPI. | |||
UM_PIXELS_DICE_TRAY = USERMOD_ID_PIXELS_DICE_TRAY, // 0x36 // Usermod "pixels_dice_tray.h" -- Needs compile time specified 6 pins for display including SPI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please revert unnecessary changes
if (wakeupAfter) { | ||
nextWakeupMin = nextWakeupMin < wakeupAfter / 60.0 | ||
? nextWakeupMin | ||
: wakeupAfter / 60.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a) dont use floats
b) use seconds and not minutes throughout the code: this breaks original code: if I set to 5s, it will turn to 0
if (nextWakeupMin > 0) { | ||
esp_sleep_enable_timer_wakeup(nextWakeupMin * 60ULL * | ||
(uint64_t)1e6); | ||
DEBUG_PRINTF("wakeup after %d minites", nextWakeupMin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
esp_sleep_enable_timer_wakeup((uint64_t)wakeupAfter * (uint64_t)1e6); //sleep for x seconds | ||
int nextWakeupMin = 0; | ||
if (presetWake) { | ||
nextWakeupMin = findNextTimerInterval() - 1; // wakeup before next preset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sleep is not that accurate, if you sleep for 2 days, this can miss the preset. not sure what a good way to handle it would be. maybe wake up offset should depend on length of sleep, use datasheet accuracy values to determine the amount (I think RTC accuracy is ±2% but did not check).
also when this wake-up is used, the lights should not turn on until the preset time is reached. could also check how far off the time still is and go back to deep-deep sleep.
esp_sleep_enable_timer_wakeup(nextWakeupMin * 60ULL * | ||
(uint64_t)1e6); | ||
DEBUG_PRINTF("wakeup after %d minites", nextWakeupMin); | ||
DEBUG_PRINTLN(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just make the new line in the print above this line and remove.
|
||
WiFi.disconnect(); | ||
WiFi.mode(WIFI_OFF); // Completely shut down the Wi-Fi module | ||
#ifndef CONFIG_IDF_TARGET_ESP32C3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not move this in the ifdef above?
} | ||
|
||
int findNextTimerInterval() { | ||
int currentHour = hour(localTime), currentMinute = minute(localTime), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a check here if the time is actually valid, not sure WLED already has a function for that but if time is not valid, this function will return bogus values.
The SleepManager module for WLED is designed to manage power consumption by enabling the ESP32 to enter deep sleep based on idle time or battery voltage levels. This module allows for more efficient battery use by automatically putting the device to sleep and waking it up based on predefined conditions. It is especially useful for battery-powered setups where minimizing power consumption is essential.