B4R Question ESP8266 3 Sleep modes - ESP8266WiFi Library

Peter Simpson

Expert
Licensed User
Longtime User
Hello,
It appears that we can't access the 3 sleep modes that are apparently available in the original ESP8266WiFi library, Modem-Sleep, Light-Sleep and Deep-Sleep, these methods are not exposed. These can be essential for developers that want to run an ESP8266 via a battery for long periods of time. I believe that the current version of the original ESP8266WiFi.h library offers these sleep modes. We could really do with at least Deep-Sleep mode as it offers extremely low power consumption usage for example data logging for extremely long periods of time with just a 3.3v LiFe battery. Using Deep-Sleep the ESP8266 uses around 9mA of current, compare this to around 80mA of current without putting the ESP8266 into Deep-Sleep and the potential power saving is clear to see.

The ESP8266 will sleeps for 10 minutes then wakes up.
ESP.deepSleep(10 * 1000000);

Anyway if it's possible to add the 3 sleep modes to the ESP8266WiFi library, or at least just the Deep-Sleep method, that would be absolutely fabulous.

Thank you.
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Posting here just to save the subs.
B4X:
Private Sub DeepSleep(ms As ULong)
    RunNative("deepSleep", ms * 1000)
End Sub

Public Sub LightSleep_OFF
    Log("Light sleep is disabled")
    RunNative("DisableLightSleep", Null)
End Sub

Public Sub LightSleep_ON
    Log("Light sleep is enabled")
    RunNative("EnableLightSleep", Null)
End Sub

#if C
void deepSleep(B4R::Object* o) {

   ESP.deepSleep(o->toULong(), WAKE_RF_DEFAULT);
}

void DisableLightSleep(B4R::Object* o) {
  // Disable light sleep
  wifi_set_sleep_type(NONE_SLEEP_T);
  delay(2000);
 }
void EnableLightSleep(B4R::Object* o) {
  // Enable light sleep
  wifi_set_sleep_type(LIGHT_SLEEP_T);
  delay(2000);
}
#end if
 
Upvote 0
Top