Hey guys,
I'm having trouble getting the ESP8266 to sleep light mode.
From the description in this document, (with similar example on the final pages), if I use a value less than 0xFFFFFFF, in wifi_fpm_do_sleep(), the ESP should go into sleep light mode forever.
And it can be woken up by a GPIO.
Using these conditions I can get it to work correctly.
ESP8266 enters sleep light mode, and exits when I put the GPIO 2 in LOW level. (set with wake up GPIO).
Per the document, if I use a value less than 0XFFFFFF, in
wifi_fpm_do_sleep(), this value should be used as a timer to wake up the ESP8266.
But when using any recommended value (between 10000 and 268435454) ESP does not go into sleep light mode.
There is relatively little information about sleep light mode.
I searched here in the forum with the argument "ESP8266 sleep light mode" and I didn't find any topic that helped me.
If anyone has any information that can help me to solve the problem or for me to give up the project,
Thank you in advance.
What does the wifi_fpm_do_sleep() call return?
Did you notice that the argument value is in µs? So the maximum value let the ESP8266 sleep for about 4 minutes.
#include "Arduino.h"
#include <ESP8266WiFi.h>
// Required for LIGHT_SLEEP_T delay mode
extern "C" {
#include "user_interface.h"
}
const char* ssid = "xxxxxxx";
const char* password = "yyyyyyyyyyyy";
//----------------------------------------------------------------
//The setup function is called once at startup of the sketch
void setup() {
Serial1.begin(115200);
while (!Serial1) { }
Serial1.println();
Serial1.println("Start device in normal mode!");
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial1.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial1.print(".");
}
Serial1.println("");
Serial1.print("Connected to ");
Serial1.println(ssid);
Serial1.print("IP address: ");
Serial1.println(WiFi.localIP());
}
//----------------------------------------------------------------
void callback() {
Serial1.println("Callback");
Serial1.println(millis());
Serial.flush();
}
//----------------------------------------------------------------
void loop() {
Serial1.println("Enter light sleep mode");
// Here all the code to put con light sleep
// the problem is that there is a bug on this
// process
//wifi_station_disconnect(); //not needed
uint32_t sleep_time_in_ms = 10000;
wifi_set_opmode(NULL_MODE);
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
wifi_fpm_open();
wifi_fpm_set_wakeup_cb(callback);
wifi_fpm_do_sleep(sleep_time_in_ms * 1000 );
delay(sleep_time_in_ms + 1);
Serial1.println("Exit light sleep mode");
WiFi.begin(ssid, password);
Serial1.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial1.print(".");
}
Serial1.println("");
Serial1.print("Connected to ");
Serial1.println(ssid);
Serial1.print("IP address: ");
Serial1.println(WiFi.localIP());
wifi_set_sleep_type(NONE_SLEEP_T);
delay(10); // Put the esp to sleep for 15s
}
I tested both codes: The one from the author " SeregaKai " and the answer from " Orcanbull ". Both had the same problem.
ESP does not go into sleep mode for 4 seconds as tested.
1 sec = 1000 x 4000 at wifi_fpm_do_sleep(1000UL * 4000UL).
Current time between sleep and wake up 1 ms.
Sleep
Wake Up
1
Sleep
Wake Up
1
extern "C" {
#include "user_interface.h"
}
unsigned long myTime;
//------------------------------------------------ ----------------
//The setup function is called once at startup of the sketch
void setup() {
Serial.begin(115200);
}
//------------------------------------------------ ----------------
void loop() {
Serial.println("Sleep");
sleepNow();
}
//------------------------------------------------ ----------------
void fpm_wakup_cb_func1() {
wifi_fpm_close(); // disable force sleep function
}
//------------------------------------------------ ----------------
void sleepNow() {
myTime = millis();
wifi_set_opmode(NULL_MODE);
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
wifi_fpm_set_wakeup_cb(fpm_wakup_cb_func1);
wifi_fpm_open();
wifi_fpm_do_sleep(1000UL * 4000UL);
Serial.println("Wake Up");
Serial.println(millis() - myTime);
Serial.println("");
}
About the search argument:
Using the search argument you suggested, I only found 9 links.
but I had already seen all 9.
I'll make a post on the expressif forum.
About my comment that it had worked in reality it doesn't work.
It simply stops with a delay at the end of the light sleep routine.