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

This commit is contained in:
Tom Sutcliffe 2022-12-04 11:41:43 +00:00
parent ed85e21a9b
commit af64917386
1 changed files with 7 additions and 0 deletions

View File

@ -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) {
// 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);
}