0

I cannot do light sleep on my NodeMCU v3 ESP8266, because the function wifi_fpm_do_sleep() returns -1. Can you help me to find why there is an error?

void light_sleep() {
  wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
  gpio_pin_wakeup_enable(GPIO_ID_PIN(gpio_read), GPIO_PIN_INTR_HILEVEL);
  wifi_fpm_open();
  WiFi.disconnect();
  WiFi.mode(WIFI_OFF);
  Serial.print("WiFi Sleep\t");
  WiFi.forceSleepBegin();
  int err = wifi_fpm_do_sleep(0xFFFFFFF);
  Serial.print("ERROR: ");
  Serial.println(err);
}

Thank you.

Jonas
  • 121,568
  • 97
  • 310
  • 388

1 Answers1

0

Right code:

void light_sleep() {
  WiFi.mode(WIFI_OFF);
  wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
  gpio_pin_wakeup_enable(GPIO_ID_PIN(gpio_read), GPIO_PIN_INTR_HILEVEL);
  wifi_fpm_open();
  Serial.print("WiFi Sleep\t");
  int err = wifi_fpm_do_sleep(0xFFFFFFF);
  Serial.print("ERROR: ");
  Serial.println(err);
}

and after light_sleep() must be:

wifi_fpm_do_wakeup();
WiFi.mode(WIFI_STA);