Skip to content
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

Don't error from node.sleep() when a sleep reject occurs #3560

Open
wants to merge 1 commit into
base: dev-esp32
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions components/modules/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,13 @@ static int node_sleep (lua_State *L)
int err = esp_light_sleep_start();
if (err == ESP_ERR_INVALID_STATE) {
return luaL_error(L, "WiFi and BT must be stopped before sleeping");
} else if (err == 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use ESP_ERR_SLEEP_REJECT here? This return code is documented. There is also ESP_ERR_SLEEP_TOO_SHORT_SLEEP_DURATION which maybe should be handled in the same way.

It also isn't clear what the right thing to do is -- it might be surprising to some developers that sleep might not sleep.

// Not documented, and not a esp_err_t, but '1' here means a sleep reject
// occurred. Usually because a GPIO is already in a state that would cause
// an immediate wakeup (in IDFv3 this situation would just cause an
// immediate wakeup and return 0). This isn't really an error condition and
// we should just treat it as OK. esp_sleep_get_wakeup_cause appears to
// still return the correct value when this happens.
} else if (err) {
return luaL_error(L, "Error %d returned from esp_light_sleep_start()", err);
}
Expand Down