wifi connectivity after exiting light sleep mode (timer based)

Gtracks
Posts: 5
Joined: Sun Jun 25, 2017 8:12 pm

wifi connectivity after exiting light sleep mode (timer based)

Postby Gtracks » 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());
}
Attachments
lightsleepNTP.png
COM port view.
lightsleepNTP.png (72.31 KiB) Viewed 7788 times

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: wifi connectivity after exiting light sleep mode (timer based)

Postby ESP_igrr » Mon Oct 23, 2017 3:48 am

You should disconnect from WiFi before entering light sleep mode (call esp_wifi_stop) and then connect again after exiting light sleep (esp_wifi_start / esp_wifi_connect).

Gtracks
Posts: 5
Joined: Sun Jun 25, 2017 8:12 pm

Re: wifi connectivity after exiting light sleep mode (timer based)

Postby Gtracks » Tue Oct 24, 2017 6:58 pm

thanks. Connecting and reconnecting to the AP adds additional delays.

I am looking for an efficient way to handle serial data coming from I2C bus and put the chip to Light_sleep mode while waiting for the serial data. I dont want to disconnect and reconnect with the AP each time I have some new data to send. The disconnect/connect process adds additional delay.

jason2
Posts: 44
Joined: Thu Oct 26, 2017 11:02 am

Re: wifi connectivity after exiting light sleep mode (timer based)

Postby jason2 » Mon Nov 06, 2017 1:20 am

We also need to enter light sleep without disconnecting wifi.

kurtzweber
Posts: 64
Joined: Tue Jan 10, 2017 1:09 pm

Re: wifi connectivity after exiting light sleep mode (timer based)

Postby kurtzweber » Mon Nov 06, 2017 2:09 pm

Hi

from the official documentation:
WiFi can coexist with light sleep mode, allowing the chip to go into light sleep mode when there is no network activity, and waking up the chip from light sleep mode when required. However APIs described in this section can not be used for that purpose. esp_light_sleep_start forces the chip to enter light sleep mode, regardless of whether WiFi is active or not. Automatic entry into light sleep mode, coordinated with WiFi driver, will be supported using a separate set of APIs.
so it seems that - being the wifi part not open source - we have to wait for espressif to release (framework v3 hopefully?) the APIs for having wifi during light sleep... Any official roadmaps/plans about this?

thanks

Who is online

Users browsing this forum: Google [Bot] and 120 guests