wifi connectivity after exiting light sleep mode (timer based)
Posted: Mon Oct 23, 2017 12:23 am
I have been trying out the light sleep feature (timer based) and it works great. However I am not sure what happens to wifi connectivity when in light sleep or after exiting light sleep mode. I have the code here that connects to NTP server to get time. I am not sure why there is a huge delay when reading time from NTP, when light sleep is inserted. There is almost 15 sec delay in time, when i am only going to sleep for 2 seconds
Code: Select all
#include <WiFi.h>
#include <esp_sleep.h>
const char* ssid = "XXX";
const char* password = "XXXXX";
/* Time Stamp */
#include <NTPClient.h>
#include <WiFiUdp.h>
#define NTP_OFFSET -3 * 60 * 60 // In seconds
#define NTP_INTERVAL 60 * 1000 // In miliseconds
#define NTP_ADDRESS "0.pool.ntp.org"
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, NTP_ADDRESS, NTP_OFFSET, NTP_INTERVAL);
void setup()
{
Serial.begin(115200);
connectWiFi();
timeClient.begin();
}
void loop()
{
Serial.println("light_sleep_enter");
esp_sleep_enable_timer_wakeup(2000000); //2 seconds
int ret = esp_light_sleep_start();
Serial.printf("light_sleep: %d\n", ret);
timeClient.update();
String formattedTime = timeClient.getFormattedTime();
Serial.println(formattedTime);
}
void connectWiFi(void)
{
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}