From af6491738618278835f316d7f9f15bcf249d043a Mon Sep 17 00:00:00 2001 From: Tom Sutcliffe Date: Sun, 4 Dec 2022 11:41:43 +0000 Subject: [PATCH] Don't error from node.sleep() when a sleep reject occurs --- components/modules/node.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/modules/node.c b/components/modules/node.c index af25ccd3..5dfd5032 100644 --- a/components/modules/node.c +++ b/components/modules/node.c @@ -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); }