0

我无法在 NodeMCU v3 ESP8266 上进行轻度睡眠,因为该函数wifi_fpm_do_sleep()返回 -1。你能帮我找出错误的原因吗?

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);
}

谢谢你。

4

1 回答 1

0

正确的代码:

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);
}

并且在 light_sleep() 之后必须是:

wifi_fpm_do_wakeup();
WiFi.mode(WIFI_STA);
于 2021-07-28T13:16:53.903 回答